Quiz & Exam Review (#2) - previous deck disappeared Flashcards
Which of the following casting expressions is recommended by the ANSI standard?
- intVar = (int)doubleVar;
- intVar = int(doubleVar);
- intVar = static_cast(doubleVar);
- intVar = (double)doubleVar;
intVar = static_cast(doubleVar);
The values in an enumerated data type are actually stored as integers.
- True
- False
True
What is the correct order of precedence of the logical (Boolean) operators?
- ||, !, &&
- &&, ||, !
- !, &&, ||
- &&, !, ||
!, &&, ||
Opening a file is an operation that can fail, so you should test for that possibility.
- True
- False
True
The rand() function automatically generates a different sequence of random values each time you run your program.
True
False
False
Which two of the following can be used to make subsequent console output begin on a new line?
endl
cin
‘\t’
‘\n’
endl
and
‘\n’
What order do the parts of a function header appear in?
- name, parameter list, return type
- name, return type, parameter list
- return type, name, parameter list
- parameter list, name, return type
return type, name, parameter list
A vector’s “size” and “capacity” are two different things.
- True
- False
True
include does what?
- prints “iostream”
- replaces occurences of “include” with “iostream”
- resets the cursor
- gives a program access to a library of input/output functions
gives a program access to a library of input/output functions
RAM is a type of secondary storage.
- True
- False
False
Which two of the following make up a CPU?
RAM
control unit
ROM
ALU
Control Unit
and
ALU
A variable of which type is used to hold a true or false value?
- int
- char
- bool
- double
bool
A set of well-defined steps for performing a task or solving a problem is a(n)
- input device
- statement
- compiler
- algorithm
algorithm
What will be the output of the following line of code?
std::cout << 5 / 4 << std::endl;
- 1.25
- 0
- 1
- 0.8
1
Which of the following statements is true?
- A local variable can have the same name as a global variable, but then it cannot be accessed, because when you use that name, it will refer to the global variable instead of the local variable.
- A local variable cannot have the same name as a global variable.
- A variable declared at the function level cannot have the same name as one of that function’s parameters, because they would have the same scope.
A variable declared at the function level cannot have the same name as one of that function’s parameters, because they would have the same scope.
By default classes are passed to a function by reference.
- True
- False
False
Which of the following is a valid vector declaration?
- double nums;
- vector(10);
- string words[10];
- vector data(10);
vector data(10);
While loops are specifically designed for the case when you know at the beginning of the loop how many times it should repeat.
- True
- False
False
If a variable is passed as a parameter to a function, the name used for that parameter within the function must match that of the variable.
- True
- False
False
What would be the result of the following expression?
5 + 6 % 4
4
0
7
2
7
Which of the following allows you to read in a multi-character string that contains whitespace?
- cin >> myString;
- myString = cin.ignore(‘\n’);
- getline(cin, myString);
- cin.get(myString);
getline(cin, myString);
What would be the result of the following expression?
5 + 6 % 4
0
2
7
4
7
Machine language is written as a sequence of 1s and 0s referred to as
ternary
decimal
high level language
binary
Binary
You should avoid using global variables.
- True
- False
True
n certain rare cases a class will be separated into two files, an interface file and an implementation file.
- True
- False
False
What is cout used for?
- declaring a variable
- input from the console
- output to the console
- editing code
output to the console
What does cin do?
- displays output to the console
- reads input from the console
- formats output
- declares a string variable
reads input from the console
A constructor must have a return type of void.
- True
- False
False
A named storage location in computer memory for holding a piece of data whose value can change is a
- constant
- reserved word
- RAM
- variable
variable
Assuming x is 2, y is 7 and z is 5, which of the following relational expressions is true?
- !(z == 2 || x < 7) && (y != 3 || z > 2)
- x == z || y % z == x
- x + y + z < x + z
- x + z == y && z == x - y
x == z || y % z == x
The following code is meant to output whether a given number is even or odd. It compiles and runs without crashing, but it says that every number is odd. What line is the error in? (Hint: it would only take a single keystroke to fix it!)
int num; std::cout \<\< "Please enter an integer." \<\< std::endl; std::cin \>\> num; int test = num % 2; if (test = 0) std::cout \<\< "your number is even" \<\< std::endl; else std::cout \<\< "your number is odd" \<\< std::endl;
- else
- if (test = 0)
- std::cin >> num;
- int test = num % 2;
if (test = 0)
Which is true of the following nested loop?
int total = 0; for (int i=0; i for (int j=0; j total = total + i + j;
- It will increment i and j together.
- It will run through all values of i while j is equal to 0, then all values of i again while j is equal to 1, then all values of i again while j is equal to 2.
- It will run through all values of j while i is equal to 0, then all values of j again while i is equal to 1, then all values of j again while i is equal to 2.
It will run through all values of j while i is equal to 0, then all values of j again while i is equal to 1, then all values of j again while i is equal to 2.
How many elements are allocated by the following array declaration?
int myArray[15];
- 14, one less than the number used to declare the array
- 15, the number entered in the declaration
- 0, no elements are allocated until some values are initialized
- 10, the default number of elements in an array
15, the number entered in the declaration
Which of the following is not part of the CPU cycle?
- fetch
- execute
- decode
- display
Display
What would be the result of the following code?
int total = 0; for (int i=1; i != 10; i += 2) { total += i; } std::cout \<\< "total = " \<\< total \<\< std::endl;
- It would print 25.
- There would be a syntax error message.
- It would print 20.
- It’s an infinite loop - I would have to stop the program myself.
It’s an infinite loop - I would have to stop the program myself.
Creating a file stream object and opening a file to be read are two separate operations.
- True
- False
True
Each character is assigned a numeric code according to a system called ASCII.
- True
- False
True
If you define any constructors for a class, the compiler will not automatically provide a default constructor.
- True
- False
True
In C++ a single array may store different data types.
- True
- False
False
Closing files is a formality that doesn’t actually affect anything.
- True
- False
False
What is the output of the following code?
int nums[] = {1,2,3,4}; nums[2] = 7; for (int i=0; i std::cout \<\< nums[i] \<\< " "; std::cout \<\< std::endl;
- 1 2 7 4
- 1 7 3 4
- 1 7 2 4
- 1 3 7 4
1 2 7 4
A program that translates source code instructions into the appropriate machine language instructions is a(n)
- source file
- preprocessor
- executable
- compiler
Compiler
An object’s private member variables can be accessed by…
- any member function of that object
- any private function of any object
- using the dot operator
- using the scope resolution operator
any member function of that object
You indicate that a function does not return a value by…
- giving it a return type of “void”.
- giving a reference type as tthe return type.
- leaving out the return type.
- putting a “&” in front of the function name.
giving it a return type of “void”.
cin requires the user to press the [Enter] key after entering data.
- True
- False
True
The name you give a class when you define it can then be used much like you would use the names of built-in types such as double and char.
- True
- False
True
After the following line of code executes, what will be the value of num?
num = 2 < 3 ? 4 : 5;
- 4
- 2
- 5
- 3
4
An else gets matched up with the if statement closest to the beginning of the program that does not already have its own else.
- True
- False
False
When a function has both required arguments and default arguments, the default arguments must be listed first in the function header (and prototype, if any).
- True
- False
False