Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An accumulator is a primitive kind of calculator that can evaluate arithmetic ex

ID: 3785508 • Letter: A

Question

An accumulator is a primitive kind of calculator that can evaluate arithmetic expressions. In fact, the Arithmetic-Logic Unit (ALU) of the rst computers was just an accumulator. An arithmetic expression, as you know, consists of two kinds of tokens:
operands and operators

All our operands will be (float) numbers and for a start, we shall use only two operators:

+ (plus)

and

- (minus)

A sample run of the program would look like this.

Welcome to your friendly neighborhood accumulator! Please input

your expression, one token at a time, starting with an operand and

type in '=' when completed.

3.0

+

2.0

-

-5.0

=

10.0

Thank-you for using your friendly neighborhood accumulator!

The problem is formally described as follows:

Input: An alternating sequence of operands and operators, given one at a time, starting and ending with an operand. The sequence is followed by an equals sign, to indicate termination. Each operand is a float value and each operator is a plus or a minus.

Output: The value of the expression dened by the sequence of operands and operators. We shall assume for now that the user will not make mistakes when using the accumulator, i.e., there is no bad input

(e.g., two consecutive tokens being both operands or both operators, other unexpected characters etc.) Note that the equals sign acts like a sentinel.

The Strategy.

To initialize the process, the first operand (a number) is read and stored as the total. Next, an operator (a character) is read and we decide what action to take. The action can be one of the following:

(i) In case of termination (equals sign) the process is exited and the total is printed;

(ii) otherwise another operand is read and either added to or subtracted from the total depending on the operator.

1.) Write the sequence of steps that would be carried out when evaluating an expression using the above strategy. Your answer will look something like this:

read num;

store num in total;

read operator;

...

(extend this following our strategy until you see repetition)

2.) From the answer to Question 1, identify a block of repeating steps. The exit test should be performed at the start of the block.

3.) Implement your algorithm in C++.

Explanation / Answer

Here is the code. Hope,my answer helped you.Any further doubts,please feel free to contact us,we will love to help you

CODE:

Sequence of steps which are carried out are :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote