1. Trace the following program:

 

#include<iostream>

#include<iomanip>

using namespace std;

 

int main()

 

{

 

double  a, b, c;

 

a = 6.50;

b = 3.45;

c = a + b;

cout<<setfill('*');

cout<<setw(10)<<fixed<<showpoint<<setprecision(2)<<a<<endl;

cout<<setw(8)<<b<<endl;

cout<<setfill('$')<<c<<setw(15)<<c;

 

}

 

 

  1. State whether the following evaluate to TRUE or FALSE:

 

    1. 7 + 3 > 15 && 6 – 1 == 7

 

    1. 8 > 15 || 6 < 7 + 3 && 8 == 2/2

 

    1. if num1 has the value of 16 and num2 has the value of 24:

 

 num1 % 8 == num2 % 4 && num1 < num2

 

 

  1. Why do we need to include:

 

    1. iomanip

 

    1. fstream

 

    1. cmath

 

    1. iostream

 

 

  1.  
    1. Write an if statement that will print out a name if  it begins with the letters M-Z.  You may NOT assume that the name was typed in capital letters.
    2. Write an if statement that will add 1 to an integer variable if it is exactly divisible by 5 (….,-5,0,5,10,….).

 

 

  1. Trace the following program:

 

 

#include<iostream>

#include<iomanip>

using namespace std;

 

int main()

 

{

 

     int a,b;

     double x = 6.2;

     bool flag = true;

     a = 12;

 

     if (x > a || a < 12)

          cout<<"this is true\t";

     else

          cout<<"it is false\n";

     if (flag)

          cout<<"this is true\t";

          cout<<"this is false\n";

 

     flag = true;

 

     if (flag && a == 12)

     {

          cout<<"hello\n";

          b = a;

     }

     cout<<a<<' '<<b<<' '<<flag<<' '<<x<<' ';

 

}