C++ project

Cerrado Publicado Sep 8, 2012 Pagado a la entrega
Cerrado Pagado a la entrega

Looking to get help on writing this C++ program as it describe.

thank you

Do the Math!

1. Write a C++ program, [url removed, login to view], that computes arithmetic expressions entered in postfix notation. We are most familiar with infix notation to specify a computation:

3 + 4 * (8 – 2) * 5

Parentheses are needed to change the precedence of operations. Parentheses are not need for postfix notation. The above expression could be written as follows:

3 4 8 2 - * 5 * +

To compute an expression in postfix notation, we use a stack. Whenever a number is encountered, it is added to the top of the stack. Whenever an operator is encountered, the operator is applied to the top two elements on the stack and the result replaces those two elements on the stack. For example, when the subtraction is encountered above, we would have the following occur:

Stack Before Subtraction Stack after Subtraction

Note for subtraction the top value is subtracted from the second value. For division, the top value is the divisor. The final result of the expression will be the number remaining in the stack at the end.

Your program will use an array of integers to represent the stack. The program will repeatedly ask the user for one of four character commands:

a : adds a given number to the stack

c : computes for a given operator

p : prints the current stack (top to bottom)

q : prints the current stack and ends the program

Your program should detect and print error messages for the following conditions:

? Command is not one of 4 given above

? Operator is not one of +, -, * or /

? A computation is requested when there are less than two numbers on the stack

You are required to write the following three functions to help complete the task. The variable calculator is the array holding the stack values and top is the index of the top element in the stack.

// add_number prompts the user for an integer, reads it in and

// adds it to the top of the stack

void add_number (int calculator [100], int& top);

// compute prompts the user for an arithmetic operator and reads

// it in. If the operator is illegal or there are less than two

// elements on the stack, it prints an error message. Otherwise,

// it applies the operator to the top two elements of the stack,

// prints the result in equation form and replaces the top two

// elements in the stack with the result.

void compute (int calculator [100], int& top);

// print_stack prints a label and then prints the elements of

// the stack, one per line from top to bottom.

void print_stack (int calculator [100], int top);

Here is a sample run of the program (user input in bold):

Enter a (add number), c (compute), p (print) or q (quit): p

The current stack is:

Enter a (add number), c (compute), p (print) or q (quit): a

Enter an integer to add to the stack: 36

Enter a (add number), c (compute), p (print) or q (quit): c

There are not enough numbers to apply an operator!

Enter a (add number), c (compute), p (print) or q (quit): a

Enter an integer to add to the stack: 19

Enter a (add number), c (compute), p (print) or q (quit): a

Enter an integer to add to the stack: 10

Enter a (add number), c (compute), p (print) or q (quit): b

Illegal command, enter one of a, c, p or q!

Enter a (add number), c (compute), p (print) or q (quit): p

The current stack is:

10

19

36

Enter a (add number), c (compute), p (print) or q (quit): c

Enter the operator: -

19 - 10 = 9

Enter a (add number), c (compute), p (print) or q (quit): p

The current stack is:

9

36

Enter a (add number), c (compute), p (print) or q (quit): c

Enter the operator: &

Illegal operator, enter one of +, -, * or /

Enter a (add number), c (compute), p (print) or q (quit): c

Enter the operator: /

36 / 9 = 4

Enter a (add number), c (compute), p (print) or q (quit): q

The current stack is:

4

Done computing!

PHP Arquitectura de software

Nº del proyecto: #2471655

Sobre el proyecto

10 propuestas Proyecto remoto Activo Oct 9, 2012

10 freelancers están ofertando un promedio de $305 por este trabajo

zeke

Expert C++ developer. Available to start immediately.

$300 USD en 1 día
(160 comentarios)
7.0
DPROF

Can do it just for fun. Extremely easy task. Regards

$250 USD en 1 día
(9 comentarios)
5.7
it2051229

Hi, kindly check your inbox for my inquiries. Thanks.

$250 USD en 1 día
(77 comentarios)
5.5
lokjaiswal12

Hello, I have done this kind of assignments.

$250 USD en 1 día
(42 comentarios)
5.1
rakib062

Hi, I am a graduate in CS and working as a C++ programmer for 3+ years. I have done lots of similar projects both in academic courses and in professional life. I assure you of clean, efficient and optimized code with Más

$250 USD en 1 día
(7 comentarios)
4.5
bazzinfotech

**************************************** Please Check PMB for more details.Thanks. ****************************************

$250 USD en 2 días
(8 comentarios)
3.5
rhythmist

I'm computer science student.I've written many programs like this.I can help you in this task.

$250 USD en 1 día
(1 comentario)
2.7
ubul

I can help you. This task is fun...

$250 USD en 1 día
(0 comentarios)
0.0
D02AvYkG9

Custom software development (<b><i>Removed by Admin</i></b>)

$750 USD en 1 día
(0 comentarios)
0.0
IronDeveloper89

I can do this job with the require quality in less than a day. Please conctact me if you are interested and see PM. Regards

$250 USD en 1 día
(0 comentarios)
0.0