Question

In: Computer Science

Trace the following program. This means you need to fill the table in which you show...

Trace the following program. This means you need to fill the table in which you show the output of each executed instruction as if you are the computer executing the program. Put your comments under the table.

#include<iostream>

using namespace std;

int main ()

{

cout.setf(ios :: fixed);

cout.setf(ios :: showpoint);

cout.precision(2);

int A=7.5, B=2.5, C;                                                                                        //statement 1

double X,Y;

char Letter;

C = A/B;                                                                                                          //statement 2

X = 1.0*A/B;                                                                                                    //statement 3

if (C<X)

        Letter = 30*C;                                                                                         //statement 4

if (C=X)

        Letter = 20*C;                                                                                         //statement 5

if (C>X)

        Letter = 10*C;                                                                                         //statement 6

cout << "Letter = " << Letter+10 << endl;                                                       //statement 7

Letter = Letter + 10;                                                                                        //statement 8

cout << "Letter = " << Letter << endl;                                                             //statement 9

Y = 1.0*(A/B);                                                                                                 //statement 10

X = Y/ (B+5) + 2.5;                                                                                          //statement 11

cout.precision(1);

cout << "X = " << X << endl;                                                                           //statement 12

return 0;

}

Solutions

Expert Solution

Please find the dry run attached.

#include<iostream>
using namespace std;

int main ()
{
    cout.setf(ios :: fixed);
    cout.setf(ios :: showpoint);
    cout.precision(2);

    int A=7.5, B=2.5, C;  //statement 1 , here value of A=7, B=2, C=Garbage value
    double X,Y; // both will contain garbage value

    char Letter; // garbage value

    C = A/B;    //statement 2, here A=7, B=2, 7/2 = 3.5 but 3 will be stored in C

    X = 1.0*A/B;  //statement 3, here A=7, B=2, X = 1.0*7/2 = 7.0/2 = 3.50

    if (C<X) // here C=3, X=3.50, condition is true
        Letter = 30*C;  //statement 4, Letter=30*3 = 90, 90 is ascii of Z, So Letter = Z.

    if (C=X) // here C=3, X=3.50, I guess this must be == , here C = X, C will store 3 and this condition is true
        Letter = 20*C;  //statement 5, Letter=20*3 = 60, 60 is ascii of <, So Letter = <.

    if (C>X) // here C=3, X=3.50, condition is false
        Letter = 10*C; //statement 6, we won't reach here

    cout << "Letter = " << Letter+10 << endl; //statement 7, Letter + 10 = 60 + 10 = 70

    Letter = Letter + 10;  //statement 8, Letter = 70, 70 is ascii of F. So, Letter = F.

    cout << "Letter = " << Letter << endl; //statement 9, Letter = F

    Y = 1.0*(A/B); //statement 10, here A=7, B=2, Y = 1.0*(7/2) = 1.0*3 = 3.00

    X = Y/ (B+5) + 2.5; //statement 11, here Y = 3.0, B = 2, X = 3.0/(2+5) + 2.5 = 3.0/7 + 2.5 = 0.428+2.5 = 2.928, 2.93 will be stored in X

    cout.precision(1); // precision set to 1 digit

    cout << "X = " << X << endl; //statement 12, X=2.9

    return 0;
}

Related Solutions

stoichiometry and a precipitation reaction. Need to fill in the data table. The following information is...
stoichiometry and a precipitation reaction. Need to fill in the data table. The following information is given. 1.5 gram of CaCL2*2H2O How many moles are present of CaCL2*2H2O and then calculate how many moles of pure CaCL2 are present in 1.5g of CaCL2*2H2O Initial CaCL2*2H2O(g) = ??? Initial CaCL2*2H2O(moles) =?? Initial CaCL2(moles) = ??? Use the information given - how many moles of Na2CO3 are necessary to reach stoichiometry Quantities. From the calculation determine how many grams of NA2CO3 are...
Fill in the following table to show how the given integers are represented, assuming 16 bits...
Fill in the following table to show how the given integers are represented, assuming 16 bits are used to store values and the machine uses 2’s complement notation. (This is not necessarily MARIE.) Give values in the last two columns in hexadecimal as they would appear memory assuming the byte at address a is on the left and the byte at the address a+1 is on the right. 2-Byte Big 2-Byte Little Integer Binary Hex Endian (hex) Endian (hex) Example...
Fill in the blanks on the following table
 Fill in the blanks on the following tableE&pshareholder basisdistributiondividendreturn of capitalcapital gain20,000300,00080,000120,00010,000170,000220,000100,000170,00020,000080,000<20,000>50,000170,000
Fill in the blanks to complete the following table.
Fill in the blanks to complete the following table.SymbolIon FormedNumber of Electrons in IonNumber of Protons in IonF__________9Te_____54_____II−_______________Mg2+_____12Part AComplete the first column of the table.Express your answer as a chemical symbol.Part BComplete the second column of the table.Express your answer as ions. Enter your answers in order given in the table, from top to bottom, separated by a comma.Part CComplete the third column of the table.Express your answer as integers. Enter your answers in order given in the table, from...
Fill in the table and answer the following questions
Fill in the table and answer the following questions **** (Use D-method) Class Frequency 10 – 12 6 13 – 15 4 16 – 18 14 19 – 21 15 22 – 24 8 25 – 27 2 28 – 30 1   50 Class Real limits f cf x d fd     10 – 12                 13 – 15                 16 – 18  ...
Fill in the blanks in the following table. At which level of output do we obtain...
Fill in the blanks in the following table. At which level of output do we obtain maximum profit? What is the relationship between marginal revenue and marginal cost at the profit-maximizing level of output? Level of Output Total Revenue Total Cost Profit Marginal Revenue Marginal Cost Marginal Profit 20 2400 1900 420 100 21 2800 120 22 3180 140 23 3540 160 24 3880 180 25 4200 200 26 4500 220 27 4780            240 28 5040 260 29 5280 280...
Please answer all questions, fill in table and show calculations. The table below shows the hypothetical...
Please answer all questions, fill in table and show calculations. The table below shows the hypothetical prices and quantities demanded of a software product. Assume that the fixed cost of setting up the production of software is $200 and the marginal cost is $5. Fill out the table by calculating the revenue, the marginal revenue, total cost, the marginal cost, and the profit. Give a general definition of price elasticity of demand. Explain the factors that make the demand of...
Create a table in which you show the following: For each variable below : 1. Identify...
Create a table in which you show the following: For each variable below : 1. Identify the variable as either categorical, numerical discrete, or numerical continuous. 2.Identify the level of measurement of each variable (nominal, ordinal, interval, or ratio) Variables a.) Length of Stay b.) ICU Days c.) Age (Years) d.) Sex (M/F/U) e.) Principal Payer f.) Total Charges g.) Drug Charges h.) Lab Charges i.) Imaging Charges j.) RT Charges
Fill in 7 blanks in the following table and interpret your results. Show your calculations and units of account.
Fill in 7 blanks in the following table and interpret your results. Show your calculations and units of account.YearReal GDP (National Income), $Consumption, $Saving, $Marginal Propensity to ConsumeMarginal Propensity to Save20159,0008,000   ---------   ---------201610,0008,600201712,0009,300Calculations:Fill in the blanks using your answers in part a):Answer:   In 2016, out of each $1 of additional income (real GDP) a country spent____________, while saved the rest_____________.Fill in the blanks using your answers in parts a) and b):Answer:If in 2016 this country’s real national income went up by $3,800,...
2.) Fill in the following table: Show work if possible Output Total Cost Fixed Cost Variable...
2.) Fill in the following table: Show work if possible Output Total Cost Fixed Cost Variable Cost ATC AFC AVC MC 0 100 1 122 2 142 3 154 4 176 5 201 6 235 7 270 8 326 9 398 10 490 b.) Now suppose this firm is in a perfectly competitive industry. The market price of the output is $25. How many units of output will this firm choose to produce in the short run? What is the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT