Write an even better calculator program calc3.cpp that can understand squared numbers. We are going to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <formulas.txt 25 1012. To take into account, don't add or subtract new numbers remember the number, read the next operator and if it is a add or subtract it. right away after reading them. Instead, square the remembered number, then C 10 11 #include<iostream> 12 #include<fstream> 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<<ans<<endl; Submission H 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 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 <formulas.txt 25 1012. To take into account, don't add or subtract new numbers remember the number, read the next operator and if it is a add or subtract it. right away after reading them. Instead, square the remembered number, then C 10 11 #include<iostream> 12 #include<fstream> 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<<ans<<endl; Submission H 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
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
The Exchange Rate between the US and the UK is $1.5 to 1 Pound. English Biscuits in the US sell for $5 a box. If the exchange rate goes to $1.4 to 1 Pound, and the costs in England do not change -...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-6. On December 12, Irene purchased the building where her store is located. She paid...
-
Some people believe that the Internet is rewriting the rules of how to attract, motivate, and retain talent internationally. Consider Planet-Intra.com Ltd., a year-old software company that is...
-
In the discussion of ULTs versus KLTs, it was pointed out that a disadvantage of ULTs is that when a ULT executes a system call, not only is that thread blocked, but also all of the threads within...
-
Approximate using linearization and use a calculator to compute the percentage error 59. 1/17 61. 1/(10.03)2
-
True or False: A worn sleeve bearing will usually be indicated by harmonics of a fundamental frequency that is less than half the shaft speed.
-
An organizations internal audit department is usually considered an effective control mechanism for evaluating the organizations internal control structure. Birch Companys internal auditing function...
-
Manufacturing overhead for the year was estimated to be $1,013,600 while the actual manufacturing overhead for the year was $955,000. Actual machine-hours for the year were 36,380 hours, and...
-
Use Nodal Analysis to find Vx, in the circuit. 202 4A -2 A Va VB 50 N 40 2 100 2 25 2 10 A
-
When PepsiCo asked its advertising agency to develop an advertising program for its Mountain Dew soft drink, it gave the agency a statement describing the age and fun - loving spirit of its target...
-
Identify and describe the benefits and challenges of interpersonal intercultural relationships. Then discuss the impacts of interpersonal intercultural relationships on our ability to communicate...
-
What is game theory? How does it relate to strategic decision making? What do the phrases dominant strategy and Nash Equilibrium mean as they apply to game theory?
-
Friction between food retailers and their suppliers is adding costs across the food chain . Big buyers including Walmart Inc. WMT -1.61%decrease; red down pointing triangle and Sysco Corp. SYY...
-
How does the term regulation relate to McDonalds and the other restaurants in the fast food industry? What kind of regulations do they have and who is the governing authority?
-
What methodological approaches and interdisciplinary insights can enrich the development and application of social theory in addressing complex societal challenges and informing policy interventions ?
-
The equity section of Cullumber Group showed the following: share premium €6,110, share capital—ordinary €930, share capital—preference €58, retained earnings €7,510,...
-
Explain five different cases of income exempt from tax with clear examples.
-
Frederick (Freddy) Freeweights (age 42) owns and operates a health club called ''Treadmills West.'' The business is located at 4321 Arnold Street, Alpine, CA 91901. Freddy had the following income...
-
Jenny earns $34,500 in 2012. Calculate the FICA tax that must be paid by: Jenny: ..............................Soc,Sec. ..................$______________...
-
Greg died on July 1, 2012, and left Lea, his wife, a $50,000 life insurance policy which she elects to receive at $5,000 per year plus interest for 10 years. In the current year, Lea receives $6,200....
-
Berkley Corp. wanted to buy 1,000 customized umbrellas imprinted with their logo to use for promotional purposes. It planned to use 250 of the umbrellas for an event scheduled for early February 2012...
-
Kemesia Boota Ward signed a contract on February 17, 2010, to hold her wedding reception at the Deauville Hotel on July 9, 2010. (The wedding ceremony was being held elsewhere.) Renting the ballroom...
-
Which of the following is a sale of goods and therefore is covered by Article 2 of the Uniform Commercial Code? A. Development, implementation, hosting, and operation of sophisticated computing...
Study smarter with the SolutionInn App