Shared Flashcard Set

Details

Quiz Questions Week 1
Week 1 Quiz Questions
25
Computer Science
Undergraduate 2
03/16/2012

Additional Computer Science Flashcards

 


 

Cards

Term
What is the output of the following code snippet? #include #include using namespace std; int main() { double x; x = pow(3.0, 2.0) + pow(4.0, 2.0); cout << x << endl; return 0; } Answer A. 25.0 B. 7.0 C. Compilation error D. 34
Definition
25.0
Term
Which one of the following is an assignment statement?
Answer

A. int a = 20;

B. a = 20;

C. assign 20 to a;

D. assign a = 20;
Definition
a = 20;
Term
What output is produced by these statements?

string name = "Joan Hunt";
cout << name.length();
Answer

A. 8

B. 4

C. 9

D. 11
Definition
9
Term
Which of the following statements is correct about constants?
Answer

A. The data stored inside a const variable can be changed using an assignment statement.

B. You can make a variable constant by using the constant reserved word while declaring the variable.

C. Constants are written using uppercase letters because the compiler ignores the constants declared in lowercase letters.

D. Variables defined using const make a code snippet more readable and easier to maintain.
Definition
Variables defined using const make a code snippet more readable and easier to maintain.
Term
Which of the following statements is correct about constants?
Answer

A. The data stored inside a const variable can be changed using an assignment statement.

B. You can make a variable constant by using the constant reserved word while declaring the variable.

C. Constants are written using uppercase letters because the compiler ignores the constants declared in lowercase letters.

D. Variables defined using const make a code snippet more readable and easier to maintain.
Definition
Unpredictable result
Term
What is the result of the following code snippet? #include using namespace std; int main() { double circle_radius; double circle_volume = 22 / 7 * circle_radius * circle_radius; cout << circle_volume << endl; return 0; } Answer A. 0 B. Unpredictable result C. 3.14 D. 6.28 Which of the following statements are valid about strings? I. An empty string literal is represented as "". II. A string stored in a string variable can be changed. III. String variables are initialized automatically. IV. A string variable can contain digits and special characters. Answer A. All four statements are valid. B. Only II and III are valid. C. Only I and III are valid. D. Only III and IV are valid.
Definition
All four statements are valid.
Term
What is the result of the following code snippet? #include using namespace std; int main() { double bottles; double bottle_volume = bottles * 2; cout << bottle_volume << endl; return 0; } Answer A. 1 B. Unpredictable result C. 0 D. 2
Definition
Unpredictable result
Term
Consider the following C++ statement:

string name = "Harry";

Which of the following is true?
Answer

A. name is a string literal.

B. name is a string variable.

C. The statement contains a syntax error.

D. "Harry" is a string variable.
Definition
name is a string variable.
Term
Assuming that the user inputs a value of 25000 for the pay and 10 for the bonus rate in the following code snippet, what is the output? #include using namespace std; int main() { cout << "Enter the pay: "; double pay; cin >> pay; cout << "Enter the bonus rate: "; double bonus; cin >> bonus; cout << "The new pay is " << pay + pay * (bonus / 100.0) << endl; return 0; } Answer A. The new pay is 30000 B. The new pay is 27500 C. The new pay is 25000 D. The new pay is 25100
Definition
The new pay is 27500
Term
Which one of the following statements can be used to extract the last 10 characters from the string variable str?
Answer

A. str.substr(str.length()-10, 10)

B. str.substr(10, 10)

C. str.substr(0, 10)

D. str.substr(str.length()-9, 10)
Definition
str.substr(str.length()-10, 10)
Term
What is the value inside the value variable at the end of the given code snippet? #include using namespace std; int main() { int value = 3; value = value – 2 * value; value++; return 0; } Answer A. –2 B. 4 C. 0 D. 2
Definition
-2
Term
What will be the output of the following code snippet?

int a = 10;
int b = 20;
int c = 2;

int x = b / a /*c*/;
cout << x << endl;
Answer

A. 2

B. No output, due to compilation error

C. 1

D. 4
Definition
2
Term
Which one of the following is a correct representation of the given mathematical expression in C++?

a + b
-----
2
Answer

A. a + b % 2

B. (a + b) / 2

C. a + b / 2

D. a + (b / 2)
Definition
(a + b) / 2
Term
In C++, which special character is used to invoke a member function?
Answer

A. A comma

B. A colon

C. A semicolon

D. A dot
Definition
A dot
Term
Which of the following options defines an integer variable?
Answer

A. age: int;

B. Integer age;

C. int age;

D. integer age;
Definition
int age;
Term
What is the output of the following code snippet? #include #include using namespace std; int main() { cout << fixed << setprecision(3) << 20 << endl; return 0; } Answer A. 20 B. 20.000 C. 20.00 D. 20.0
Definition
20.000
Term
Consider the following C++ variable names:

I. 1st_instance
II. basic_in_$
III. _emp_name_
IV. address_line1
V. DISCOUNT

Which of the following options is correct?
Answer

A. Only IV is a valid C++ variable name.

B. Only I, IV, and V are valid C++ variable names.

C. Only III, IV, and V are valid C++ variable names.

D. Only I and IV are valid C++ variable names.
Definition
Only III, IV, and V are valid C++ variable names.
Term
What will be the value inside the variables x and y after the given set of assignments?

int x = 20;
int y = 10;

x = (x - y) * 2;
y = x--;
Answer

A. x = 20, y = 20

B. x = 19, y = 19

C. x = 20, y = 19

D. x = 19, y = 20
Definition
x = 19, y = 20
Term
Which statement about variable names is true?
Answer

A. Variable names can be no longer than 8 characters long

B. Variables cannot be assigned and declared in the same statement

C. Variable names must contain at least one dollar sign

D. It is incorrect to initialize a string variable with a number
Definition
It is incorrect to initialize a string variable with a number
Term
The typical ranges for integers may seem strange but are derived from
Answer

A. Field requirements for typical usage and limits

B. Powers of two because of base 2 representation within the computer

C. Overflows

D. Base 10 floating point precision
Definition
Powers of two because of base 2 representation within the computer
Term
Assuming that the user enters 23 and 45 as inputs for num1 and num2, respectively, what is the output of the following code snippet? #include #include using namespace std; int main() { cout << "Enter a number: "; string num1; cin >> num1; cout << "Enter another number: "; string num2; cin >> num2; string final = num1 + num2; cout << final << endl; return 0; } Answer A. 68 B. 2345 C. No output due to a run-time error D. 23
Definition
2345
Term
Consider the following division statements:

I. 22 / 7
II. 22.0 / 7
III. 22 / 7.0
IV. 22.0 / 7.0

Which of the following options is correct?
Answer

A. Only II and III will return an integer value.

B. All the four statements will return an integer value.

C. Only I, II, and III will return an integer value.

D. Only I will return an integer value.
Definition
Only I will return an integer value.
Term
What is result of evaluating the following expression?
(45 / 6) % 5
Answer

A. 2.5

B. 2

C. 7

D. 3
Definition
2
Term
What is the meaning of num = 10; in C++?
Answer

A. It checks whether num equals 10.

B. It gives a syntax error since num cannot be assigned a value using = operator.

C. It declares a variable named num and initializes it with 10.

D. It sets the variable num to ten.
Definition
It sets the variable num to ten.
Term
Consider the following code snippet:

cout << "Please enter a number: ";
int x;
cin >> x;
cout << "Please enter another number: ";
int y;
cin >> y;
cout << "The sum is " << x + y << endl;

Suppose the student provides the answer 17 29 [Enter] as input to the first prompt. What will the program do?
Answer

A. Produce an error because the input for the first prompt is not a single integer

B. Print "The sum is 46"

C. Print "The sum is 17"

D. Produce an error because no value was provided after the second prompt
Definition
Print "The sum is 46"
Supporting users have an ad free experience!