PART A) 2.5 points
1. How many spaces printed out by this statement: cout << "how" << "now" << "brown" << "cow"
<< "?";
2. How many lines are printed out by this statement: cout << "abc\ndef\tghi\njkl" << endl << endl
<< "mno\npqr\n";
3.
Write the include directive that allows use of the function headers in the file myFuncs.h.
4. Write a statement that declares an int variable named count.
5. Write a statement to set the value of num to 4 (num is a variable that
has already been declared).
6.
Given an integer variable drivingAge that has already been declared, write
a statement that assigns the value 17 to drivingAge.
7. Which of the following is NOT a legal identifier?
outrageouslyAndShockinglyLongRunon
_42
_
lovePotionNumber9
7thheaven
8. Which of the following IS a legal identifier?
5_And_10
Five_&_Ten
____________
LovePotion#9
"Hello World"
9. Which of the following is NOT a C++ keyword?
using
int
main
namespace
return
10. Which is the best identifier for a variable to represent the amount of money your boss pays
you each month?
notEnough
wages
paymentAmount
monthlyPay
money
11. Of the following variable names, which is the best one for keeping track of whether a patient
has a fever or not?
temperature
feverTest
hasFever
fever
12.
Of the following variable names, which is the best one for keeping track of whether an integer
might be prime or not?
divisible
isPrime
mightBePrime
number
13. Write a declaration of a variable named numberOfWidgets that can be used to hold numbers
like 57 and 981 and -4.
14. Declare a variable populationChange, suitable for holding numbers like -593142 and 8930522.
15. Declare a floating point variable named distance.
16.
Write a declaration for a variable rate_of_pay that can hold values like 11.50 or 12.75.
17. Given an integer variable i and a floating-point variable f, write a statement that writes both
of their values to standard output in the following format: i=value-of-i f=value-of-f
Thus, if i has the value 25 and f has the value 12.34, the output would be:
i=25 f=12.34
But if i has the value 187 and f has the value 24.06, the output would be:
i=187 f=24.06
18. Write a character literal representing the (upper case) letter A.
19. Declare a character variable named c.
Part B) 2.5 points
1. Write a program that displays the following parallelogram pattern on the screen:
2.
The Earth’s ocean levels have risen an average of 1.8 millimeters per year over the past
century. Write a program that computes and displays the number of centimeters and number
of inches the oceans rose during this time. One millimeter is equivalent to 0.1 centimeters.
One centimeter is equivalent to 0.3937 inches. The output of your program should be of this
form:
The ocean rose X centimeters or Y inches in the last 100 years.
where X and Y are the two numbers your program calculated.
Part C) 10 points
5,6,13,15,20 on page 76,77,78 Chapter 2 Programming Challenges