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

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

ID: 3828807 • Letter: 8

Question

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

8.

8.
beta = 19
beta%7 = 5
beta = -10

beta = 23
beta%7 = 2
beta = beta++ = 24

beta = 0
beta%7 = 0
beta = beta*beta = 0

beta = 11
beta%7 = 4
beta = beta + 4 = 15
beta = beta -- = 14


9.

#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.

#include <iostream>

using namespace std;

int main()

{

double firstNum, secondNum;

cout << "Enter two nonzero numbers: ";

cin >> firstNum >> secondNum;

cout << endl;

if (firstNum > secondNum)

cout << (firstNum / secondNum);

else if (firstNum < secondNum)

cout << (secondNum / firstNum);

else

cout << (secondNum * firstNum);

return 0;

}

I hope this helps you. I kept the code quite simple and they are self-explanatory. If incase you face any trouble, please feel free to comment below. I shall be glad to help you. :)

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