Answer to Question #6668 in C++ for kiran

Question #6668
The grade 7 mathematics class of Sunnyside Primary are doing an interesting project on operator
precedence. The class is divided into groups. Each member in each group must say how they
want the following calculation to be done by supplying operator precedence:

y = 14 * 9 – 8 / 2 + 10 / 3 – 8 + 4;

For example, if Peter wants division to be done first, then addition, then subtraction and then
multiplication, the statement will look as follows:

y = 14 * (9 – ((8 / 2) + (10 / 3)) – (8 + 4));

There are 24 possible combinations of these operators. Peter’s group has chosen combinations 3,
8, 7, 1, 2 and 4. The preference of the members of a specific group is saved in an input file "precedence.dat" as follows:

Peter 3 / + - *
Dahne 8 + - / *
Renee 7 - * + /
Charl 1 * / + -
Johan 2 / - * +
Sipho 4 * - / +

You have to write a program that will read the file line by line and supply the correct bracketed
assignment statement depending on the combination number that was chosen. The team member
name, the precedence of the operators and the value for "y" must be written to the output file
"results.dat" so that the teacher can check if the answer is correct according to the precedence
chosen. If your program works correctly, the output file will look as follows:

Peter / + - * y = -140
Dahne + - / * y = 0
Renee - * + / y = -1
Charl * / + - y = 107
Johan / - * + y = 69
Sipho * - / + y = 61

Create the input file "precedence.dat". Use a "string" variable to read in the team member’s
name, an "int" variable to read the combination number and variables of type "char" to read in the
operators. You can assume there will only be 6 records for the purpose of the calculation, but your
program must determine when the end of the file is reached without testing that 6 records have
been read. For the purpose of the program we give you part of the "switch" statement. Assume
that we are only working with these 6 combinations and complete the "switch" statement by
supplying the assignment statements with the correct bracketing according to the combinations
supplied above in "precedence.dat".

switch (combo) //where combo is the variable defined for the
//combination number
{
case 1:
//add correct assignment statement here
break;
case 2:
//add correct assignment statement here
break;
case 3:
y = 14 * (9 - ((8 / 2) + (10 / 3)) - (8 + 4));
break;
case 4:
//add correct assignment statement here
break;
case 7:
//add correct assignment statement here
break;
case 8:
y = 14 * ((9 - 8) / (2 + 10) / (3 - (8 + 4)));
break;
default:
cout << "Other combinations not developed yet" << endl;
}
1
Expert's answer
2012-02-17T08:56:51-0500

Unfortunately, your question requires a lot of work and cannot be done for free.
Submit it with all requirements as an assignment to our control panel and we'll assist you.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
17.02.12, 16:20

Through PayPal system. Price depends on difficulty of the assignment and the deadline.

kiran
17.02.12, 16:06

I am from South Africa..how do I go about doing the payments and how much does it cost?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS