Midterm
Self--Check Exercises
(not graded...just for
practice!)
CS 161:
Introduction to Computer Science 1
Self-Check
Exercises
1.
Write an algorithm that allows for the input of an integer value, doubles it,
subtracts 10, and displays the result.
2.
List three basic data types in C++
3.
When reading in two characters using the extraction operator (>>), does
it matter how many blanks (if any) appear before the first character? Or,
between the first and second characters? Or, after the second character?
4.
Write a nested if statement to display a message indicating the educational
level of a student based on the number of years of schooling (0 is none, 1-6 is
elementary, 7-8 is middle school, 9-12 is high school, greater than 12 is
college). Display a message to indicate if the data is bad, as well.
5.
Write if/else statements, given
these variables:
int number;
char letter;
a) Display the message telling whether or not number
is positive
b) Display a message telling whether or not letter
follows ‘M’ in the alphabet
c) Display a message telling whether or not number is
evenly divisible by three
6.
What is the most significant difference between a while and a do-while loop?
7.
Write a while loop that prompts a user for a grade between 0 and 100 inclusive
and continues to repeat the prompt until a valid entry is provided.
8.
Now, rewrite the answer to question #7 using a do-while loop
9.
Write a program to sum and print a collection of payroll amounts entered at the
terminal until a sentinel value of -1 is entered. Display the sum total at the
end.
10.
What changes would you make to your answer of question #9 if you wanted to
calculate the average pay?
11.
Write a program to find the largest, smallest, and average of a n whole
numbers. You can assume that “n” has already been set by the user.
12.
Write a while loop that displays
all the even number from start to end
13. Write a program that reads in two integers at a time, and outputs their sum, difference, and product.