Hi, this is kind of silly request, can anyone help me with these three C++ progs:

I - Predefined number of operation Calculator:

e.g.

5 + 12 - 3

10 / 3 - 5 /12

The program should ask for the following

1- number of operations

2- the equation

for example

please enter the number of operations

2

Please Enter equation in the form num [op num] then press enter

6 / 2 * 3

9

II - Unknown number of operation Calculator:

accept an equation of any number of operatoins ending with the equal (=) operator.

e.g.

6 + 9 - 3 / 2 =

6

2 * 3 + 3 * 2 / 6 =

3

III - Priority Calculator:

caculate the (*, /) operations first then (+, -).

e.g.

6 + 2 * 9 - 3 / 2 =

processing

[6 + 18 - 3/2]

[6 + 18 - 1.5]

[24 - 1.5]

22.5

2 * 3 + 3 * 2 / 6 =

processing

[6 + 3 * 2 / 6]

[6 + 6 / 6]

[6 + 1]

7

I really hope that you help me, thanx in advance

## All 3 Replies

Yes, it is a silly request since you didn't bother to give us any indication what you need help with. We don't code for people, we help you fix your code.

Be sure to read the Member Rules.

This is really a self explanitory type of assignment. Straight-forward, no exotic techniques required.

I will assume since requirement #3 mandates the use of PEMDOS precidence, requirements #1 & #2 do not; therefore, we can get away with working "left-to-right" for requirements #1 & #2.

Requirement #1: We have to assert that the user entered equation matches number of operations. If not, throw errror and back out to main menu. Push the equation into a single string object. Identify the number of operators, you could use the count() function from <algorithm>. Number of operators should equal number of operations. Parse the string into a terms[ ] string array, you can use the <string> class substr() function for string parsing. Pass each term into a user defined function that will return a 'double' type result of each term. You can use the <sstream> class to perform string-to-int conversion. Accumulate the result into a double type 'subtotal' variable. Repeat until all terms have been processed.

Requirement #2: Actually a little easier than req. #1 since we do not have to perform operators == operations assertion. Push user entered expression into a single string. Parse each expression into a token[ ] string array. Pass each token into a user defined function for processing. Use the <sstream> class to perform string-to-int conversion. Accumulate the results from each token into a double type 'subtotal' variable.

Requirement #3: Perform the same steps at req. #2 up untill the point you have the expression parsed into tokens. At this point, you will have to use if/else logic to determine which tokens get passed into a user-defined function for math processing; all multiplication and division tokens should be passed into the function first. Everything else (+ and -) will be passed in last. Identification of priority tokens can be made using the string class function find_first_of("*/"). Results should be += accumulated into a 'subtotal' variable.

commented: Neat & clear. Very good explanation. +11

@WaltP: I'm really sorry, please accept my apology, i did not know that this act is not acceptable.

@Clinton Portis: Thank you for your assistance, it been a very helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.