Computers and Technology

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

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 11:30, kyraj21
Which excel file extension stores automated steps for repetitive tasks?
Answers: 1
image
Computers and Technology, 24.06.2019 13:30, sweeps8758
Which type of excel chart should be used to track students’ progress on test grades? line column bar pie
Answers: 2
image
Computers and Technology, 24.06.2019 21:30, erickamiles1797
How do i copy and paste equations and pictures like math graphs, to post on this site to get my questions answered?
Answers: 2
image
Computers and Technology, 25.06.2019 08:50, chrisssrutter
1. define independent-set as the problem that takes a graph g and an integer k and asks whether g contains an independent set of vertices of size k. that is, g contains a set i of vertices of size k such that, for any v and w in i, there is no edge (v, w) in g. show that independent-set is np-complete.
Answers: 3
Do you know the correct answer?
Task:

We want to make a simple calculator that can add and subtract integers and will ac...

Questions in other subjects:

Konu
Computers and Technology, 13.07.2019 02:00
Konu
Advanced Placement (AP), 13.07.2019 02:00