Answer to Question #174875 in C++ for Kaviyan P

Question #174875

Write a C++ code for the following pattern display using ios classes. The precision is set according to the value of variable x. (use setprecision(), setwidth(), setfill() ios flags and functions).


1
Expert's answer
2021-03-25T18:21:57-0400
#include <iostream>
#include <iomanip>
 
using namespace std;
 
int main()
{
	int x = 0;
	cout << "Set precision: ";
	cin >> x;
	cout << fixed << setprecision(x);
	cout << "Now double number 2.3 as: " << 2.3 << endl;
	cout << "Set width ('Hello' will be right - aligned with a padding of x) : ";
	cin >> x;
	cout << setw(x);
	cout << "Hello" << endl;
	cout << "Set fill ('Hello' will be right - aligned, indented by x, all spaces will be replaced with the entered character.)(char): ";
	char ch;
	cin >> ch;
	cout << setfill(ch);
	cout << setw(x) << "Hello" << 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