Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Ta Email

Download Compiler

Final Project

Lab Notes

Office Hours

Schedule

Syllabus

Announcements

Check Grades

 

CSci 1113 Home

 
 

Printer-friendly version

 
Sample Midterm Exam Questions - Spring 2009

1. Terms and definitions

a) What are the three structures of structured programming?

b) What is a post-test loop?

c) What are the values a bool variable can have?

d) What is a variable?

e) True or false?  Every C++ program must have a main() function.__________
 

2. Describe the exact output that is produced by the following program segments. Use an underscore (_) to indicate blank spaces.

       double PI = 3.14159;
     int NUM = 73;
     cout.setf(ios::fixed);
     cout.setf(ios::showpoint);
     cout.precision(3);
     cout << "NUM=" << setw(6) << NUM
          << "\nPI=" << PI << endl;

 

3. Write the statements, including a loop, required to calculate y(t) from the equation:

            -3t2 + 5       t >= 0
    y(t) = 
             3t2 + 5       t < 0


for values of t between -9 and 9 in steps of 3.  Display each value of t and y(t).

You do not need to write a complete program but you should include declaration statements for all the variables that you use.

 
4. A program is needed to score a dice game as follows.  If the roll of a pair of dice is 7 or 11, the player's winnings are to be increased by 100.  If the roll turns up any other number, the winnings are to be reduced by 100. Write the C++ statement or statements that will score the dice game.  Assume that the following declarations have been made and that a value has been assigned to variable roll.

     int roll; // the value of the dice roll
    double winnings; // the player's score 

      

5. Relational and Logical Expressions.

a) Assuming the value of variable count is 0 and the value of variable limit is 10, state whether each the following expressions is true or false.

    1. (count == 0) && (limit > 12) _______________________

    2. (limit > 20) || (count < 5)    ________________________

    3. !(count == 12)            ___________________________                                                       

b) In algebra we see numeric intervals given as

    2 < x < 3

This is not how we express this relationship in C++, however.  Give the correct C++ boolean expression that specifies that x lies between 2 and 3.


6. The price of gasoline has fluctuated widely in recent months causing concern for motorists. Here you are to write a complete C++ program to calculate the cost of a visit to a gas station. Your program should ask the user whether he or she wants regular ($2.629 per gallon) or premium ($2.979 per gallon) gasoline, whether or not a car wash ($5.99) is desired, and if a receipt should be printed. Of course the program must also ask how many gallons it took to fill the tank. Then the program should calculate the cost of the gas and the total cost including a car wash if there was one. If the user wanted a receipt, display the number of gallons, the cost of the gasoline, any car wash cost, and the total cost as in this example:


Gallons = 10.00
Gasoline = $21.29
Car wash = $5.99
Total cost = $27.28

Notes:

  • Use variables to hold constant values (e.g., 2.629).

  • Display two digits after the decimal point.

  • Include a few comment statements to document the program.



 
The University of Minnesota is an equal opportunity educator and employer.
CSci 1113: C++ Programming