Answer to Question #121275 in C++ for Md Bayezid

Question #121275
Suppose you have some words and you want to right justify them, that is, align them to
the right. Create a program that reads a word and print it all right justified, in the same
order as they appear in the input.
1
Expert's answer
2020-06-10T05:23:28-0400
#include <iomanip>
#include <iostream>


using namespace std;


int main() {
	cout << "Enter amount of strings : ";
	int size = 0;
	cin >> size;


	string words[size];


	int i = 0;
	size_t max_length = 0;
	while (i < size){


		string word = "";
		cout << " > ";
		cin >> word;
		words[i] = word;


		if (word.length() > max_length)
			max_length = word.length();


		i++;
	}


	cout << endl;


	i = 0;
	while (i < size){
		cout.width(max_length);
		cout << right << words[i] << endl;
		i++;
	}


	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