Question

(C++ program) Use the code segment below to answer the two questions that follow. … int...

(C++ program) Use the code segment below to answer the two questions that follow.

int size = 0;
cout << “Enter size: “;

cin >> size;

int sizeCode = size / 10;

if (sizeCode == 0)

   cout << “extra small”;

else if(sizeCode == 1 )

   cout << “small”;

else if (sizeCode == 2)

   cout << “medium”;

else if (sizeCode == 3)

   cout << “large”;

else

   cout << “extra large”;

//end if

What would the code display when the size variable contains the value 35?

What would the code display when the size variable contains the value 9?

Rewrite the code in part a above using the switch statement. The new code should have the same functionality as the previous one.

Homework Answers

Answer #1
the code display when the size variable contains the value 35 is
large

the code display when the size variable contains the value 9 is
extra small

the code in part a above using the switch statement is
int size = 0;
cout << “Enter size: “;
cin >> size;
int sizeCode = size / 10;
switch(sizeCode){
    case 0:
        cout << “extra small”;
        break;
    case 1:
       cout << “small”;
       break;
    case 2:
        cout << “medium”;
        break;
    case 3:
       cout << “large”;
       break;
    default:
        cout << “extra large”;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
When the user enters 2 the following program segment should print the message “You’ve selected to...
When the user enters 2 the following program segment should print the message “You’ve selected to get an A”, however it always prints “You’ve selected to get a C”. Rewrite the code segment to behave properly, i.e., print the proper message: int selection; cout << “Please enter the grade you would like to receive “ << endl; cout << “1 = C, 2 = A”; cin >> selection; if (selection = 1) cout << “You’ve selected to get a C“...
1. What output will be produced by the following code? int extra = -37; if (extra...
1. What output will be produced by the following code? int extra = -37; if (extra < 0) System.out.println("small"); else if (extra == 0) System.out.println("medium"); else System.out.println("large") a. large b. medium c. small d. nothing
1. What is the output of the following code fragment? (All variables are of type int.)...
1. What is the output of the following code fragment? (All variables are of type int.) limit = 8; cout << 'H'; for (loopCount = 10; loopCount <= limit; loopCount++) cout << 'E'; cout << "LP"); 2. What is the output of the following code fragment if the input value is 4? (Be careful here.) int num; int alpha = 10; cin >> num; switch (num) { case 3 : alpha++; case 4 : alpha = alpha + 2; case...
C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether...
C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether a college class room is in violation of fire law regulations regarding the maximum room capacity and add more logic to that program. We will need to make the following enhancements… The program should now determine the number of classes, and should do so by generating a unique, random number. Replace taking user input for the number of rooms with a computer generated number...
1.    Given the following segment of code: (If there is nothing output, write None.) int x;...
1.    Given the following segment of code: (If there is nothing output, write None.) int x; int y; cin >> x; cin >> y; while (x > y) {     x -= 3;     cout << x << " "; } cout << endl;        a.    What are the output and final values of x and y when the input is 10 for x and 0 for y? [2, 2, 2]               Output                                                                                                                                                                                                    x = ______________                                                                                                                                                                                                   ...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You must...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
C ++ program that will read in prices and store them into a two-dimensional array //...
C ++ program that will read in prices and store them into a two-dimensional array // It will print those prices in a table form and the lowest price. // EXAMPLE // Input: // Please input the number of rows from 1 to 10 // 2 // Please input the number of columns from 1 to 10 // 3 // // Input price of item (0,0): 2 // Input price of item (0,1): 4 // Input price of item (0,2):...
Below is my C++ program. There is a function to add data, display it and search...
Below is my C++ program. There is a function to add data, display it and search the data. Just add two more functions to this porgram. One function to update the student data and second function to delete the data. Also, change the display function little bit. Right now, it shows all data entered. Make it so you have to put the uin number and it only displays the data of that specific student. #include <iostream> #include <string> using namespace...