Quiz & Exam Review (#2) - previous deck disappeared Flashcards

1
Q

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;
A

intVar = static_cast(doubleVar);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

The values in an enumerated data type are actually stored as integers.

  • True
  • False
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the correct order of precedence of the logical (Boolean) operators?

  • ||, !, &&
  • &&, ||, !
  • !, &&, ||
  • &&, !, ||
A

!, &&, ||

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Opening a file is an operation that can fail, so you should test for that possibility.

  • True
  • False
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The rand() function automatically generates a different sequence of random values each time you run your program.

True
False

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which two of the following can be used to make subsequent console output begin on a new line?

endl
cin
‘\t’
‘\n’

A

endl

and

‘\n’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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
A

return type, name, parameter list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A vector’s “size” and “capacity” are two different things.

  • True
  • False
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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
A

gives a program access to a library of input/output functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

RAM is a type of secondary storage.

  • True
  • False
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which two of the following make up a CPU?

RAM
control unit
ROM
ALU

A

Control Unit

and

ALU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A variable of which type is used to hold a true or false value?

  • int
  • char
  • bool
  • double
A

bool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A set of well-defined steps for performing a task or solving a problem is a(n)

  • input device
  • statement
  • compiler
  • algorithm
A

algorithm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What will be the output of the following line of code?

std::cout << 5 / 4 << std::endl;

  • 1.25
  • 0
  • 1
  • 0.8
A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

By default classes are passed to a function by reference.

  • True
  • False
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of the following is a valid vector declaration?

  • double nums;
  • vector(10);
  • string words[10];
  • vector data(10);
A

vector data(10);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What would be the result of the following expression?

5 + 6 % 4

4
0
7
2

A

7

16
Q

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);
A

getline(cin, myString);

16
Q

What would be the result of the following expression?

5 + 6 % 4

0
2
7
4

A

7

17
Q

Machine language is written as a sequence of 1s and 0s referred to as

ternary
decimal
high level language
binary

A

Binary

18
Q

You should avoid using global variables.

  • True
  • False
A

True

19
Q

n certain rare cases a class will be separated into two files, an interface file and an implementation file.

  • True
  • False
A

False

21
Q

What is cout used for?

  • declaring a variable
  • input from the console
  • output to the console
  • editing code
A

output to the console

22
Q

What does cin do?

  • displays output to the console
  • reads input from the console
  • formats output
  • declares a string variable
A

reads input from the console

23
Q

A constructor must have a return type of void.

  • True
  • False
A

False

24
Q

A named storage location in computer memory for holding a piece of data whose value can change is a

  • constant
  • reserved word
  • RAM
  • variable
A

variable

25
Q

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
A

x == z || y % z == x

26
Q

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;
A

if (test = 0)

28
Q

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.
A

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.

29
Q

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
A

15, the number entered in the declaration

31
Q

Which of the following is not part of the CPU cycle?

  • fetch
  • execute
  • decode
  • display
A

Display

32
Q

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.
A

It’s an infinite loop - I would have to stop the program myself.

33
Q

Creating a file stream object and opening a file to be read are two separate operations.

  • True
  • False
A

True

34
Q

Each character is assigned a numeric code according to a system called ASCII.

  • True
  • False
A

True

35
Q

If you define any constructors for a class, the compiler will not automatically provide a default constructor.

  • True
  • False
A

True

36
Q

In C++ a single array may store different data types.

  • True
  • False
A

False

38
Q

Closing files is a formality that doesn’t actually affect anything.

  • True
  • False
A

False

39
Q

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
A

1 2 7 4

41
Q

A program that translates source code instructions into the appropriate machine language instructions is a(n)

  • source file
  • preprocessor
  • executable
  • compiler
A

Compiler

42
Q

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
A

any member function of that object

43
Q

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.
A

giving it a return type of “void”.

45
Q

cin requires the user to press the [Enter] key after entering data.

  • True
  • False
A

True

46
Q

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
A

True

47
Q

After the following line of code executes, what will be the value of num?

num = 2 < 3 ? 4 : 5;

  • 4
  • 2
  • 5
  • 3
A

4

48
Q

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
A

False

49
Q

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
A

False