Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6. Suppose that overSpeed and fine are double variables. Assign the value to fin

ID: 3828760 • Letter: 6

Question

6. Suppose that overSpeed and fine are double variables. Assign the value to fine as follows: If 0 < overSpeed <= 5, the value assigned to fine is $20.00; if 5 < overSpeed <= 10, thevalueassignedto fine is $75.00; if 10 < overSpeed <= 15, the value assigned to fine is $150.00; if overSpeed > 15, the value assigned to fine is $150.00 plus $20.00 per mile over 15

7. Rewrite the following expressions using the conditional operator. (Assume that all variables are declared properly.)

a. if (x >= y)

z = x - y;

else

z = y - x;

b. if (hours >= 40.0)

wages = 40 * 7.50 + 1.5 * 7.5 * (hours - 40);

else

wages = hours * 7.50;

c. if (score >= 60)

str = "Pass";

else

str = "Fail";

8. Suppose that beta is an int variable. Consider the following C++ code:

cin >> beta;

switch (beta % 7)

{

case 0:

case 1:

beta = beta * beta;

break;

case 2:

beta++;

break;

case 3:

beta = static_cast<int>(sqrt(beta * 1.0));

break;

case 4:

beta = beta + 4;

case 6:

beta = beta--;

break;

default:

beta = -10;

}

a. What is the output if the input is 19?

b. What is the output if the input is 23?

c. What is the output if the input is 0?

d. What is the output if the input is 11?

9. The following program contains errors. Correct them so that the program will run and output

w = 21.

#include<iostream>

using namespace std;

const int SECRET = 5

main ()

{

int

x, y, w, z;

z = 9;

if

z > 10

x = 12; y = 5, w = x + y + SECRET;

else

x = 12; y = 4, w = x + y + SECRET;

cout << "w = " << w << endl;

}

10. Write the missing statements in the following program so that it prompts the user to input two numbers. If one of the numbers is 0, the program should output a message indicating that both numbers must be nonzero. If the first number is greater than the second number, it outputs the first number divided by the second number; if the first number is less than the second number, it outputs the second number divided by the first number; otherwise, it outputs the product of the numbers.

#include <iostream>

using namespace std;

int main()

{

double firstNum, secondNum;

cout << "Enter two nonzero numbers: ";

cin >> firstNum >> secondNum;

cout << endl;

//Missing statements

return 0;

}

Explanation / Answer

HI, I have answered Q6 and Q7

Please repost others in separate post.


6. Suppose that overSpeed and fine are double variables. Assign the value to fine as follows: If 0 < overSpeed <= 5, the value assigned to fine is $20.00; if 5 < overSpeed <= 10, thevalueassignedto fine is $75.00; if 10 < overSpeed <= 15, the value assigned to fine is $150.00; if overSpeed > 15, the value assigned to fine is $150.00 plus $20.00 per mile over 15

   if(overSpeed > 0 && overSpeed <= 5)
       fine = 20.0;
   else if(overSpeed > 5 && overSpeed <= 10)
       fine = 75.0;
   else if(overSpeed > 10 && overSpeed <= 15)
       fine = 150.0;
   else if(overSpeed > 15){
       fine = 150 + (overSpeed-15)*20;
   }

7. Rewrite the following expressions using the conditional operator. (Assume that all variables are declared properly.)

a. if (x >= y)
       z = x - y;
   else
       z = y - x;

   Ans: (x >= y) ? z = x-y : z = y-x;

b.
   if (hours >= 40.0)
        wages = 40 * 7.50 + 1.5 * 7.5 * (hours - 40);
   else
       wages = hours * 7.50;

   Ans: (hours >= 40) ? wages = (40 * 7.50 + 1.5 * 7.5 * (hours - 40)) : wages = hours * 7.50;

c.
   if (score >= 60)
        str = "Pass";
   else
       str = "Fail";

   (score >= 60) ? str = "Pass" : str = "Fail" ;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote