CMPSC 101 Exam Information

Exam #1 - Exam #2 - Final Exam

Exam #1 -

This exam will cover variables, statements, data types, if statements, & loops. The first portion of the exam will consist of True/False questions. You must use a #2 pencil to answer this portion of the exam. The second part of the exam will require you to write C++ programs and/or code segments. You will not be able to use a computer during the exam.

To review for the exam, please look over online notes, worksheets, and demo programs. Review the textbook material and assigned questions, projects, and exercises as well. Be sure to practice writing code segments and even complete working programs. You may want to write a program out on paper and then to informally grade yourself, type it into Visual C++ to see if it would successfully compile. While you can receive partial credit on the exam, you must still use basic syntax correctly to do well on the exam.

Practice Exam #1

Part I - True/False

1. The + operator comes before the / operator in the order of operations.
2. Keywords are words that you cannot use as identifiers.
3. A bug is a logic error or other problem in a computer program.
4. "ant eater" is a legal identifier?
5. The statement    ++i;     increments the variable i.
6. The statement    cin >> cost;    gets a number from the keyboard and stores it in a variable named cost?
7. An if statement must have an else part.
8. A do while loop should be used when you can determine the exact number of iterations that will be necessary.
9. A break statement causes a loop to end.
10. A while loop is a top-checking, determinate loop.
11. The loop set up with the statement for (j = 1; j <= 5; j++) will iterate 5 times (assuming j is not affected within the loop and that there are no break's).
12. The loop set up with the statement for (j = 0; j < 10; j++) will iterate 10 times (assuming j is not affected within the loop and that there are no break's).
13. The loop set up with the statement for (j = 10; j < 100; j = j + 3)will iterate 5 times (assuming j is not affected within the loop and that there are no break's).
14. At one point the value of j is 11 when the loop set up with the statement for (j = -4; j <=20; j = j + 5) iterates.

Part II - Write valid, efficient C++ code to perform the following tasks. It is NOT necessary to include documentation. However, you MUST use the same exact variable names that are specified. In each separate exercise, you may assume that the necessary variables have been declared unless you are being asked to write an actual declaration statement or a whole program. Use good white space and indentation, so that your answers are neat and easy to read.

1. Write a statement that declares a variable sum of type double.
2. Write a statement that assigns the value 209 to the double variable sum.
3. Write a statement that displays the value of the integer variable sum to the screen.
4. Write a statement that increments the variable sum using the incrementing operator.
5. Write a single statement that declares a constant named DOZEN with the value of 12. Use a logical & reasonable data type.
6. Write an if statement that displays the message "Won" if the value of the double variable runsScored is greater than 8.
7. Write an if else statement that displays the message "You earned an A." if the value of the variable named studentGrade is greater than or equal to 90. Otherwise, the if else statement causes the message "You could have done better!" to display.
8. Write a for loop that displays the values of 1 to 10 on the screen.
9. Write a for loop that counts by two’s from 10 to 20, displaying each value as it counts.
10. Write a top-checking indeterminate loop that allows the user to input a sequence of integers until the sum of the numbers that he has entered is greater than 100.
11. Write a whole program that prompts the user to enter his age. The program then displays the number of years the user has until retirement assuming that the user works until he is 65.
12. Write a full C++ program that obtains three floating-point values from the user via the keyboard, providing suitable prompt statements indicating that each input is a weight in pounds known to the hundredths place. The program must display the average of the three values rounded to the first decimal place (tenths place) along with a suitable message indicating that this result is the average.


Exam #2 - 

This exam will focus on functions & files but it will also require you to use syntax and concepts learned in earlier chapters.

The first portion of the exam will consist of True/False questions. You must use a #2 pencil to answer this portion of the exam. The second part of the exam will require you to write C++ programs and/or code segments. You will not be able to use a computer during the exam.

To review for the exam, please look over online notes, worksheets, and demo programs. Review the textbook material and assigned questions, projects, and exercises as well. Be sure to practice writing code segments and even complete working programs. You may want to write a program out on paper and then to informally grade yourself, type it into Visual C++ to see if it would successfully compile. While you can receive partial credit on the exam, you must still use basic syntax correctly to do well on the exam.

Part I - True/False

1. You should try to avoid using global variables in C++ programs.
2. All C++ programs have a
main function.
3. Function prototypes should always appear below the
main function.
4.
It is dangerous to leave a file open when it is not being used in a program.
5. The statement       infile().close();     would close a file named infile.
6. The statement    file infile;    would declare a file pointer.
7. Random access files are used to store databases.
8. Adding data to the end of an existing file is called appending.
9. The compiler directive      #include <string>     must appear at the top of a program that uses files.
10. The name infile must be used for a file pointer that is used to read data from a file.

Part II - Write valid, efficient C++ code to perform the following tasks. It is NOT necessary to include documentation. However, you MUST use the same exact variable names that are specified. In each separate exercise, you may assume that the necessary variables have been declared unless you are being asked to write an actual declaration statement or a whole program. Use good white space and indentation, so that your answers are neat and easy to read.

1. Write a statement that declares an output file pointer named outfile that would point to the file named TEXT.TXT.
2. Use the open function to open a file named TEXT.TXT for output using a file pointer named outfile. You are to assume that outfile has already been declared as an ofstream file pointer.
3. Close a file named TEXT.TXT that is pointed to by a file pointer named outfile.
4. Open a file named TEXT.TXT for appending using a file pointer named outfile.
5. Write a complete program that appends the user's inputted age (an integer) to a file named
AGES.TXT.
6. Write a function named
max2 that returns the maximum value of the two integer parameters that are passed to it.
7. Write a function named
ave3 that returns the exact average of three integer parameters that are passed to it.
8. Write a complete program that allows the user to input two integers and then displays the larger value. The program should use a function named
max2 from a previous exercise to determine which of the two inputed values is the largest. Two int parameters should be passed to the function max2 and the function should return the larger of the two. The main function should then display the largest value.
9. Write a complete program that allows the user to input two integer values. The program must pass those two values to a function named
computeAve which returns the average of the two parameters. The main function should then display the final average rounded to the nearest whole number.

Final Exam - 

This exam will mainly focus on strings & arrays, however other topics from earlier chapters will be represented as well.

The first portion of the exam will consist of True/False questions. You must use a #2 pencil to answer this portion of the exam. The second part of the exam will require you to write full working C++ programs and/or code segments on lined paper. You will not be able to use a computer during the exam.

To review for the exam, please look over online notes, worksheets, and demo programs. Review the textbook material and assigned questions, projects, and exercises as well. Be sure to practice writing code segments and even complete working programs. You may want to write a program out on paper and then to informally grade yourself, type it into Visual C++ to see if it would successfully compile. While you can receive partial credit on the exam, you must still use basic syntax correctly to do well on the exam.

Part I - True/False

1. A string is made up of characters.
2. sample[5] refers to the fifth character of a string named sample.
3. The beverage, RC Cola, can be used to remember that rows come before columns in the subscript notation used with two-dimensional arrays.
4. Data in parallel arrays has to be of the same type. For example, you cannot store integer values in an array that "is parallel to" an array that stores double values.

Part II - Write valid, efficient C++ code to perform the following tasks. It is NOT necessary to include documentation. However, you MUST use the same exact variable names that are specified. In each separate exercise, you may assume that the necessary variables have been declared unless you are being asked to write an actual declaration statement or a whole program. Use good white space and indentation, so that your answers are neat and easy to read.

1. Write a statement that declares a string named courseName.
2. Write a single statement that displays the string variables
firstName and lastName to the screen on separate lines. You will lose points if you do not write a single statement to perform the given task.
3. Write a declaration statement that declares an array named
numbers that can store exactly 10 values of type double.
4. Write an assignment statement that assigns the value of 13 to the fifth element of an array of integers named
numbers. (You may assume that numbers has the capacity to hold 10 elements and has already been declared.)
5. Write a loop that allows the user to input exactly 10 numbers and that stores the numbers into an array named
numbers.
6. Write a loop that efficiently assigns the value of 100 to every element of an array named
numbers which has a size of 20.
7. Write a code segment that uses a loop to search an array named
numbers for the value 15. You may assume that the array has 100 elements. If the value is found, use a break statement to terminate the loop and display the message "found". If the value is not found, the message "not found" should displayed one time.
8. Write a complete program that uses a loop to allow a user to input 10 numbers and that stores those numbers into an array named
numbers. The program must display all of the inputted numbers that are odd and greater than 50.