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:
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.
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Through PayPal system. Price depends on difficulty of the assignment and the deadline.
I am from South Africa..how do I go about doing the payments and how much does it cost?
Leave a comment