Question

QUESTION 1 What will be displayed as a result of executing the following code? int   x...

QUESTION 1

  1. What will be displayed as a result of executing the following code?

    int   x = 5, y = 20;

    x += 32;

    y /= 4;

    cout <<"x = " << x <<"y = " << y;

    A.

    x = 32, y = 4

    B.

    x = 9, y = 52

    C.

    x = 37, y = 5

    D.

    x = 160, y = 80

8 points   

QUESTION 2

  1. What will be the displayed when the following code is executed?

    const int x = 22, y = 4;

    y += x;

    cout <<"x= " << x <<" , y = " << y;

    x = 22, y = 4

    x = 22, y = 26

    x = 22, y = 88

    Nothing, this is an error

8 points   

QUESTION 3

  1. If chr is a character variable, which of the following if statements is written correctly?

    A.

    if (chr = "a")

    B.

    if (chr == "a")

    C.

    if (chr = 'a')

    D.

    if (chr == 'a')

8 points   

QUESTION 4

  1. What would be the value of bonus after the following statements are executed?

    int bonus, sales = 85000;

    char dept = 'S';

    if (sales > 100000)

        if (dept == 'R')

            bonus = 2000;

       else

            bonus = 1500;

    else if (sales > 75000)

        if (dept == 'R')

            bonus = 1250;

         else

            bonus = 1000;

    else

         bonus = 0;

    A.

    2000

    B.

    1500

    C.

    1250

    D.

    1000

8 points   

QUESTION 5

  1. Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

    A.

    ((x >= 500 && x <= 650) && (y != 1000))

    B.

    ((x > 500 AND x < 650) OR !(y.equal(1000)))

    C.

    ((x > 500 && x < 650) || (y != 1000))

    D.

    ((x < 500 && x > 650) || !(y == 1000))

8 points   

QUESTION 6

  1. What will be printed when the following code is executed?

    int y = 10;

    if ( y == 10)

    {

       int x = 30;

       x += y;

    }

    cout<<"x = ";

    cout<<x;

    A.

    x = 30

    B.

    x = 40

    C.

    x = 20

    D.

    x is unknown when the last statement is executed

8 points   

QUESTION 7

  1. What would be the value of discountRate after the following statements are executed?

    double discountRate = 0.0;

    int purchase = 1250;

    char cust = 'N';

    if (purchase > 1000)

        if (cust == 'Y')

            discountRate = .05;

        else discountRate = .04;

    else if (purchase > 750)

        if (cust == 'Y')

            discountRate = .04;

        else

            discountRate = .03;

    else

        discountRate = 0;

    A.

    .05

    B.

    .04

    C.

    .03

    D.

    0

8 points   

QUESTION 8

  1. What would be the value of discountRate after the following statements are executed?

    double discountRate;

    char custType = 'B';

    switch (custType)

    {

         case 'A':

              discountRate = .08;

              break;

         case 'B':

              discountRate = .06;

         case 'C':

              discountRate = .04;

         default:

              discountRate = 0.0;

    }

    .08

    .06

    .04

    0.0

8 points   

QUESTION 9

  1. What will be the values of x and y as a result of the following code?

    int x = 25, y = 8;

    x += y;

    x = 25, y = 8

    x = 34, y = 8

    x = 33, y = 8

    x = 34, y = 9

8 points   

QUESTION 10

  1. Assume a program has the following variable defenition:

    int a, b =2;

    float c = 4.2;

    and the following statement:

    a = b * c;

    What will be stored in a?

    A.

    8.4

    B.

    8

    C.

    0

    D.

    None of the above

8 points   

QUESTION 11

  1. What the following statement will be evaluated to where T is true and F is false:

    T&&T||F&&T

    A.

    true

    B.

    false

    C.

    this statement is wrong

    D.

    not applicable in C++ language

8 points   

QUESTION 12

  1. Which of the following is a string literal constant?

    A.

    “Visual C++”

    B.

    “A”

    C.

    “2.3456”

    D.

    all of the above

6 points   

QUESTION 13

  1. The statement i+=1; is equivalent to

    A.

    i = i + i;

    B.

    i = i + 1;

    C.

    i = i - 1;

    D.

    i --;

8 points   

QUESTION 14

  1. What will the following code display?

    Assume this code in included within the main function.

    int x = 10, y;

    if(x < 10)
    y = 1;
    if (x>= 10)
    y = 2;
    cout << "y is " <<y;

10 points   

QUESTION 15

  1. Convert the following if/else if statement into a switch statement:

    If (option ==1)

    {

                    cout<< “ You selected option 1”;

    }

    else if (option==2 || option == 3)

    {

                cout<< “ You selected option 2 or option 3”;

    }

    else if (option == 4)

    {

              cout<< “ You selected option 4”;

    }

    else

    {    

                cout<< “ You selected other option”;

    }


14 points   

QUESTION 16

  1. Write the if/else statement as the conditional expression that performs the same option

    result = x < y ? x * 5 : a + b;

14 points   

QUESTION 17

  1. Write a C++ program that asks the user to enter two numbers. The program should use the conditional operator to determine which number is the smaller and which is the larger.

20 points   

QUESTION 18

  1. Write a cout statement so that the variable totalAge is displayed in a field of 12 spaces, in fixed point notation, with a precision of 4 decimal places.

12 points   

QUESTION 19

  1. Write an if/else statement that compares the value of the variables   soldYesterday and   soldToday , and based upon that comparison assigns   salesTrend the value -1 or 1 .

    -1 represents the case where   soldYesterday is greater than   soldToday ;

    1 represents the case where   soldYesterday is not greater than   soldToday .

14 points   

QUESTION 20

  1. Write nested if statements that perform the following tests:

    If amount1 is greater than 10 and amount2 is less than 100, display the greater of the two.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

QUESTION1

int   x = 5, y = 20;

x += 32;

y /= 4;

cout <<"x = " << x <<"y = " << y;

solution:

x=5

x+=32 =>x =x+32 => x=5+32=37

y=20

y/=4=>y=y/4=>y=20/4=>y=5

Therefore x=37 y=5 Option C is correct

QUESTION 2:

const int x = 22, y = 4;

y += x;

cout <<"x= " << x <<" , y = " << y;

Here there will be an error because y is constant and cannot be changed

Hence option D is correct

QUESTION 3:

option D is correct if(char=='a')

option A is wrong because if(char="a") here in if statement it is assignment operator ..in if statement only equal operator is valid more over char variables should be compared with ' ' and not " " Therefore option B is also wrong

option C is wrong because in if statement it  is assignment operator

QUESTION 4:

int bonus, sales = 85000;

char dept = 'S';

if (sales > 100000)

    if (dept == 'R')

        bonus = 2000;

   else

        bonus = 1500;

else if (sales > 75000)

    if (dept == 'R')

        bonus = 1250;

     else

        bonus = 1000;

else

     bonus = 0;

solution:

option D is correct

the first if does not satisfy because given sales=85000

it goes to else if statement which is sales>75000 this satisfies because sales=85000

now in this else if statement given dept is not R so else will be executed and bonus=1000;

first four questions are answered according to the HomeworkLib policy

if u understand up vote else post a comment

Add a comment
Know the answer?
Add Answer to:
QUESTION 1 What will be displayed as a result of executing the following code? int   x...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer and explain thank you. Question 1 What will be printed when the following code...

    Please answer and explain thank you. Question 1 What will be printed when the following code is executed? double x = 45678.259; System.out.printf("%,.2f", x); Group of answer choices 45678.259 0,045,678.26 45,678.26 45,678.3 Question 2 What will be printed when the following code is executed? double x = 45678.259; String output = String.format("%,.1f", x); System.out.println(output); Group of answer choices 45678.259 45,678.259 45,678.26 45,678.3 Question 3 What will be the value of ans after the following code has been executed? int ans=0;...

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • 5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8};       ...

    5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8};        for(int i=0;i<9;i++)      a[i]=a[i+1]; for(int i=0;i<8;i++)      cout<<a[i]<<” “; cout<<endl; 6. What will be shown on the output screen after following statements are executed? char a[ ]="I have a part time job"; int c=x, i=0 while(a[i]!=’\0’){      if(a[i]==' '){           c++;           cout<<endl;      }      else           cout<<a[i];      i++; } cout<<c<<endl; 7. After following statements are executed, what are the outputs char a[ ]= "Fresno City College";        for (i...

  • 2. What is the value of x alter the following code is executed # include<iostream> using...

    2. What is the value of x alter the following code is executed # include<iostream> using namespace std; int main int t-0, c- 0,x-3; while (c < 4) t=t+x; cout << x return 0; a) 3 b) 21 c) 24 d) 48 3. What is the output of the following code? # include<iostream> using namespace std; int main0 int a- 3; for (int i 5; i >0; i) a a+i cout << a << “ “ return 0; d) 8...

  • In the code given below, how many times the cout statement is executed? for (int x...

    In the code given below, how many times the cout statement is executed? for (int x = 0; x< 10; x++) for (int y=0; y < 10; y++) for (int z = 0; z <=10; z++) cout << X+y+z;

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • 31. The following code segment is syntactically correct:              int number{20};          cout << number <<...

    31. The following code segment is syntactically correct:              int number{20};          cout << number << setbase(16) << " " << number                               << setbase(10) << " " << number                                 << showpos << " " << number << endl;                 T__   F__       32. The following statement wants to determine if ‘count’ is outside the     range of 0 through 100:             if (count < 0 && count > 100)                                             T__   F__ 33. There is...

  • 12. What is the output of the following C++ code? int x; int y; int *p...

    12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...

  • QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x,...

    QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x, int& y); int Doughnut(int y, int z); int main( ) {             int a = 1;             int b = 2;             int c = 3;             int d = 4;             Pancake(a, b, c);             Waffle(b, c);             Pancake(d, c, b);             d = Doughnut(b, a);             return 0; } void Pancake(int x, int& y, int z) {             y += 3;            ...

  • Question 15 After the following code executes, what is the output if user enters 0? int...

    Question 15 After the following code executes, what is the output if user enters 0? int x =-1; cout << "Enter O or 1:"; cin >> X; if (x) cout << true else cout << false O nothing will be displayed true O false 0

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT