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

19. Suppose that sale and bonus are double variables. Write an if. . .else state

ID: 3566303 • Letter: 1

Question

19. Suppose that sale and bonus are double variables. Write an if. . .else
statement that assigns a value to bonus as follows: If sale is greater than
$20,000, the value assigned to bonus is 0.10; if sale is greater than
$10,000 and less than or equal to $20,000, the value assigned to bonus
is 0.05; otherwise, the value assigned to bonus is 0.
20. 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, the value assigned to 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.
21. Suppose that score is an int variable. Consider the following if statements:
if (score >= 90);
cout << "Discount = 10%" << endl;
a. What is the output if the value of score is 95? Justify your answer.
b. What is the output if the value of score is 85? Justify your answer.
22. Suppose that score is an int variable. Consider the following if statements:
i. if (score == 70)
cout << "Grade is C." << endl;
ii. if (score = 70)
cout << "Grade is C." << endl;
Answer the following questions:
a. What is the output in (i) and (ii) if the value of score is 70? What is
the value of score after the if statement executes?
b. What is the output in (i) and (ii) if the value of score is 80? What is
the value of score after the if statement executes?
23. 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";

Explanation / Answer

19)

if(sale > 20000)
bonus = 0.10;

else if( sale > 10000 && sale <= 20000)
bonus = 0.05;

else
bonus = 0;

20)

if( overSpeed > 0 && overSpeed <= 5)
fine = 20;

else if( overSpeed > 5 && overSpeed <= 10)
fine = 75;

else if( overSpeed > 10 && overSpeed <= 15)
fine = 150;

else if( overSpeed > 15)
fine = 150 + ( miles * 20 );

21)

if (score >= 90);
cout << "Discount = 10%" << endl;

a. What is the output if the value of score is 95? Justify your answer.

ANS) if( 95 >= 90) so condition is true then cout statement will execute

Output:

Discount = 10%


b. What is the output if the value of score is 85? Justify your answer.

ANS)   if( 85 >= 90 ) condition is false so cout statement will NOT execute


Output:

NO Output

22)

i. if (score == 70)
cout << "Grade is C." << endl;
ii. if (score = 70)
cout << "Grade is C." << endl;

a. What is the output in (i) and (ii) if the value of score is 70? What is
the value of score after the if statement executes?

ANS)   i) if( 70 == 70 ) condition TRUE

Output:

Grade is C.   


   ii) if( 70 = 70 ) if condition Requires Boolean Type but here we are using Assignment Operator
so ERROR will arise so No Ouput for this

Output:

No Output


score value is 70.

b. What is the output in (i) and (ii) if the value of score is 80? What is
the value of score after the if statement executes?

ANS) i) if( 80 == 70 ) condition FALSE

Output:

No Output

  
   ii) if( 80 = 70 ) Again assignment operator is used so ERROR will arise.


Output:

No Output


score value is 80.

23)

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

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


c) str = (score >= 60 ) ? "Pass" : "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