Multiple Choice Questions Flashcards

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

. ________ is the physical aspect of the computer that can be seen
a) hardware
b) Software
c) Operating system
d) Application programming

A

Hardware

some hardware components of a computer include: CPU, memory, hard disk, printer, and communication devices

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

__________ is the brain of a computer.
a) Hardware
b) CPU
c) Memory
d) Disk

A

CPU

the CPU retrieves instructions from the memory and executes them

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

One byte has __ bits
a) 4
b) 8
c) 12
d) 16

A

8

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

A computers _____ is volatile; that is, any information stored in it is lost when the systems power is turned off
a) Floppy disk
b) Flashdisk
c) CD-ROM
d) memory

A

Memory

The memory of the computer is used to store data and program instructions for the CPU to execute. The memory is volatile, so when power is turned off information is lost. That is why information is stored in storage devices.

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

Computers can execute the code in ______
a) machine language
b) assembly language
c) high-level language
d) none of the above

A

Machine Language

Machine language is a computers native language, a set of built in primitive instructions
ex. adding two numbers would look something like
1101101010011010

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

_____ translates high level language program into machine language program
a) An assembler
b) A compiler
c) CPU
d) the operating system

A

A compiler

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

_____ is an operating system
a) Java
b) C++
c) Windows
d) Visual basics

A

Windows

An operating system is an important program that manages and controls a computers activities

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

_______ is a program that runs on a computer to manage and control a computers activities
a) Operating System
b) C++
c) interpreter
d) Complier

A

Operating System

an example of an operating system is Windows

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

Which of the following statements is the correct way to displau Welcome to C++ on the console?
A) cout &laquo_space;“Welcome to C”;
B) cout&raquo_space; “Welcome to C”;
C) cout < “Welcome to C”;
D) cout &laquo_space;‘Welcome to C’

A

cout &laquo_space;“Welcome to C”;

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

Which of the following preprocessor directive is correct?
A) import iostream
B) #include <iostream>
C) include <iostream>
D) #include iostream</iostream></iostream>

A

include <iostream></iostream>

a compiler preprocessor directive that tells the compiler to include the iostream library in the program. It is needed to support console input and output

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

Every statement in C ends with ________, which is called a statement terminator
A) a semicolon (;)
B) a comma (,)
C) a peiod (.)
D) an asteisk (*)

A

A semicolon ;

a statement is a complete and separate instruction that preforms some action.

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

A block is enclosed inside __________.
A) Parentheses
B) Braces
C)Brackets
D) Quotes

A

Braces

a block is a set of statements that are grouped together and treated as one unit

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

Which of the following statements is correct?

A) Every line in a program must end with a semicolon

B) Every statement in a program must end with a semicolon

C) Every comment line must end with a semicolon

D) Every function must end with a semicolon

E) Every preprocessor directive must end with a semicolon

A

Every statement in a program must end with a semicolon

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

What is the output of the following code?
cout &laquo_space;“1 + 2 +3” &laquo_space;endl;
cout «1 +2 +3 &laquo_space;endl;

A) 1 + 2 + 3 followed by 6
B) “6” followed by 6
C) 1 + 2 + 3 followed by 1 + 2 + 3
D) 6 followed by 6

A

1 + 2 + 3 followed by 6

cout &laquo_space;“1 + 2+ 3” &laquo_space;endl;
cout &laquo_space;1 +2 + 3 &laquo_space;endl;

anything in quotation marks is displayed exactly as seen.

Since the next line is not in quotation marks, it will be calculated and the answer will be displayed.

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

___________ is called a stream insertion operator for sending output to the console.
A) a semicolon (;)
B) a comma (,)
C) a peiod (.)
D) an asteisk (*)
E) «

A

«

The &laquo_space;is used to insert data into the output stream.

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

C++ compiler translates C++ source code into _________.
A) Java code
B) machine code
C) C code
D) another high-level language code

A

Machine code

The computer can only read machine code, so the compiler takes everything in C++ language and translates it into machine language so the computer can execute it.

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

Suppose you create a C as follows, the source code should be stored in a file named ___________.

int main()
{

}

A) Test.cpp
B) Test.doc
C) Test.txt
D) Test.java
E) Any name with extension .cpp

A

Any name with extension .cpp

When naming the source code it is really only being named for your use. You can call it anything you want, just maker sure it is followed by .cpp

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

If a program compiles fine, but it produces incorrect result, then the program suffers
__________.
A) a compilation/syntax eror
B) a runtime eror
C) a logic error

A

a logic error

A logic error is when the program does not run the way it was intended. These errors are really hard to identify.

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

include <iostream></iostream>

The following code has _______.

using namespace std;

int main()
{
cout &laquo_space;“Welcome to C++ &laquo_space;endl;
return 0;
}

A) a compilation/syntax eror
B) a runtime eror
C) a logic error

A

A compilation/ syntax error

A compiler/ syntax error is one detected by the compiler. You can see that there is a missing quotation mark, a mistake made by the programmer.

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

____________ is the assignment operator.
A ==
B :=
C =
D =:

A

=

the assignment operaotr is used to assign a value to a variable.

ex.
int x=5
the assignment operator is used to assign the value of 5 to the variable x

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

To assign a value 1 to variable x, you write
1 = x;
B x = 1;
C x := 1;
D 1 := x;
E x == 1;

A

x=1;

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

Which of the following types can be used to define a floating-point numbers?
A) int
B) shot
C) long
D) double

A

double

use when the variable can be a decimal number

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

To improve readability and maintainability, you should declare a _________ for PI instead of
using literal values such as 3.14159.

A) variable
B) function
C) constant
D) class

A

constant

declaring a constant allows you to create a value that cannot be changed throughout the program.

ex. declaring a constant for pi
const double pi = 3.14159;

now, anytime you use pi in your program its value that was initialized will be used.

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

To declare a constant MAX_LENGTH inside a function with value 99.98, you write
A)const MAX_LENGTH = 99.98;
B) double MAX_LENGTH = 99.98;
C) const double MAX_LENGTH = 99.98;

A

const double MAX_LENGTH = 99.98;

this statement is declaring a constant variable called MAX_LENGTH. This number will stay the same throughout the entire program i=since it is a constant. It can also be a decimal number since it is a double type

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

What is the result of (4 + 1) * ((5 - 2) / 2)?

A) 4
B) 5
C) 5.0
D) 7.5
E) 5.5

A

5

(3/2) is 1.5 but since the function used 3 and not 3.0 the answer is rounded down to 1. The rest of the equation makes the answer equal to 5.

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

Which of the following are correct ways to declare variables? Please select all that apply.
A) int length; int width;
B) int length, width;
C) int length; width;
D) int length, int width;

A

int length; int width;

this declares integer variables named length and width. you can also split this into two separate lines and the same thing would happen.

int length, width;

this function also declares two variables int length and int width.

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

include <iostream></iostream>

Analyze the following code.

using namespace std;

int main()
{
int month = 09;
cout &laquo_space;“month is “ &laquo_space;month;
return 0;
}

A) The program displays month is 09
B) The program displays month is 9
C) The program displays month is 9.0
D) The program has a syntax error, because 09 is an incorrect literal value.

A

The program has a syntax error, because 09 is an incorrect literal value.

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

What is result of 45 / 4?
A) 10
B) 11
C) 11.25
D) 12

A

11

the answer is rounded down since 45.0 was not used

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

25 % 1 is _____.
A 1
B 2
C 3
D 4
E 0

A

0

if you divide 25 by 1 there is 0 remaining.

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

The __________ function returns a raised to the power of b
A power(a, b)
B exponent(a, b)
C pow(a, b)
D pow(b, a)

A

pow (a,b)

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

To write 2.1 ^ 2.4 in C++, use _____
A pow(2.4, 2.1)
B pow(2.1, 2.4)
C 2.1 * 2.4
D 2.1 * 2.1

A

pow(2.1, 2.4)

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

pow(2.0, 3) returns __________.
A 9
B 8
C 1
D 0

A

8

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

What is x after the following statements?
int x = 2;
int y = 1;
x *= y + 1;

A x is 1.
B x is 2.
C x is 3.
D x is 4.

A

4

The statement x* = y+1 multiplies the value of x by the result of y+1

(basically a trick is do the math but ignore the = sign)

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

Suppose x is 1. What is x after x+=2?
A) 0
B) 1
C) 2
D) 3
E) 4

A

3

ignore = sign and solve

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

invoking time(0) returns____

A) the hour, minute, and second of the current time.

B) the elapsed time in milliseconds since Midnight, Jan 1, 1970 GMT.

C) the elapsed time in seconds since Midnight, Jan 1, 1970 GMT.

D) the elapsed time in minutes since Midnight, Jan 1, 1970 GMT.

A

the elapsed time in seconds since Midnight, Jan 1, 1970 GMT.

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

The time function is defined in the ________ header file.
A time
B ctime
C cctype
D cstdlib
E cmath

A

ctime

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

What will be the output of the following code?
int i 1;
int j = i++;
cout &laquo_space;“i is “ &laquo_space;i;
cout &laquo_space;” and j is “ &laquo_space;j;

A) i is 1 and j is 1
B) i is 1 and j is 2
C) i is 2 and j is 1
D) i is 2 and j is 2

A

i is 2 and j is 2

i is initialized to the value 1. then it assigns i to j and it increments the value of i by 1. since i is not a constant its value is changed to 2

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

Are the following four statements equivalent?
number 1;
number = number 1;
number++;
++number;

A) yes
B) no

A

yes

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

The equal comparison operator is __________.
A <>
B !
C ==
D =

A

==

the equal comparison operator is used to compare two values. It checks to see if both numbers on each side of the operator are equal.

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

Which of the following is incorrect?
A The word tue is a C keyword
B The word tue is a Boolean literal
C The word true is same as value 1
D The word true is same as value 0

A

The word true is same as value 0

true is assigned to 1
false is assigned to 0

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

What is 1 + 1 + 1 + 1 + 1 == 5?
A tue
B false
C There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is tue.

A

true

the equal comparison operator checks both signs of the equal signs

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

Which of the following code displays the area of a circle if the radius is positive.

A if (radius ! 0) cout &laquo_space;radius * radius * 3.14159;
B if (radius > 0) cout &laquo_space;radius * radius * 3.14159;
C if (radius <= 0) cout &laquo_space;radius * radius * 3.14159;

A

if (radius > 0 cout &laquo_space;radius * radius * 3.14159;

this function is preformed if radius is greater than 0

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

What is the output of the following code?

int x = 0;
if (x < 4)
{
x = x + 1;
}
cout &laquo_space;“x is “ &laquo_space;x &laquo_space;endl;

A x is 0
B x is 1
C x is 2
D x is 3
E x is 4

A

x is 1

the if statement check to see if x is less then 4, since it is the statement is preformed

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

Analyze the following code.

bool even = false;
if (even)
{
cout &laquo_space;“It is even!”;
}

A The code displays: It is even!

B The code displays nothing.

C The code is wrong. You should replace if (even) with if (even == true)

D The code is wrong. You should replace if (even) with if (even = true)

A

The code displays nothing.

int the if statement the condition ‘even’ is evaluated. since ‘even’ is false , the statement is not executed

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

Suppose isPrime is a boolean variable, which of the following is the correct and best
statement for testing if isPrime is true.

A) if (isPrime = true)
B) if (isPrime == true)
C) if (isPrime)
D) if !isPrime = false)
E) if !isPrime == false)

A

if (isPrime)

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

What is the output of the following code?

int number =8;
if (number < 8)
cout &laquo_space;1 &laquo_space;endl;
else
cout &laquo_space;2 &laquo_space;endl;

A 1
B 2
C nothing
D 1 2
E 2 1

A

2

the fist if statement is not met, it then moves onto the next else statement and the code displays 2

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

The following code displays____.

double temperature = 50;
if (temperature >= 100)
cout &laquo_space;“too hot” &laquo_space;endl;
else if (temperature <= 40)
cout &laquo_space;“too cold” &laquo_space;endl;
else
cout &laquo_space;“just right” &laquo_space;endl;

A too hot
B too cold
C just right
D too hot too cold just right

A

just right

48
Q

What is the output of the following code?
Hint: pay attention to the Boolean Expression!

int score = 70;
if (score = 100)
cout &laquo_space;“A perfect score” &laquo_space;endl;
else
cout &laquo_space;“Not a perfect score” &laquo_space;endl;

A) a perfect score
B) Not a perfect score

A

A perfect score

notice how = is used and not == . this resultsw in score being set to 100.

49
Q

Suppose income is 4001, what is the output of the following code:
if (income > 3000)
{
cout &laquo_space;“Income is greater than 3000” &laquo_space;endl;
}
else if (income > 4000)
{
cout &laquo_space;“Income is greater than 4000” &laquo_space;endl;
}

A no output
B Income is greater than 3000
C Income is greater than 3000 followed by Income is greater than 4000
D Income is greater than 4000
E Income is greater than 4000 followed by Income is greater than 3000

A

Income is greater than 3000

since the first expression i checked and matches, it is then carried out

50
Q

Which function returns a random integer?
A srand()
B srand(0 )
C rand()
D rand(0 )

A

rand ()

51
Q

What is the minimum and maximum possible return from invoking rand()?

A 0 and 10000000
B 10000000 and 10000000
C 0 and RAND_MAX
D 0 and RANDMAX

A

0 and RAND_MAX

no negative numbers are ever returned

52
Q

Assume x = 4, Which of the following is true?

A !(x == 4)
B x != 4
C x == 5
D x != 5

A

x!=5

the != means not equal

53
Q

Suppose x = 10 and y = 10 What is x after evaluating the expression (y > 10) && (x++ > 10) ?

A 9
B 10
C 11

A

10

when the && operator evaluates, it evaluates the left side first. if it is false, the left is ignored

&& means both while || means or

54
Q

Suppose x = 10 and y = 10 what is x after evaluating the expression (y >= 10 )|| (x++ > 10)?
A 9
B 10
C 11

A

10

since the first expression is true, the second is not evaluated. since y is equal to 10 the second part is ignored.

Note- if the first one was false, then it would move on to the right side

55
Q

Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100, or the number is negative?

A 1 < x < 100 && x < 0
B ((x < 100) && (x > 1)) || (x < 0)
C ((x < 100 )&& (x > 1 && (x < 0)
D (1 > x > 100) || (x < 0)

A

((x < 100) && (x > 1)) || (x < 0)

56
Q

What is y after the following statement is executed?
x = 0;
y = (x> 0) ? 10 : -10;

A 10
B 0
C 10
D 20

A

-10

since the first expression is false, the value of -10 is assigned to y

57
Q

What will be displayed by the following switch statement?

char ch = ‘a’;
switch (ch)
{
case ‘a’:
cout &laquo_space;ch &laquo_space;endl; break;
case ‘b’:
cout &laquo_space;ch &laquo_space;endl; break;
case ‘c’:
cout &laquo_space;ch &laquo_space;endl; break;
case ‘d’:
cout &laquo_space;ch &laquo_space;endl;

A abcd
B a
C aa
D ab

A

a

58
Q

What is y after the following switch statement is executed?

int x = 3; int y = 4;
switch (x +3 )
{
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}

A 1
B 2
C 3
D 4

A

2

breakdown of code:
-switch (x+3) is evaluated and it equals 6. case 6 is then evaluated.
-y is now assigned to 0
-since there is no break statement the next case is evaluated, assigning 1 to y
-the next case is evaluated assigning y to 2

since there was no break statement, the cases continue to be executed until the end.

the switch statement allows you to select one of many code blocks to be executed based off of the value of the given expression.

Break statement: after executing a code block, the break statement is used to exit the switch statement. Without a break statement, the execution will continue to the next case.

59
Q

What is sqt(4.0)?
A 2
B 2.5
C 1
D 3.0

A

2

60
Q

What is ceil(3.6)
A 2
B 3
C 4
D 5

A

4

61
Q

What is floor(3.6)?
A 2
B 3
C 4
D 5.0

A

3

62
Q

What is max(min(3, 6), 2)?
A 2
B 3
C 4
D 5.0

A

3

63
Q

Which of the following are NOT the functions in C++? Please select all that apply.

A srand()
B rand()
C rint()
D pow()
E random()

A

random()
rint()

64
Q

Which of the following is the correct expression of character 4?
A 4
B “4”
C ‘\0004’
D ‘4’

A

‘4’

65
Q

Which of the following assignment statements is correct? Please select all that apply.

A char c = ‘d’;
B char c = 100;
C char c = “d”;
D char c = “100”;

A

char c = ‘d’;
char c = 100;

66
Q

Note that the ASCII for character A is 65. The expression ‘A’ + 1 evaluates to ________.

A B
B 66
C A1
D Illegal expression
E 67

A

66

67
Q

The ASCII of ‘a’ is 97. What is the ASCII for ‘c’?
A 96
B 97
C 98
D 99

A

99

68
Q

Suppose x is a char variable with a value ‘b’. What will be displayed by the statement
cout &laquo_space;++x?
A a
B b
C c
D d

A

c

69
Q

Suppose i is an int type variable. Which of the following statements display the character whose ASCII is stored in variable i?

A cout &laquo_space;i;
B cout &laquo_space;static_cast<char>i;
C cout << static_cast<int>i;</int></char>

A

cout &laquo_space;static_cast<char>i;</char>

the static_cast is a casting operator that allows you to convert one data type to another

this uses the static_cast operator to convert the integer value in i to a character. it will then display the character corresponding to the ASCII value.

70
Q

What is the output of the following code?

char ch = ‘F’;
if (ch >= ‘A’ && ch <= ‘Z’)
cout &laquo_space;ch &laquo_space;endl

A F
B f
C nothing
D F f

A

F

F has a value of 70 in the ASCII
A is equal to 65
Z is equal to 90

71
Q

To return an uppercase letter from a character variable ch, we use:

A isdigit(ch)
B isalpha(ch)
C toupper(ch)
D tolower(ch)
E islower(ch)

A

toupper(ch)

this function is designed to convert lowercase characters to uppercase characters

72
Q

Suppose a sting is declared as sting s = “abcd”. What is s.length()?

A 1
B 2
C 3
D 4

A

4

the s.length() function is used to determine the length of a string and will return the number of characters in a string, this includes whitespaces and special characters.

A string is a sequence of characters enclosed in double quotation marks.

the s.length() function starts counting at 1.

73
Q

Suppose a sting is declared as sting s = “abcde”. What is s.at(0)?
A a
B b
C c
D d
E e

A

a

the s.at() function allows us to access individual characters within a string based off of their position.

Indexing starts at 0.

74
Q

If you read a sting input: PROGRAMMING IS FUN using the following code, what will s be?

cout &laquo_space;“Enter a sting:”;
sting s;
cin&raquo_space; s;

A PROGRAMMING IS FUN
B PROGRAMMING
C IS
D FUN

A

PROGRAMMING

this is assigning PROGRAMMING to variable s. If you want the entire string to be read, you have to use the getline function.

75
Q

If you read a sting input: PROGRAMMING IS FUN using the following code, what will s be?

cout &laquo_space;“Enter a sting:”;
sting s;
getline(cin, s);

A PROGRAMMING IS FUN
B PROGRAMMING
C IS
D FUN

A

PROGRAMMIN IS FUN

the getline function reads and displays the entire string that is entered.

76
Q

You can use _______ to set the width of a pint field.
A setw(width)
B setprecision(n)
C fixed
D showpoint
E left

A

setw(width)

field width- the field width refers to the number of characters allocated for a particular output field

the setw(width) function is in the <iomanip> library</iomanip>

77
Q

To create an object for reading data from file test.txt, use ________.

A ofstream(“test.txt”);
B ofstream input(“test.txt”);
C ifstream(“test.txt”);
D ifstream input(“test.txt”);

A

ifstream input(“test.txt”);

78
Q

To create an object for witing data to file test.txt, use ________.

A ofstream(“test.txt”);
B ofstream output(“test.txt”);
C ifstream(“test.txt”);
D ifstream output(“test.txt”);

A

ofstream output(“test.txt”);

79
Q

What is the output of the following code?
int x = 0;
while (x < 4 )
{
x = x + 1;
}
cout &laquo_space;“x is “ &laquo_space;x &laquo_space;endl;

A x is 0
B x is 1
C x is 2
D x is 3
E x is 4

A

x is 4

the function will be done a total of 4 times because x starts at 0

80
Q

What is the output of the following code?
int count = 5;
while (count > 0)
{
cout &laquo_space;count &laquo_space;” “;
count–;
}

A 5 4 3 2 1
B 4 3 2 1
C 4 3 2 1 0
D 5 4 3 2 1 0

A

5 4 3 2 1

81
Q

What will be displayed when the following code is executed?
int number = 6;
while (number > 0)
{
number -= 3;
cout &laquo_space;number &laquo_space;” “;
}

A 6 3 0
B 6 3
C 3 0
D 3 0 3
E 0 3

A

3 0

82
Q

What is the output of the following code?
int count = 0;
do
{
cout &laquo_space;count &laquo_space;” “;
count++;
}
while (count < 5);

A 1 2 3 4 5
B 2 3 4 5
C 0 1 2 3 4 5
D 0 1 2 3 4

A

0 1 2 3 4

the do while loop is always executed once. it then checks the requirements at the end of the statement.

The loop is executed for the first time, the value of count (0) is printed. It is then executed until x is 5 and not longer matches the requirements.

83
Q

. How many times will the following code pint “Welcome to C”?
int count= 0;
do
{
cout &laquo_space;“Welcome to C++”;
count++;
}
while (count ++ < 10);

A 8
B 9
C 10
D 11
E 0

A

11

84
Q

ollowing code pint “Welcome to C”?
int count= 0;
do
{
cout &laquo_space;“Welcome to C++”;
count++;
}
while (++count < 10);

A 8
B 9
C 10
D 11
E 0

A

10

85
Q

What is the number of iterations in the following loop:
for (int i =1; i < n; i++)
{
// iteration
}

A 2*n
B n
C n-1
D n+1

A

n-1

Loop Condition: The condition that determines whether the loop should continue or terminate. It is evaluated before each iteration.
i<n

Iteration: Each execution of the loop body is called an iteration.

Loop Counter: A variable that keeps track of the number of iterations performed.
i is incremented by 1 (i++)

86
Q

What is the number of iterations in the following loop:
for (int i =1; i <= n; i++)
{
// iteration
}

A 2*n
B n
C n-1
D n+1

A

n

87
Q

What is the output for y?
int y = 0;
for (int i = 0; i < 10; ++i)
{
y += i;
}
cout &laquo_space;y;

A 10
B 11
C 12
D 13
E 45

A

45

this code the variable y is initialized to 0. The for loop is then executed 10 times, with i starting at 0 and incrementing by 1 each time. Inside the loop the value of i is added to y using the += operator.

once ran through 10 times we have y= the sum of numbers from 0 to 9 which is 45

88
Q

Do the following two statements result in the same value in sum?
1
for (int i = 0; i < 10; ++i)
{
sum += i;
}

2
for (int i= 0; i <10; i++)
{
sum += i;
}

A yes
B no

A

yes

89
Q

Analyze the following code fragment:
double sum = 0;
double d = 0;
while (d != 10.0 )
{
d += 0.1;
sum += sum + d;
}

A The program does not compile because sum and d are declared double, but assigned with
integer value 0.

B The program never stops because d is always 0.1 inside the loop.

CThe program may not stop because of the phenomenon refered to as numeical inaccuracy for

operating with floating-point numbers.
D After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + … + 1.9

A

The program may not stop because of the phenomenon referred to as numerical inaccuracy for

90
Q

What is sum after the following loop terminates?

int sum= 0;
int item= 0;
do
{
item++;
sum += item;
if (sum > 4) break;
}
while (item 5);

A 5
B 6
C 7
D 8

A

6

91
Q

Will the following program terminate?
int balance=10;
while (true)
{
if (balance< 9)
break;
balance = balance -9;

A yes
B no

A

yes

92
Q

What is sum after the following loop teminates?
int sum = 0;
int item = 0;
do
{
item++;
if (item == 4) continue;
sum += item;
}
while (item 5);

A 10
B 11
C 12
D 13

A

11

93
Q

Will the following program terminate?

int balance =10;
while (true)
{
if (balance < 9)
continue;
balance = balance - 9;
}

A Yes
B No

A

no

94
Q

The signature of a function consists of ____________.
A function name
B function name and parameter list
C return type, function name, and parameter list
D parameter list

A

function name and parameter list

95
Q

The header of the main function in C++ is __________.
A Main(Sting[] args)
B Main(Sting args[])
C void main(Sting[] args)
D main(Sting[] args)
E int main()

A

int main()

96
Q

Arguments to functions always appear within __________.
A brackets
B parentheses
C curly braces
D quotation marks

A

parentheses

97
Q

Suppose your function does not return any value, which of the following keywords can be
used as a return type?
A void
B int
C double
D float
E unsigned shot

A

void

98
Q

Which of the following functions should be defined as void? Please select all that apply.

A Retun a sales commission, given the sales amount and the commission rate.

B Pint the calendar for a month, given the month and year.

C Return a square root for a number.

D Return a bool value indicating whether a number is even.

E Pint a character a specified number of times.

A

Pint the calendar for a month, given the month and year.

Pint a character a specified number of times.

99
Q

Suppose
void nPint(char ch, int n)
{
while (n > 0)
{
cout &laquo_space;ch;
n–;
}
}

A aaaaa
B aaaa
C aaa
D invalid call

A

aaaa

100
Q

C allows you to declare functions with the same name. This is called ________.

A function duplication
B function oveiding
C function overloading
D function redeclaration

A

function overloading

101
Q

include <iostream></iostream>

Analyze the following code

using namespace std;
int xfunction(int n, long t)
{
cout &laquo_space;“int”;
retun n;
}
long xfunction(long n)
{
cout &laquo_space;“long”;
retun n;
}
int main()
{
cout &laquo_space;xfunction(5;
retun 0;
}

The program displays int followed by 5.
B The program displays long followed by 5.
C The program uns fine but displays nothing.

A

he program displays long followed by 5.

102
Q

Which of the following are correct function prototypes for a function that returns the max value between two int values? Please select all that apply.

A int max(int num1, int num2);
B int max(int num1, int num2)
C int max(int, int);
D int max(num1, num2);
E max(int num1, int num2);

A

int max(int num1, int num2);

int max(int, int);

103
Q

Which of the following function declarations are illegal? Please select all that apply.

A void t1(int x, int y = 0, int z);
B void t2(int x = 0, int y = 0, int z);
C void t3(int x, int y = 0, int z = 0;
D void t4(int x = 0, int y = 0, int z = 0;

A

void t1(int x, int y = 0, int z);

void t2(int x = 0, int y = 0, int z);

104
Q

What is the output of the following code?
inline void pint(int i)
{
cout &laquo_space;i &laquo_space;endl;
}
int main()
{
pint(1);
return 0;
}

A 0
B 1
C 2
D nothing

A

1

105
Q

A vaiable defined inside a function is refered to as __________.

A a global vaiable
B a function vaiable
C a block vaiable
D a local vaiable

A

local variable

106
Q

What will be the output of the following code?
#include <iostream>
using namespace std;
int j 1;
int main()
{
int i 2;
int j 2;
cout << "i is " << i << " j is " << j << endl;
retun 0;
}</iostream>

A i is 2 j is 1
B i is 1 j is 1
C i is 1 j is 2
D i is 2 j is 2

A

i is 2 j is 2

107
Q

What is the representation of the third element in an aray called a?

A a[2]
B a(2)
C a[3]
D a(3)

A

a[2]

108
Q

If you declare an aray double list[] = 3.4, 2.0, 3.5, 5.5, list[1 is ________.

A 3.4
B 2.0
C 5.5
D undefined

A

2.0

109
Q

. If you declare an aray double list[] = 3.4, 2.0, 3.5, 5.5, the highest index in aray list is
__________.

A 0
B 1
C 2
D 3
E 4

A

3

110
Q

How many elements are in aray double list[5]?

A 4
B 5
C 6
D 0

A

5

111
Q

Can you copy an aray as follows:
int x[] = 120, 200, 16;
int y[3];

yes
no

A

no

112
Q

Which of the following statements is false?

A Evey element in an aray has the same type.

B The aray size is fixed after it is created.

C The aray size used to declare an aray must be a constant expression.

D The aray elements are initialized when an aray is created.

A

The aray elements are initialized when an aray is created.

113
Q

Analyze the following code.
#include <iostream>
using namespace std;
int main()
{
int x[3];
cout << "x[0 is " << x[0];
return 0;
}</iostream>

A The program has a compile eror because the size of the aray wasn’t specified when declaing
the aray.

B The program has a untime eror because the aray elements are not initialized.

C The program uns fine and displays x[0 is 0.

D The program has a untime eror because the aray element x[0 is not defined.

E x[0 has an arbitray value.

A

E x[0 has an arbitray value.

114
Q

Which of the following statements is valid? Please select all that apply

A int i(30);
B double d[30];
C int i[] = {3, 4, 3, 2};
D int[] i = {3, 4, 3, 2};
E int i[4] = {3, 4, 3, 2};

A

double d[30];

int i[] = {3, 4, 3, 2};

int i[4] = {3, 4, 3, 2};

115
Q

What is the corect tem for numbers[99]

A index
B index vaiable
C indexed vaiable
D aray vaiable
E aray

A

indexed vaiable

116
Q

include <iostream></iostream>

What is the output of the following code:

using namespace std;
int main()
{
int x[] = 120, 200, 16;
for (int i 0; i 3; i++)
cout &laquo_space;x[i] &laquo_space;” “;
retun 0;
}

A 120 200 16
B 16 200 120
C 200 120 16
D 16 120 200

A

120 200 16

117
Q

When you pass an aray to a function, __________ is passed to the aray parameter in the
function

A a copy of the aray
B a copy of the first element
C the stating address of the aray
D the length of the aray

A

the stating address of the aray