Lab 6

 

  1. Give the outputs for the following executed statements.  If not enough information to give output state that.
    1. if  (6<2*5)

cout<<”hello”;

cout<<”  There”;

    1. if( ‘a’ > ’b’ || static_cast<int> (‘A’))

cout<< “#*# “<< endl;

    1. if (7 <= 7)

cout << 6 – 9 * 2 / 6 <<endl;

    1. if (7 < 8 )

{

cout << “2 4 6 8 “ << endl;

cout << “1 3 5 7 “<< endl;

                        }

    1. if  (5 < 3)

cout << ‘*’;

                        else

                                    if (7 == 8)

                                                cout <<’&’;

                                    else

                                                cout <<’$’;

 

  1. Write C++ statements that output Male if the gender is ‘M’, Female if the gender is ‘F’, and invalid gender otherwise.

 

 

 

 

 

  1. Correct the following code so that it prints the correct message.

if (score >= 60)

                        cout <, “You pass.” << endl;

            else;

                        cout<< “You fail.” << endl;

 

  1. Write a program that prompts the user to input an integer between 0 and 35.  If the number is less than or equal to 9, the program should output the number, otherwise, it should output A for 10, B for 11, C for 12… and Z for 35.  (Hint: Use the cast operator static_cast<char>(), for numbers >= 10.).  Hand in source code and resulting output on the same sheet.

 

  1. The cost of an international call from New York to New Delhi is calculated as follows;  Connection fee, $1.99,

$2.00 for the first three minutes; and $0.45 for each additional minute.  Write a program that prompts the user to enter the number of minutes the call lasted and outputs the amount due.  Format your output with two decimal places.  Hand in source code and resulting output on the same sheet.

 

  1. Suppose the input is 3.  What is the value of beta after the following C++ statements executes?

cin >> beta;

switch (beta)

{

case 3:

            beta = beta + 3;

case 1:

            beta++;

            break;

case 5:

            beta = beta + 5;

case 4:

            beta = beta + 4;

}