Question: Write an even better calculator program calc3.cpp that can understand squared numbers. We are going to use a simplified notation x^ to mean X.



Write an even better calculator program calc3.cpp that can understand squared numbers. We are going to use a simplified notation x^ to mean X. For example, 10+7 51^ should mean 10 + 7-51. Example: When reading input file formulas.txt 5^; 1000+ 6^ 5^ + 1; the program should report: A hint: $ ./calc3 C 10 11 #include 12 #include 13 using namespace std; 14 int main(int arge, char** argv) 15 { 16 17 char old_opr='+',new_opr; 18 int number, ans=0; 19 ifstream file; 20 file.open(argv[1]); 21 while (file>>number) 22 { 23 file>>new_opr; 24 if(new_opr==^') 25 ( 26 number*number; 27 file>>new_opr; 28 } 29 if (old_opr=='+') 30 ( 31 ans+-number; 32 ) 33 else if(old_opr=='_') 34 ( 35 ans--number; 36 37 if(new_opr==';') 38 39 ( cout < Autograder Results Error found On input: 5^; 1000 + 6^ - 5^ + 1; Received output: While expected: 25 1012 Correctness (0/20) Errors found, see the message above. Results Code
Step by Step Solution
3.31 Rating (166 Votes )
There are 3 Steps involved in it
It seems like you have a C program that is designed to be a calculator which interprets a file containing mathematical expressions with addition subtr... View full answer
Get step-by-step solutions from verified subject matter experts
