Design, write and compile a C++ program to display the following output using setw(), setprecision(), setiosflags():
Radians
Degrees
1
57.2958
10
572.9580
20
1145.9200
30
1718.87000
40
2291.83000
(b) What is the minimum number of cout statements that could be used to print the above output?
(c) Explain your choice of coding style with your chosen number of cout statements.
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<"Radians\n Degrees\n"<<1<<endl<<setprecision(10)
<<57.2958<<endl<<10<<endl<<fixed<<setprecision(4)
<<572.958<<endl<<20<<endl<<1145.92<<endl<<30<<endl
<<setprecision(5)<<1718.87<<endl<<40<<endl
<<2291.83;
//b) We can use only 1 cout statement
/*c) I think if we use min amount of cout statements, we have a bit better performance, because of less amount of operations*/
}
Comments
Leave a comment