I have problem making structure decimal number in c++. To be more specific my greatest issue is how to overload (input) >> operator and operation of fast powering. The number needs to be represented by two lists, first list has to contain int part of number ond the secound decimal part. What is the best way to separate number aaa.bbb on int aaa and int bbb in reasonable time, and put them in separate lists? also if the last k digits of decimal part are 0 I need to cut them off.
// Example program
#include <iostream>
#include <string>
int main()
{
usingnamespace std;
cout << "Enter number: ";
int left;
char decimal_point;
int right;
cin >> left;
cin >> decimal_point;
cin >> right;
cout << "You entered: " << left << decimal_point << right << '\n';
}
Enter number: 1234.5678
You entered: 1234.5678
Of course, it will be larger in complexity after you add more dynamic behavior and error handling, at which point it might just be easier to parse the input as a string, and then break it up yourself (hint: strings and stringstreams).
You are going to be hard pressed to make that function work. Eventually, you will have to do some rounding if your decimal components are represented by ints.