Suppose that beta is an int variable Consider the following

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 (squareroot (beta * 1.0)); break; case 4: beta - beta + 4; case 6: beta - beta--; break; default: beta = -10;} -What is the output if the input is 11? What is the output if the input is 12? What is the output if the input is 0 What is the output if the input is 16? Suppose that num is an ink variable Consider the following C ++ code; cin >> num; (num > = 0) (num) {0:

Solution

#include <iostream>
#include<cmath>
using namespace std;

int main()
{
   int beta;
   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;
               break;
       case 6: beta = beta--;
               break;
       default: beta = -10;
   }

cout<<\"beta =\"<<beta;
   return 0;
}

a. beta = 11

11%7 = 4 so case 4 will execute where beta = beta +4 ,beta = 11+4 =15. So beta = 15.

b. beta = 12

12%7 = 5. But case 5 is not defined so default case will execute where beta = -10

c. beta = 0

0%7 = 0. so case 0 will execute. nothing happens and beta has same value ie beta =0;

d. beta = 16

16%7 = 2 . case 2 will execute and beta++ will execute. So beta = 17

 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site