subject

Task:

We want to make a simple calculator that can add and subtract integers and will accept arbitrarily long mathematical formulas composed of symbols +, -, and non-negative integer numbers.

Imagine you have a file formula. txt with the summation formula such as:

100 + 50 - 25 + 0 + 123 - 1
If you redirect the file into your program, it should compute and print the

$ ./calc < formula. txt
247
Specifically, write a program calc. cpp that reads from the cin a sequence of one or more non-negative integers written to be added or subtracted. Space characters can be anywhere in the input. After the input ends (end-of-file is reached), the program should compute and print the result of the input summation.

Possible input that has spaces and characters:

1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 +
1 + 1 + 1 + 1
Possible output: 16

You can use >> operator to read the numbers and the +/- characters, because >> will be skipping all spaces between the input terms.

WHat would the program be here? How would i successfully read in the file and get the right output?

Thanks

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:30
Apower user needs you to install a second type of operating system on his computer to increase efficiency while running some specialized software programs. which installation technique should you use?
Answers: 3
question
Computers and Technology, 22.06.2019 08:30
1.the index finger on your right hand types the f r v 4 j u m 7 h y 6 n lo.9 j u 7 m g t 5 b 2.if you need to multiply 400, 2, and 1 ½, what would you type on the numeric keypad? 400*2*1.5 400/2*1.5 400/2/1.5 400*2*1½ 3.select all examples of proper keyboarding technique. rest your fingers gently on the home row or home keys. slouch in your chair. rest your palms on the keyboard. relax your fingers. keep your hands lower than your elbows.
Answers: 1
question
Computers and Technology, 22.06.2019 10:40
"it security policy enforcement and monitoring" respond to the following: describe how monitoring worker activities can increase the security within organizations. describe the rationale that managers should use to determine the degree of monitoring that the organization should conduct. explain the extent to which you believe an organization has the right to monitor user actions and traffic. determine the actions organizations can take to mitigate the potential issues associated with monitoring user actions and traffic.
Answers: 3
question
Computers and Technology, 22.06.2019 22:30
Which of the following factors would your hypothetical supervisor look at when deciding whether to test a biological material sample for dna? the amount of other evidence you have implicating a suspect in a crime the annual budget for the crime lab both of the above none of the above; you would almost always order a test
Answers: 3
You know the right answer?
Task:

We want to make a simple calculator that can add and subtract integers and will ac...
Questions
question
Mathematics, 21.05.2021 22:40
question
Advanced Placement (AP), 21.05.2021 22:40
Questions on the website: 13722367