Quiz 1 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

double result = 15 / 6;

Given the assignment statement…. What is the value stored in result?

  1. 2.0
  2. 0
  3. Nothing, an error occurs. The program will not compile.
  4. 2.5
A
  1. 2.0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Recall that the slope formula is.... Assume the variable names y2, y1, x2, and x1` already exist in your program as integer values.

Which of the following assignment statements would correctly calculate the slope and store it in a floating-point variable called m?

  1. double m = y2 – y1 / x2 – x1;
  2. double m = static_cast<double>(y2 – y1) / (x2 – x1);
  3. double m = static_cast<double>(y2 – y1) / x2 – x1;
  4. double m = (y2 – y1) / (x2 – x1);
A
  1. double m = static_cast<double>(y2 – y1) / (x2 – x1);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Given the following information: a = 10 and b = 7.

Which of the following assignment statements will result in the variable answer containing the value true?

  1. bool answer = a == 12 && b > 7;
  2. bool answer = a == 12 || b >= 7;
  3. bool answer = a == 12 || b > 7;
  4. bool answer = a == 12 && b >= 7;
A
  1. bool answer = a == 12 || b >= 7;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Assume the following x = 5, y = 6, and z = 8. What is the result of the Boolean Expression: 7 <= x && z > 4?

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

Assume all variables have been declared properly and all includes are there.

The following is a valid assignment statement: sqrt(b * b + c * c) = a;

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

Assume the following, x = 5, y = 6, and z = 8. What is the result of the Boolean Expression: x != 5 || x <= y

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

Which header file would we need to include to gain access to tools that let us format our output in C++ ?

A

iomanip

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

Which of the following statements will correctly set the cout buffer to always display 3 decimal places?

  1. std::fixed; std::setprecision(3);
  2. std::cout << std::fixed;
  3. std::cout << std::setprecision(3);
  4. std::cout << std::fixed << std::setprecision(3);
A
  1. std::cout << std::fixed << std::setprecision(3);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A variable declared as const should be initialized to a value because you cannot change it later in the program.

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

Which header file would we need to include to gain access to cout and cin?

A

iostream

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

Which header file would we need to include to gain access to useful mathematical functions in C++?

A

cmath

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

What is the name and operator used to send get input from cin?

A

Extraction Operator >>

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

The \_\_\_\_\_\_\_\_ marks the beginning of a single line comment in C++.

A

\\

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

Which of the following data types uses the most memory?

  1. int
  2. float
  3. char
  4. double
A
  1. double
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

C++ is a(n) \_\_\_\_\_\_\_\_\_\_\_\_\_ language.

A

Compiled/compiler

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

A byte consists of how many bits?

A

8

17
Q

The \_\_\_\_\_\_\_\_\_ marks the beginning of a preprocessor directive in C++.

A

#

18
Q

Which operator gives the remainder?

A

%

19
Q

An integer divided by an integer in C++ always results in a floating point result. True or false?

A

False. It will store an integer result.

20
Q

An assignment statement always stores the result of the expression on the right hand side of the = in the variable on the left hand side. True or false?

A

True.

21
Q

cin << var;

Assuming the variable var exists and has been properly declared, the statement would try to read a value in and store it in the variable var. True or false?

A

False. The operator << is incorrect, and it should be >>

22
Q

Which of the following data types uses the least memory?

  1. double
  2. int
  3. char
  4. float
A

char

23
Q

Every C++ program must have a \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_?

A

main function

24
Q

A variable must be declared before it is used. True or false?

A

True.

25
Q

A set of well-defined logical steps is referred to as a(n) \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ in programming.

A

Algorithm

26
Q

What is the name and operator used to send output to cout?

A

Insertion Operator <<

27
Q

The variable name 3rd_number is a valid variable name. True or false?

A

False. It cannot begin with a number.