CMSC 201 SAMPLE TEST 1 Name _______________
Total Points: 100 Point values in margin.
(10) 1. Use the following variables to write a single C++ statement
for each task:
float root, a, b, c;
a) Assign to variable root one value given by the quadratic formula.
b) Display the value of root on the screen in a field of width
20 columns with 4 decimal places after the decimal point.
Assume that these statements have been executed:
cout.setf(ios :: fixed, iso :: floatfield);
cout.setf(ios :: showpoint);
(10) 2. Fill in the blanks.
Name a person at AT&T Bell Labs who was part of the history
of C++:__________________.
The history of C++ is closely related to the development of
this operating system: __________________.
In C++ an expression is: ____________________________________.
Each function has two parts, called __________________ and
__________________.
Before compilation occurs, your C++ code is handled by the
__________ whose directives all begin with this symbol__________.
Your C++ source code is called a source file. The compiler
produces the__________________file. The linker produces the
__________________file.
Name 3 kinds of control in program execution of statements.
__________________, __________________, __________________.
Tell what is in a function prototype: _________________
(10) 3. Give the exact output for the following program.
# include < iostream.h >
int main(void)
{
int a, b, c;
a = 13;
b = 5;
c = 2;
cout << a % b << endl;
cout << a / c << endl;
cout << ( a > c ) << endl;
cout << ( a == c ) << endl;
c++;
cout << c << endl;
if (a = 15)
{
cout << "ONE" << endl;
}
else
{
cout << "TWO" << endl;
}
return 0;
}
(10) 4. a) Convert the integral value 18 to binary.
Show how it would be stored using 8 bits.
b) Convert the integral value -18 to binary in two's
complement form.
Show how it would be stored using 8 bits.
c) Convert float value 13.25 to normalized binary form.
Indicate what is the exponent and what is the mantissa
(significand).
(10) 5. Assume these statements.
Give the value for each expression below.
Tell whether or not short circuiting occurs in evaluation.
int Age, Height;
Age = 35;
Height = 70;
EXPRESSION
(Age <= 20) && (Height > 60)
(Age <= 20) || (Height > 60)
! (Age > 50) && ( Height < 72)
(10) 6. Assume that these variable declarations have been made:
float Wage, Hours, Years;
Write an if...else statement to do the following.
If the value of variable Years is less than 20, you should
assign to variable Wage the value 6.15, and assign to variable
Hours the value 37.5. Otherwise, you should assign to Wage
the value 10.75, and assign to Hours the value 40.0
(10) 7. Write a multiway branching if...else if... statement which
prints out a message depending on a patient's blood pressure
variable BP.
You should print the word "DANGER" if the blood pressure is
250 or over;
print the word "HIGH" if the blood pressure is at least 180
but less than 250;
print the word "NORMAL" if the blood pressure is at least
100 but less than 180;
print the word "LOW" otherwise.
int BP;
(10) 8. Write a function definition for a function called DisplayStars
with return type void, and one parameter Number of type int.
Your function body should use a for loop or a while loop.
NOTE: Some sample function calls and their output are shown below.
DisplayStars(5); // prints ***** to screen
DisplayStars(10); // prints ********** to screen
(20) 9. The local phone company offers 2 types of service:
Unlimited service costs $40.50 per month, no matter how many
local calls are made
Limited service charges a basic rate of $19.38 per month for
up to 30 calls, and $0.09 for each additional call.
The first line of a data file called "A:\PHONE.DAT" contains
an area code and an exchange.
Each of the remaining lines contains a 'U' or an 'L' to
indicate the type of service, the customer's 4 digit number,
and the number of local calls made that month. You do not
know how many telephone numbers are in the data file.
"A:\PHONE.DAT"
410 780
L 4168 130
L 6543 13
U 6578 200
L 6662 31
U 7123 15
. . .
. . .
Write a program to read data from this input file and create an
output file called "A:\BILLS.DAT" which contains the phone number
and bill for each customer in the following form.
"A:\BILLS.DAT"
(410) 780-4168 28.38
(410) 780-6543 19.38
(410) 780-6578 40.50
(410) 780-6662 19.47
(410) 780-7123 40.50
. . .
. . .
Last updated: Nov. 4, 1999