Write program to read three numbers and display each output in a separate line.
ID: 3921893 • Letter: W
Question
Write program to read three numbers and display each output in a separate line. Use long double type. Use setw (15) to format the output. Explain the effect of setw (15) on output. Write a C++ program to read three numbers and display them. Use double type. Use set precision (3). Explain the effect of setprecision (3) on output. Write a program to read three numbers.and display them. Use double type. Use setw (15) and setprecision (3). Explain the effect of both setw(15) and setprecision (3) on output. Write a program to read three numbers and display them. Use double type. Use setprecision (16) and showpoint. Explain the effect of both setw(15) and showpoint on output. Write a program to read three numbers as type double and display them. Use setw (15) and left manipulator objects. Explain the effect of both setw(16) and left on output. Write a C++ program to read three numbers and display them. Use double type. Use setw(16) and left manipulator object. Explain the effecExplanation / Answer
6. Setw is used to set field width for characters (i.e escape that many character with space).
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
long double a,b,c;
cin>>a>>b>>c;
cout<< a<<endl;
cout << setw(10);
cout << b << endl;
cout << setw(50);
cout << c << endl;
return 0;
}
In second line of output it can be seen that,number starts after 15 character width.
2. It is used to set the decimal precision to format float values on output operations.
// setprecision example
#include <iostream> // std::cout, std::fixed
#include <iomanip> // std::setprecision
using namespace std;
int main () {
double a,b,c;
cin>>a>>b>>c;
cout << a << ' ';
cout << setprecision(3) << b << ' ';
cout << setprecision(5) << c << ' ';
return 0;
}
In output , 2nd and 3rd line you can see there are change in precision after decimal point wrt to the argument n function.
12.
// setprecision example
#include <iostream> // std::cout, std::fixed
#include <iomanip> // std::setprecision
using namespace std;
int main () {
float hours,rate;
cin>>hours>>rate;
cout << hours<< setw(10) << rate << ' ';
return 0;
}
hours & rate is seprted by 10 character widths.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.