Name:
Class:
Date:
Page 1
Indicate whether the statement is true or false.
1. C++ provides the static_cast operator for explicitly converting data from one data type to another.
a.
True
b.
False
2. The following statement adds a value of 1 to the sum variable:
sum += 1;
a.
True
b.
False
3. A stream is defined in C++ as a sequence of numeric values.
a.
True
b.
False
4. The remainder operator is used to divide two integers and results in the remainder of the division.
a.
True
b.
False
5. The cin object typically is used with the insertion operator (<<).
a.
True
b.
False
6. The processing of locating and correcting the errors in a program is called debugging.
a.
True
b.
False
7. The cin object tells the computer to pause program execution while the user enters one or more characters at the
keyboard.
a.
True
b.
False
8. When you break one of the programming language rules it is a logic error.
a.
True
b.
False
9. The execution of a C++ program begins with the main function.
a.
True
b.
False
10. When used with the cout object, the endl stream manipulator advances the cursor to the next line on the computer
screen.
a.
True
b.
False
Name:
Class:
Date:
Page 2
Indicate the answer choice that best completes the statement or answers the question.
11. When creating a program using C++, which symbol is used for the insertion operator?
a.
<<
b.
>>
c.
%
d.
=
12. What type of error occurs when you break one of the programming language’s rules?
a.
logic
b.
stream
c.
syntax
d.
manipulator
13. What type of error is often difficult to find, and can occur for many reasons, such as entering instructions in the
incorrect order?
a.
logic
b.
stream
c.
syntax
d.
manipulator
14. Given the following code, what is the final value of the variable gpa?
int gpa;
int numclasses = 3;
int class1 = 4;
int class2 = 2;
int class3 = 3;
gpa = (class1 + class2 + class3)/numclasses;
a.
3.0
b.
1.0
c.
2.5
d.
3.5
15. In C++, which symbol is used for the extraction operator?
a.
<<
b.
>>
c.
%
d.
=
16. When creating an assignment statement, which symbol is used for the assignment operator?
a.
==
b.
=
c.
>>
d.
+=
17. What is used to tell the compiler where it can find the definitions of keywords and classes?
a.
linker
b.
$keyword statement
c.
using directive
d.
IDE
18. What extension does a source file name have?
a.
.c
b.
.cpp
c.
.prog
d.
.cprog
19. Which line of code takes the value of count and adds three to its current value?
a.
count = 3++;
Name:
Class:
Date:
Page 3
b.
count = ++3;
c.
count = +3;
d.
count += 3;
20. Which stream manipulator can be used to advance the cursor to the next line on the computer screen?
a.
endline
b.
cout
c.
endl
d.
cin
21. Examine the following code. What type of error do you find and what is the correct line of code if the goal of the
program is to calculate a grade point average from the point values of three classes?
int gpa;
int numclasses = 3;
int class1 = 4;
int class2 = 2;
int class3 = 3;
gpa = (class1 + class2) + class3/numclasses;
a.
syntax error, gpa += (class1 + class2) + class3/numclasses;
b.
syntax error, gpa = class1++ class2++ class3++/numclasses;
c.
logic error, gpa = (class1 + class2 + class3)/numclasses;
d.
logic error, gpa = class1 + class2 + (class3/numclasses);
22. Which file must be included in any program that uses the cin or cout objects?
a.
namespace
b.
stream
c.
io
d.
iostream
23. What can be used to provide a convenient way to merge the source code from one file with the source code in another
file, without having to retype the code?
a.
the $append directive
b.
the #include directive
c.
the using directive
d.
the @add directive
24. Which development component combines the object file with other machine code necessary for your C++ program to
run correctly?
a.
linker
b.
object code
c.
IDE
d.
source code
25. Which C++ program instruction will subtract a value of 3 from the sum variable?
a.
sum 3;
b.
sum -= 3;
c.
sum = -3(sum);
d.
sum ==-3;
26. The extraction operator stops removing characters from the cin object when it encounters which of the following?
a.
letter
b.
number
c.
white-space character
d.
none of the above
27. What is the first line in a function called?
a.
title
b.
header
Name:
Class:
Date:
Page 4
c.
block
d.
comment
28. The original program instructions entered into an editor is known as which of the following?
a.
linker
b.
object code
c.
IDE
d.
source code
29. What type of objects are used in C++ to handle standard input and output operations?
a.
inout
b.
io
c.
data
d.
stream
30. Which of the following is defined in C++ as a sequence of characters?
a.
cin
b.
cout
c.
stream
d.
endline
31. What symbol is used in C++ for the modulus operator?
a.
&
b.
$
c.
%
d.
#
32. What is the code contained between a function’s opening and closing braces known as?
a.
header
b.
body
c.
return
d.
comment
33. Explicit type conversion is accomplished in C++ with which of the following operators?
a.
type_cast
b.
explicit
c.
static_cast
d.
convert
34. Which object tells the computer to pause program execution while the user enters one or more characters at the
keyboard?
a.
cin
b.
cout
c.
stream
d.
endline
35. To insert a comment into a C++ program you begin the line with which of the following?
a.
||
b.
\\
c.
**
d.
//
36. In C++, which file contains all of the machine code necessary to run a program as many times as desired without the
need for translating the program again?
a.
compiler
b.
object file
c.
source file
d.
executable file
37. Dividing one integer by another integer in C++ may not give you the result you are expecting. Explain, including an
example, what occurs in C++ when one integer is divided by another integer.
38. Why is it important that each cin statement should be preceded by an accompanying cout statement?
Name:
Class:
Date:
Page 5
39. Add the necessary stream manipulators to the cout statements shown below to produce the following output:
A
BC
D
Note that you can only add the appropriate stream manipulators, not change the string literal constants within the cout
statements.
cout << “A”;
cout << “B”;
cout << “C”;
cout << “D”;
40. How should the average calculation below be modified to compute the correct average of the two numbers?
int num1 = 10;
int num2 = 20;
double average = 0.0;
average = num1 + num2 / 2;
41. Write the C++ statements to declare a variable called age, and prompt the user for their age.
42. Write the appropriate C++ statements using cin and cout that prompt the user for a base salary, and a percentage raise
and then displays the line “Your new salary is: NewSalary” where NewSalary is the calculated new salary. End with a new
line.
43. Write the equivalent C++ statement of the following statement using a single arithmetic assignment operator.
sum = sum + 47;
44. Explain exactly what happens during the execution of a cin statement. Include in your answer the terms cin,
extraction operator, and white-space character. Begin where characters are typed at the keyboard.
45. Draw a flow diagram that incorporates the following terms from where the programmers enter the source code to
where there is a valid executable file ready for execution: source code, compiler, linker, executable code, and additional
code (other necessary machine language code).
Name:
Class:
Date:
Page 6
Name:
Class:
Date:
Page 7
Name:
Class:
Date:
Page 8