I tried to search online but most of my search will point me to the following result.
#include <iostream>
using namespace std;
int main () {
double a,b,c;
a = 3.1415926534;
b = 2006.0;
c = 1.0e-10;
cout.precision(5);
cout << a << '\t' << b << '\t' << c << endl;
cout << fixed << a << '\t' << b << '\t' << c << endl;
cout << scientific << a << '\t' << b << '\t' << c << endl;
return 0;
}
However, I am given the following only and requested to produce the above outcome. (not to use the full std function)
#include <iostream>
using std::cout;
using std::endl;
int main()
{
double x = 0.001234567;
double y = 1.946e9;
}
expected output
Displayed in default format: 0.001234567 1.946e+009 Displayed in scientific format: 1.234567e-003 1.946000e+009 Displayed in fixed format: 0.001235 194000000.000000
How should I go about it?
I am thinking maybe operator(<<) overloading...but without the built-in function, how do I convert double to scientific and fixed format?

New Topic/Question
Reply



MultiQuote




|