98 717
Assignments Done
98.6%
Successfully Done
In April 2021

# 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 &ndash; 8 / 2 + 10 / 3 &ndash; 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 &ndash; ((8 / 2) + (10 / 3)) &ndash; (8 + 4));

There are 24 possible combinations of these operators. Peter&rsquo;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 &quot;precedence.dat&quot; 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 &quot;y&quot; must be written to the output file
&quot;results.dat&quot; 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 &quot;precedence.dat&quot;. Use a &quot;string&quot; variable to read in the team member&rsquo;s
name, an &quot;int&quot; variable to read the combination number and variables of type &quot;char&quot; 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 &quot;switch&quot; statement. Assume
that we are only working with these 6 combinations and complete the &quot;switch&quot; statement by
supplying the assignment statements with the correct bracketing according to the combinations
supplied above in &quot;precedence.dat&quot;.

switch (combo) //where combo is the variable defined for the
//combination number
{
case 1:
break;
case 2:
break;
case 3:
y = 14 * (9 - ((8 / 2) + (10 / 3)) - (8 + 4));
break;
case 4:
break;
case 7:
break;
case 8:
y = 14 * ((9 - 8) / (2 + 10) / (3 - (8 + 4)));
break;
default:
cout &lt;&lt; &quot;Other combinations not developed yet&quot; &lt;&lt; endl;
}
1
2012-02-17T08:56:51-0500

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!

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?