Answer to Question #172847 in C++ for KAVIN MUKILAN

Question #172847

Develop a C++ program to display the string in left and right justifications. Specify the width as 20 and consider the special character to be filled as ‘&’.


1
Expert's answer
2021-03-18T05:53:48-0400
#include <iostream>


using namespace std;


string JustifyContentLeft(string line){
    while (line.size()<20)
        line+='&';
    return line;
}
     
string JustifyContentRight(string line){
    while (line.size()<20)
        line='&'+line;
    return line;
}
int main()
{
    cout<<"Enter string: ";
    string line;
    getline(cin, line);
    cout << "Justify Content Left:  " << JustifyContentLeft(line) << endl;
    cout << "Justify Content Right: " << JustifyContentRight(line) << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS