COSC 1320 - C++ Programming
Bob Comer, Professor, CIT/COSC


Exam 1 Review Exercises

General Information on Exams

See the course syllabus for important information on exams. Here are some more general notes on exams:

I recommend that everyone use the official textbook for this course, Starting Out with C++ Brief 2nd Edition by Tony Gaddis. However, if you have C++ How to Program by Deitel and Deitel, click here for review questions.

Review Questions from Gaddis textbook

To prepare for Exam 1, I recommend that you look over these exercises taken from the Gaddis book. I will NOT grade these exercises.

In general, the Checkpoint questions in the chapters are good (the answers are in Appendix K). The Review Questions at the ends of the chapters are also good (the answers to odd-numbered questions are in Appendix L). Click here for answers that are not in the textbook. Feel free to discuss the answers with your classmates or me (this is a good place to use the listserve).

Note: There will be no questions over strings on Exam 1. Strings will be covered on exam 2.

Chapter 1

No specific questions.

Chapter 2

Review Questions:18, 19, 20, 23.

Other questions:

1. How do you output a newline character from your program?

Chapter 3

Checkpoint: 3.1, 3.4, 3.5, 3.6, 3.7, 3.9, 3.10, 3.11, 3.13, 3.14, 3.16, 3.17, 3.21, 3.22.

Review questions: 5, 17

1. Write a C++ statement that displays the value of floating-point variable rate in a field 8 characters wide with exactly one digit to the right of the decimal.

2. How do you enter a newline character from the keyboard?

Chapter 4

Checkpoint: Do them all if you have time. Save the questions over strings (4.28 - 4.29) for exam 2.

1. A company pays its sales people $200 per week plus 9 percent of their gross sales for the week. Write declarations for variables to hold a salesperson's gross weekly sales and weekly pay. Write a statement to calculate the weekly pay and store it in your variable.

2. Given float variables predictedHigh and actualHigh, write a C++ statement or statements that print:

3. Write a C++ statement that means the same thing as this math expression:

0 < length < 10

Chapter 5

Checkpoint: I have not had a chance to look them over, but I imagine that it would be good to do them all if you have time. Check here for an update on Thursday.

1. The following loop is supposed to print the odd integers from 1 through 5.

count = 1;
while (count != 6)
{
   count++;
   cout << count << ' ';
}

a. What is printed by the loop?
b. Rewrite the loop so that it works correctly.

2. When the following code is inserted in a program and executed, it reads the first price and then the computer "hangs". Find the problem and correct it.

int quantity;
float price, cost;

cout << "Enter item price (or -1 to quit): ";
cin >> price;
while (price > 0);
{
   cout << "Enter quantity for this item: ";
   cin >> quantity;
   cout << endl;
   cost = price * quantity;
   cout << "The cost for " << quantity
        << " items at " << price
        << " each is " << cost
        << endl;
   cout << "Enter item price (or -1 to quit): ";
   cin >> price;
}

3. Write C++ code to read 20 integers and count how many times the integer 100 appears in the input. You must use a loop.

4. Write a loop that sums the integers from 1 through 10.

5. Write a loop that reads a list of integers from the keyboard and counts how many negative integers are input and how many positive integers are input. The loop should stop when zero is input. Then print the count of negative numbers and the count of positive numbers with appropriate labels.

6. Write a switch statement to convert a letter grade to a numeric value based on the following table. Use char variable ltrGrade and int variable numGrade.

letter grade

numeric value

A

4

B

3

C

2

D

1

F

0

Chapter 6

Checkpoint: I have not had a chance to look them over, but I imagine that it would be good to do them all if you have time. Check here for an update on Thursday.

Other questions:

1. Write a possible prototype for function func() below.

int main()
{
   double d;
   float f = 6.2;
   int i = 3;
   d = func( i, f );
   cout << "The result is " << d << endl;
   return 0;
}

2. Write an example call for the following function.

float square( float num)
{
   return num * num;
}

3. True or False: To use a constant variable throughout your program, it should be declared inside your main() function.

4. Write a function that receives a float parameter called num and calculates and returns the fourth power of num (num * num * num * num). Try using a local variable in your function.

5. Write a function that prints the sentence:

Your age is ___ years.

In the blank space in the sentence it should print the value of an integer parameter called age.

6. Write a function that prompts the user to enter a number of hours worked and a pay rate. Your function should then input two values into float parameters called hoursWorked and payRate. Your function will need to supply the two input values to the calling function.

7. The following program will not compile. Find the problem and fix it.

#include <iostream.h>

void PrintCurved( int grade );

int main()
{
   int studentNo, grade;
   cout << "Enter student number and grade:";
   cin >> studentNo >> grade;
   PrintCurved(grade);
   return 0;
}

void PrintCurved( int grade )
{
   cout << "The curved grade for student ";
        << studentNo << " is " 
        << grade + 10 << endl;
}

8. Write a function that receives two float values as parameters and "returns" each value halved. Write an example call for your function. Write declarations for all variables that you use.

9. Write an overloaded version of your function in the previous problem that works on int values.

10. Write a statement that causes all floating point numbers to be printed with exactly 1 place to the right of the decimal point.


Return to C++ Home Page

Copyright: Ó 2001 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to:
Bob Comer
Last updated: October 2, 2001