Computer Science homework help
Computer Science homework help
Question 1
1. Main memory is called ____.
read only memory
random access memory
read and write memory
random read only memory
3 points
Question 2
1. The ____ is the brain of the computer and the single most expensive piece of hardware in your personal computer.
MM
ROM
RAM
CPU
3 points
Question 3
1. The ____ carries out all arithmetic and logical operations.
IR
ALU
CU
PC
3 points
Question 4
1. The ____ holds the instruction currently being executed.
CU
IR
PC
ALU
3 points
Question 5
1. When the power is switched off, everything in ____ is lost.
main memory
secondary storage
hard disks
floppy disks
3 points
Question 6
1. ____ programs perform a specific task.
Application
System
Operating
Service
3 points
Question 7
1. The ____ monitors the overall activity of the computer and provides services.
Central Processing Unit
operating system
arithmetic logic unit
control unit
3 points
Question 8
1. Which of the following is NOT an output device?
monitor
printer
CPU
secondary storage
3 points
Question 9
1. ____ represent information with a sequence of 0s and 1s.
Analog signals
Application programs
Digital signals
System programs
3 points
Question 10
1. A sequence of eight bits is called a ____.
binary digit
byte
character
double
3 points
Question 11
1. The digit 0 or 1 is called a binary digit, or ____.
bit
bytecode
Unicode
hexcode
3 points
Question 12
1. The term GB refers to ____.
giant byte
gigabyte
group byte
great byte
3 points
Question 13
1. ____ consists of 65,536 characters.
ASCII-8
ASCII
Unicode
EBCDIC
3 points
Question 14
1. A program called a(n) ____ translates instructions written in high-level languages into machine code.
assembler
decoder
compiler
linker
3 points
Question 15
1. A program called a(n) ____ combines the object program with the programs from libraries.
assembler
decoder
linker
compiler
3 points
Question 16
1. Consider the following C++ program.
#include <iostream>
using namespace std;
int main()
{
cout << “Hello World ”
return 0;
}
In the cout statement, the missing semicolon in the code above will be caught by the ____.
compiler
editor
assembler
control unit
3 points
Question 17
1. A program that loads an executable program into main memory is called a(n) ____.
compiler
loader
linker
assembler
3 points
Question 18
1. A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____.
algorithm
linker
analysis
design
3 points
Question 19
1. To develop a program to solve a problem, you start by ____.
analyzing the problem
implementing the solution in C++
designing the algorithm
entering the solution into a computer system
3 points
Question 20
1. In C++, the mechanism that allows you to combine data and operations on the data into a single unit is called a(n) ____.
object
class
function
algorithm
3 points
Question 21
1. Which of the following is a legal identifier?
program!
program_1
1program
program 1
3 points
Question 22
1. All of the following are examples of integral data types EXCEPT ____.
int
char
double
short
3 points
Question 23
1. Which of the following is a valid char value?
-129
-128
128
129
3 points
Question 24
1. The value of the expression 17 % 7 is ____.
1
2
3
4
3 points
Question 25
1. The expression static_cast<int>(9.9) evaluates to ____.
9
10
9.9
9.0
3 points
Question 26
1. The length of the string “computer science” is ____.
14
15
16
18
3 points
Question 27
1. Suppose that count is an int variable and count = 1. After the statement count++; executes, the value of count is ____.
1
2
3
4
3 points
Question 28
1. Suppose that alpha and beta are int variables. The statement alpha = –beta; is equivalent to the statement(s) ____.
alpha = 1 – beta;
alpha = beta – 1;
beta = beta – 1;
alpha = beta;
alpha = beta;
beta = beta – 1;
3 points
Question 29
1. Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____.
alpha = 1 + beta;
alpha = alpha + beta;
alpha = beta;
beta = beta + 1;
beta = beta + 1;
alpha = beta;
3 points
Question 30
1. Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____.
beta = beta + 1;
alpha = beta;
alpha = beta;
beta = beta + 1;
alpha = alpha + beta;
alpha = beta + 1;
3 points
Question 31
1. Choose the output of the following C++ statement:
cout << “Sunny ” << ‘\n’ << “Day ” << endl;
Sunny \nDay
Sunny \nDay endl
Sunny
Day
Sunny \n
Day
3 points
Question 32
1. Which of the following is the new line character?
\r
\n
\l
\b
3 points
Question 33
1. Consider the following code.
// Insertion Point 1
using namespace std;
const float PI = 3.14;
int main()
{
//Insertion Point 2
float r = 2.0;
float area;
area = PI * r * r;
cout << “Area = ” << area <<endl;
return 0;
}
// Insertion Point 3
In this code, where does the include statement belong?
Insertion Point 1
Insertion Point 2
Insertion Point 3
Anywhere in the program
3 points
Question 34
1. ____ are executable statements that inform the user what to do.
Variables
Prompt lines
Named constants
Expressions
3 points
Question 35
1. The declaration int a, b, c; is equivalent to which of the following?
inta , b, c;
int a,b,c;
int abc;
int a b c;
3 points
Question 36
1. Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____.
sum = 0
sum = 5
sum = 10
sum = 15
3 points
Question 37
1. Suppose that alpha is an int variable and ch is a char variable and the input is:
17 A
What are the values after the following statements execute?
cin >> alpha;
cin >> ch;
alpha = 17, ch = ‘ ‘
alpha = 1, ch = 7
alpha = 17, ch = ‘A’
alpha = 17, ch = ‘a’
3 points
Question 38
1. Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is:
15 76.3 14
Choose the values after the following statement executes:
cin >> x >> y >> z;
x = 15, y = 76, z = 14
x = 15, y = 76, z = 0
x = 15, y = 76.3, z = 14
x = 15.0, y = 76.3, z = 14.0
3 points
Question 39
1. Suppose that x and y are int variables, ch is a char variable, and the input is:
4 2 A 12
Choose the values of x, y, and ch after the following statement executes:
cin >> x >> ch >> y;
x = 4, ch = 2, y = 12
x = 4, ch = A, y = 12
x = 4, ch = ‘ ‘, y = 2
This statement results in input failure
3 points
Question 40
1. Suppose that ch1, ch2, and ch3 are variables of the type char and the input is:
A B
C
Choose the value of ch3 after the following statement executes:
cin >> ch1 >> ch2 >> ch3;
‘A’
‘B’
‘C’
‘\n’
3 points
Question 41
1. Suppose that ch1 and ch2 are char variables, alpha is an int variable, and the input is:
A 18
What are the values after the following statement executes?
cin.get(ch1);
cin.get(ch2);
cin >> alpha;
ch1 = ‘A’, ch2 = ‘ ‘, alpha = 18
ch1 = ‘A’, ch2 = ‘1’, alpha = 8
ch1 = ‘A’, ch2 = ‘ ‘, alpha = 1
ch1 = ‘A’, ch2 = ‘\n’, alpha = 1
3 points
Question 42
1. Suppose that ch1, ch2, and ch3 are variables of the type char and the input is:
A B
C
What is the value of ch3 after the following statements execute?
cin.get(ch1);
cin.get(ch2);
cin.get(ch3);
‘A’
‘B’
‘C’
‘\n’
3 points
Question 43
1. When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.
clear
skip
delete
ignore
3 points
Question 44
1. Suppose that alpha, beta, and gamma are int variables and the input is:
100 110 120
200 210 220
300 310 320
What is the value of gamma after the following statements execute?
cin >> alpha;
cin.ignore(100, ‘\n’);
cin >> beta;
cin.ignore(100,’\n’);
cin >> gamma;
100
200
300
320
3 points
Question 45
1. Suppose that ch1 and ch2 are char variables and the input is:
WXYZ
What is the value of ch2 after the following statements execute?
cin.get(ch1);
cin.putback(ch1);
cin >> ch2;
W
X
Y
Z
3 points
Question 46
1. Suppose that ch1 and ch2 are char variables and the input is:
WXYZ
What is the value of ch2 after the following statements execute?
cin >> ch1;
ch2 = cin.peek();
cin >> ch2;
W
X
Y
Z
3 points
Question 47
1. In C++, the dot is an operator called the ____ operator.
dot access
member access
data access
member
3 points
Question 48
1. Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements?
cout << fixed << showpoint;
cout << setprecision(2);
cout << x << ‘ ‘ << y << ‘ ‘ << z << endl;
25.67 356.87 7623.96
25.67 356.87 7623.97
25.67 356.88 7623.97
25.67 356.876 7623.967
3 points
Question 49
1. Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements?
cout << fixed << showpoint;
cout << setprecision(3) << x << ‘ ‘;
cout << setprecision(4) << y << ‘ ‘ << setprecision(2) << z << endl;
1565.683 85.8000 123.98
1565.680 85.8000 123.98
1565.683 85.7800 123.98
1565.683 85.780 123.980
3 points
Question 50
1. What is the output of the following statements?
cout << setfill(‘*’);
cout << “12345678901234567890” << endl
cout << setw(5) << “18” << setw(7) << “Happy”
<< setw(8) << “Sleepy” << endl;
12345678901234567890
***18 Happy Sleepy
12345678901234567890
***18**Happy**Sleepy
12345678901234567890
***18**Happy Sleepy
12345678901234567890
***18**Happy Sleepy**
3 points
Question 51
1. What is the output of the above statements?
cout << “123456789012345678901234567890” << endl
cout << setfill(‘#’) << setw(10) << “Mickey”
<< setfill(‘ ‘) << setw(10) << “Donald”
<< setfill(‘*’) << setw(10) << “Goofy” << endl;
123456789012345678901234567890
####Mickey Donald*****Goofy
123456789012345678901234567890
####Mickey####Donald*****Goofy
123456789012345678901234567890
####Mickey####Donald#####Goofy
23456789012345678901234567890
****Mickey####Donald#####Goofy
3 points
Question 52
1. Consider the following program segment.
ifstream inFile; //Line 1
int x, y; //Line 2
… //Line 3
inFile >> x >> y; //Line 4
Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4?
inFile.open(“progdata.dat”);
inFile(open,”progdata.dat”);
open.inFile(“progdata.dat”);
open(inFile,”progdata.dat”);
3 points
Question 53
1. In a ____ control structure, the computer executes particular statements depending on some condition(s).
looping
repetition
selection
sequence
3 points
Question 54
1. What does <= mean?
less than
greater than
less than or equal to
greater than or equal to
3 points
Question 55
1. Which of the following is a relational operator?
=
==
!
&&
3 points
Question 56
1. Which of the following is the “not equal to” relational operator?
!
|
!=
&
3 points
Question 57
1. Suppose x is 5 and y is 7. Choose the value of the following expression:
(x != 7) && (x <= y)
false
true
0
null
3 points
Question 58
1. The expression in an if statement is sometimes called a(n) ____.
selection statement
action statement
decision maker
action maker
3 points
Question 59
1. What is the output of the following C++ code?
int x = 35;
int y = 45;
int z;
if (x > y)
z = x + y;
else
z = y – x;
cout << x << ” ” << y << ” ” << z << endl;
35 45 80
35 45 10
35 45 –10
35 45 0
3 points
Question 60
1. When one control statement is located within another, it is said to be ____.
blocked
compound
nested
closed
3 points
Question 61
1. What is the output of the following code?
if (6 > 8)
{
cout << ” ** ” << endl ;
cout << “****” << endl;
}
else if (9 == 4)
cout << “***” << endl;
else
cout << “*” << endl;
*
**
***
****
3 points
Question 62
1. The conditional operator ?: takes ____ arguments.
two
three
four
five
3 points
Question 63
1. What is the value of x after the following statements execute?
int x;
x = (5 <= 3 && ‘A’ < ‘F’) ? 3 : 4
2
3
4
5
3 points
Question 64
1. Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.
2
3
4
6
3 points
Question 65
1. What is the output of the following code?
char lastInitial = ‘S’;
switch (lastInitial)
{
case ‘A’:
cout << “section 1” <<endl;
break;
case ‘B’:
cout << “section 2” <<endl;
break;
case ‘C’:
cout << “section 3” <<endl;
break;
case ‘D’:
cout << “section 4” <<endl;
break;
default:
cout << “section 5” <<endl;
}
section 2
section 3
section 4
section 5
3 points
Question 66
1. What is the output of the following code?
char lastInitial = ‘A’;
switch (lastInitial)
{
case ‘A’:
cout << “section 1” <<endl;
break;
case ‘B’:
cout << “section 2” <<endl;
break;
case ‘C’:
cout << “section 3” <<endl;
break;
case ‘D’:
cout << “section 4” <<endl;
break;
default:
cout << “section 5” <<endl;
}
section 1
section 2
section 3
section 5
3 points
Question 67
1. What is the output of the following code fragment if the input value is 4?
int num;
int alpha = 10;
cin >> num;
switch (num)
{
case 3:
alpha++;
break;
case 4:
case 6:
alpha = alpha + 3;
case 8:
alpha = alpha + 4;
break;
default:
alpha = alpha + 5;
}
cout << alpha << endl;
13
14
17
22
3 points
Question 68
1. What is the output of the following C++ code?
int x = 55;
int y = 5;
switch (x % 7)
{
case 0:
case 1:
y++;
case 2:
case 3:
y = y + 2;
case 4:
break;
case 5:
case 6:
y = y – 3;
}
cout << y << endl;
2
5
8
10
3 points
Question 69
1. A(n) ____-controlled while loop uses a bool variable to control the loop.
counter
sentinel
flag
EOF
3 points
Question 70
1. Consider the following code. (Assume that all variables are properly declared.)
cin >> ch;
while (cin)
{
cout << ch;
cin >> ch;
}
This code is an example of a(n) ____ loop.
sentinel-controlled
flag-controlled
EOF-controlled
counter-controlled
3 points
Question 71
1. What is the next Fibonacci number in the following sequence?
1, 1, 2, 3, 5, 8, 13, 21, …
34
43
56
273
3 points
Question 72
1. Which of the following is the initial statement in the following for loop? (Assume that all variables are properly declared.)
int i;
for (i = 1; i < 20; i++)
cout << “Hello World”;
cout << “!” << endl;
i = 1;
i < 20;
i++;
cout << “Hello World”;
3 points
Question 73
1. What is the output of the following C++ code?
int j;
for (j = 10; j <= 10; j++)
cout << j << ” “;
cout << j << endl;
10
10 10
10 11
11 11
3 points
Question 74
1. Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code?
cin >> sum;
cin >> num;
for (j = 1; j <= 3; j++)
{
cin >> num;
sum = sum + num;
}
cout << sum << endl;
24
25
41
42
3 points
Question 75
1. Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code?
sum = 0;
cin >> num;
for (int j = 1; j <= 4; j++)
{
sum = sum + num;
cin >> num;
}
cout << sum << endl;
124
125
126
127
3 points
Question 76
1. Which executes first in a do…while loop?
statement
loop condition
initial statement
update statement
3 points
Question 77
1. What is the value of x after the following statements execute?
int x = 5;
int y = 30;
do
x = x * 2;
while (x < y);
5
10
20
40
3 points
Question 78
1. What is the output of the following loop?
count = 5;
cout << ‘St’;
do
{
cout << ‘o’;
count–;
}
while (count <= 5);
St
Sto
Stop
This is an infinite loop.
3 points
Question 79
1. Which of the following loops does not have an entry condition?
EOF-controlled while loop
sentinel-controlled while loop
do…while loop
for loop
3 points
Question 80
1. Which of the following is a repetition structure in C++?
if
switch
while…do
do…while
3 points
Question 81
1. Which of the following is true about a do…while loop?
The body of the loop is executed at least once.
The logical expression controlling the loop is evaluated before the loop is entered.
The body of the loop may not execute at all.
It cannot contain a break statement.
3 points
Question 82
1. Which of the following is not a function of the break statement?
To exit early from a loop
To skip the remainder of a switch structure
To eliminate the use of certain bool variables in a loop
To ignore certain values for variables and continue with the next iteration of a loop
3 points
Question 83
1. Which executes immediately after a continue statement in a while and do-while loop?
loop-continue test
update statement
loop condition
the body of the loop
3 points
Question 84
1. When a continue statement is executed in a ____, the update statement always executes.
while loop
for loop
switch structure
do…while loop
3 points
Question 85
1. The heading of the function is also called the ____.
title
function signature
function head
function header
3 points
Question 86
1. Given the following function prototype: int test(float, char); which of the following statements is valid?
cout << test(12, &);
cout << test(“12.0”, ‘&’);
int u = test(5.0, ‘*’);
cout << test(’12’, ‘&’);
3 points
Question 87
1. A variable or expression listed in a call to a function is called the ____.
formal parameter
actual parameter
data type
type of the function
3 points
Question 88
1. A variable listed in a function call is known as a(n) ____ parameter. A variable list in a header is known as a(n) ____ parameter.
actual; actual
formal; formal
actual; formal
formal; actual
3 points
Question 89
1. What value is returned by the following return statement?
int x = 5;
return x + 1;
0
5
6
7
3 points
Question 90
1. Given the following function
int strange(int x, int y)
{
if (x > y)
return x + y;
else
return x – y;
}
what is the output of the following statement:?
cout << strange(4, 5) << endl;
-1
1
9
20
3 points
Question 91
1. Given the following function
int next(int x)
{
return (x + 1);
}
what is the output of the following statement?
cout << next(next(5)) << endl;
5
6
7
8
3 points
Question 92
1. Given the function prototype:
float test(int, int, int);
which of the following statements is legal?
cout << test(7, test(14, 23));
cout << test(test(7, 14), 23);
cout << test(14, 23);
cout << test(7, 14, 23);
3 points
Question 93
1. Given the following function prototype: double tryMe(double, double);, which of the following statements is valid? Assume that all variables are properly declared.
cin >> tryMe(x);
cout << tryMe(2.0, 3.0);
cout << tryMe(tryMe(double, double), double);
cout << tryMe(tryMe(float, float), float);
3 points
Question 94
1. Given the function prototype: double testAlpha(int u, char v, double t); which of the following statements is legal?
cout << testAlpha(5, ‘A’, 2);
cout << testAlpha( int 5, char ‘A’, int 2);
cout << testAlpha(‘5.0’, ‘A’, ‘2.0’);
cout << testAlpha(5.0, “65”, 2.0);
3 points
Question 95
1. Which of the following function prototypes is valid?
int funcTest(int x, int y, float z){}
funcTest(int x, int y, float){};
int funcTest(int, int y, float z)
int funcTest(int, int, float);
3 points
Question 96
1. Which of the following function prototypes is valid?
int funcExp(int x, float v);
funcExp(int x, float v){};
funcExp(void);
int funcExp(x);
3 points
Question 97
1. Given the following function prototype: int myFunc(int, int); which of the following statements is valid? Assume that all variables are properly declared.
cin >> myFunc(y);
cout << myFunc(myFunc(7, 8), 15);
cin >> myFunc(‘2’, ‘3’);
cout << myFunc(myFunc(7), 15);
3 points
Question 98
1. The statement: return 8, 10; returns the value ____.
8
10
18
80
3 points
Question 99
1. The statement: return 37, y, 2 * 3; returns the value ____.
2
3
y
6
3 points
Question 100
1. The statement: return 2 * 3 + 1, 1 + 5; returns the value ____.
2
3
6
7