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

Question #172911

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-21T04:46:16-0400
#include <iostream>
#include <string>
#include <iomanip>
void leftJustification(std::string arg) {
    std::cout << std::setfill('&') <<std::setw(20)<<std::left<< arg << std::endl;
}
void rightJustification(std::string arg) {
    std::cout << std::setfill('&') << std::setw(20) << std::right << arg << std::endl;
}
int main()
{
    std::cout << "Enter  example string: ";
    std::string str;
    std::cin>>str;
    std::cout << "Example left justification string"<<std::endl;
    leftJustification(str);
    std::cout << "Example right justification string" << std::endl;
    rightJustification(str);
    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