An old CIS22A Midterm


1.     Write a program that calculates the tax on an item purchased.  You should prompt the user for cost of the item.  Your program should make use of a named constant for the tax.  This constant should represent a tax rate of 7%.

Program execution:

What is the cost of the item?  100.00            // User input is 100.00
The tax is $7.00                                           // Multiple the cost by the tax rate

2.     Write a function definition for a function called getAge.  The function prompts the user for their age and then returns it.

3.     Write a function prototype for the function that you defined in problem 2.

4.     Insert into the following main() an appropriate call to the function that you defined in problem 2.

int main()
{
   _________________  // function call
   
   return 0;
}
 
5.     Which of the following is NOT a valid identifier?  Enter letter ->    __________
A.    cout
B.    Cout
C.    _55
D.    55_
E.    end

6.     Assume the following declaration is made:

double A = 9876.543;

Write one cout statement that prints the number A two times with exactly the following format.

∆∆∆9877∆∆∆∆9876.543                                                    // Note: each ∆ represents 1 space

__________________________________________________________________________________

7.     Assume the following declaration:

int M = 12345;

Write one statement that will print  M three times like this:

12345 45 12


__________________________________________________________________________________

8.     What is the output from each cout statement?

    cout << (9 / 6 + 9 * 6);                      ______
    
    cout << static_cast<double>(2 / 5 + 5 * 2);   ______

    cout << 100.0/(2 + 8.0 * 6);                  ______

    cout << (6 / 9 ? 6 : 9)                       ______

    cout << rand() % 10 / 10 * 10 + 10 - 10;      ______


9.     Assuming a = 3, b = 4, c = 5, and d = 6, what is the value of each cout statement?

cout << d++ / --b;                                  ______
        
cout << (a + c) % a - c;                            ______
        
cout << static_cast<char>(c * c * c - a * a * a);   ______

cout << ++a % c++;                                  ______

 
10.     Write a function that prints a day of the week.  The function should take an int argument.  It must use a switch.
If the argument is 1, then the function should print Sunday.
If the argument is 2, then the function should print Monday.
If the argument is 3, then the function should print Tuesday.

If the argument is 7, then the function should print Saturday.
If the argument is not between 1 and 7, it should print “error”

11.    Write a program that prints multiples of 8 that are less than 9999.  The output should look like this:

8
16
24
32

9992