l Exam Study Guide TRUE/FALSE. Write \'T\' if the statement is true and \'F\' if
ID: 3719880 • Letter: L
Question
l Exam Study Guide
TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false.
1)
Any ‘for’ instruction can be re-written as a ‘while’instruction.
1)
_______
2)
Polymorphism occurs when there are several functions with the same name in one file.
2)
_______
3)
The opposite of (x > 3 && x < 10) is (x < 3 && x > 10).
3)
_______
4)
Object is to a class what a type is to a variable.
4)
_______
5)
#ifndef is a pre-processor directive.
5)
_______
6)
The first run-time argument is always considered to be the name of the program.
6)
_______
7)
The argc parameter in the following construction is a counter:
int main (int argc, char *argv[])
7)
_______
8)
If x has the value of 3, y has the value of -2, and w is 10, is the following condition true or false?
if( x < 2 && w < y)
8)
_______
SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question.
9)
<< is called the ________ operator.
9)
_____________
10)
The braces for a loop define the ________ of the loop.
10)
_____________
11)
A loop that always executes the loop body at least once is known as a ________ loop.
11)
_____________
12)
int myValue; is called a ________.
12)
_____________
13)
What is the opposite of ( x < 20 && x > 12)?
13)
_____________
14)
Each time a loop body executes is known as an ________.
14)
_____________
15)
if-else statements that are inside other if-else statements are said to be ________.
15)
_____________
16)
>> is known as the ________ operator.
16)
_____________
17)
Is << used for input or output?
17)
_____________
18)
The stream that is used for input from the keyboard is called ________.
18)
_____________
19)
The stream that is used for output to the screen is called ________.
19)
_____________
20)
Write the loop condition to continue a while loop as long as x is negative.
20)
_____________
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
21)
Which of the following is a valid identifier?
21)
______
A)
3_com
B)
3com
C)
dollar$
D)
three_com
E)
3-com
22)
Which of the following is not a valid identifer?
22)
______
A)
return
B)
myInt
C)
total3
D)
myInteger
23)
What is the value of x after the following statements?
int x, y, z;
y = 10;
z = 3;
x = y * z + 3;
23)
______
A)
garbage
B)
33
C)
30
D)
60
24)
What is the value of x after the following statements?
int x;
x = 0;
x = x + 30;
24)
______
A)
30
B)
0
C)
garbage
D)
33
25)
What is the output of the following code?
float value;
value = 33.5;
cout << value << endl;
25)
______
A)
33
B)
33.5
C)
value
D)
garbage
26)
What is the output of the following code?
float value;
value = 33.5;
cout << "value" << endl;
26)
______
A)
33.5
B)
value
C)
33
D)
garbage
27)
Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat?
27)
______
A)
cin >> myFloat >> endl;
B)
cin >> myFloat;
C)
cin << myFloat;
D)
cin >> "myFloat";
28)
Which of the following statements is NOT legal?
28)
______
A)
char ch = '0';
B)
char ch = 65;
C)
char ch = "cc";
D)
char ch = 'b';
29)
What is the value of x after the following statements?
int x;
x = 15/4;
29)
______
A)
15
B)
3.75
C)
3
D)
4
30)
Given the following code fragment and the input value of 4.0, what output is generated?
float tax;
float total;
cout << "enter the cost of the item ";
cin >> total;
if ( total >= 3.0)
{
tax = 0.10;
cout << total + (total * tax) << endl;
}
else
{
cout << total << endl;
}
30)
______
A)
3
B)
4.0
C)
3.3
D)
4.4
31)
What is the correct way to write the condition y < x < z?
31)
______
A)
(y < x < z)
B)
( (y < x) && z)
C)
((y < x) && (x < z))
D)
((y > x) ?? (y < z))
32)
Given the following code fragment, and an input value of 5, what is the output?
int x;
if( x < 3)
{
cout << "small ";
}
else
{
if( x < 4)
{
cout << "medium ";
}
else
{
if( x < 6)
{
cout << "large ";
}
else
{
cout << "giant ";
}
}
}
32)
______
A)
large
B)
giant
C)
small
D)
medium
33)
Given the following code fragment, what is the output?
int x = 5;
if( x > 5)
cout << "x is bigger than 5. ";
cout << "That is all. ";
cout << "Goodbye ";
33)
______
A)
x is bigger than 5
B)
x is bigger than 5. That is all
C)
That is all. Goodbye
D)
Goodbye
34)
What is the final value of x after the following fragment of code executes?
int x = 0;
do
{
x++;
}while(x > 0);
34)
______
A)
10
B)
8
C)
9
D)
infinite loop.
E)
11
35)
What is wrong with the following switch statement?
int ans;
cout << "Type y for yes on n for no ";
cin >> ans;
switch (ans)
{
case 'y':
case 'Y': cout << "You said yes "; break;
case 'n':
case 'N': cout << "You said no "; break;
default: cout <<"invalid answer ";
}
35)
______
A)
break; is illegal syntax.
B)
ans is a int.
C)
nothing
D)
There are no break statements on 2 cases.
36)
How many times is "Hi" printed to the screen?
for(int i = 0;i < 14;i ++ );
cout << "Hi ";
36)
______
A)
1
B)
14
C)
15
D)
13
37)
What is wrong with the following for loop?
for(int i = 0;i < 10;i -- )
{
cout << "Hello ";
}
37)
______
A)
infinite loop
B)
cannot use a for-loop for this
C)
i is not initialized.
D)
off-by-one error
38)
Which of the following is a legal call to the displayOutput function?
void displayOutput(int total);
38)
______
A)
displayOutput(myTotal);
B)
cout << displayOutput(myTotal);
C)
void displayOutput(myTotal);
D)
displayOutput(int mytotal);
39)
Which of the following is true for a void function?
39)
______
A)
Nothing is returned.
B)
The value of void should be returned.
C)
The value of 0 should be returned.
D)
There cannot be a return statement.
40)
If you need a function to get both the number of items and the cost per item from a user, which would be a good function declaration to use?
40)
______
A)
int getData(float cost);
B)
void getData(int count, float cost);
C)
int,float getData( );
D)
void getData(int& count, float& cost);
TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false.
41)
A class member function may be private.
41)
______
42)
All constructors for a class must be private.
42)
______
SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question.
43)
The keyword ________ defines a structure type definition.
43)
_____________
44)
A structure definition ends with the closing brace and a ________.
44)
_____________
45)
A structure variable is a collection of smaller values called ________ values.
45)
_____________
46)
The name of a constructor is ________.
46)
_____________
47)
A member function that gets called automatically when an object of the class is declared is called a ________.
47)
_____________
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
48)
You specify an individual member of a struct by using
48)
______
A)
an underscore.
B)
the assignment operator.
C)
the dot operator.
D)
an ampersand.
49)
What is wrong with the following structure definition?
struct MyStruct
{
int size;
float weight;
}
49)
______
A)
cannot have mixed data types in a structure
B)
Braces are not needed.
C)
missing semicolon
D)
nothing
50)
Given the following structure definitions, what is the correct way to print the person's birth year?
struct DateType
{
int day;
int month;
int year;
}
struct PersonType
{
int age;
float weight;
DateType birthday;
}
PersonType person;
50)
______
A)
cout << year;
B)
cout << birthday.year;
C)
cout << person.birthday.year;
D)
cout << person.year;
51)
When defining a class, the class should be composed of the kind of values a variable of the class can contain, and
51)
______
A)
nothing else.
B)
member functions for that class.
C)
the keyword private.
D)
other class definitions.
52)
Which of the following is the correct function definition header for the getAge function which is a member of the Person class?
52)
______
A)
int Person:getAge( )
B)
int Person::getAge( )
C)
int getAge( )
D)
int getAge( );
53)
A class member function that automatically initializes the data members of a class is called
53)
______
A)
a cast.
B)
an operator.
C)
a constructor.
D)
the init function.
54)
If you have a class named myPersonClass, which of the following correctly declare a constructor in the class definition?
54)
______
A)
myPersonClass::myPersonClass( );
B)
myPersonClass( );
C)
cast( );
D)
init( );
55)
Given the following class, what would be the best declaration for a mutator function that allows the user of the class to change the age?
class Wine
{
public:
Wine( );
int getAge( );
float getCost( );
private:
int age;
float cost;
}
55)
______
A)
void setAge(int newAge);
B)
int getAge(int newAge);
C)
void setAge( );
D)
Wine( );
56)
Given the following class, what would be the best declaration for a constructor that would allow the user to initialize the object with an initial age and cost?
class Wine
{
public:
Wine( );
int getAge( );
float getCost( );
private:
int age;
float cost;
}
56)
______
A)
Wine( );
B)
int getAge(int newAge);
C)
Wine(int age);
D)
Wine(int newAge, float newCost);
57) What will be the output of the C++ program?: 57)____
//all needed preprocessor directives should be here
A. 5 6
B. 5 5
C. 6 6
D. the program will not run
Explanation / Answer
Hi, I have answered firt 6 Qs.
Please repost others.
1. Any ‘for’ instruction can be re-written as a ‘while’instruction.
Ans: True
2. Polymorphism occurs when there are several functions with the same name in one file.
Ans: False
3. The opposite of (x > 3 && x < 10) is (x < 3 && x > 10).
Ans: False
4. Object is to a class what a type is to a variable.
Ans: True
5.#ifndef is a pre-processor directive.
Ans: True
6. True
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.