CMPSC 101
Exam Information
Exam #1 - Exam
#2 - Final Exam
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 twos
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.
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.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.