CISP 31

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The following program displays #include <iostream> using namespace std; int main() { cout << "A"; cout << "B"; return 0; } Select one: a. B A b. BA c. AB d. A B

AB

Which of the following statements are true? Select one: a. Encapsulating data fields makes the program easy to maintain. b. Encapsulating data fields helps prevent programming errors. c. All of the above d. Use the private keyword to encapsulate data fields. e. If you don't use the public keyword, the visibility is private by default. f. Encapsulating data fields makes the program short

All of the above

A block is enclosed inside Select one: a. Quotes b. Parentheses c. Braces d. Brackets

Braces

__________ is the brain of a computer. Select one: a. Hardware b. CPU c. Memory d. Disk

CPU

Suppose char city[7] = "Dallas"; what is the output of the following statement? cout << city; Select one: a. Dallas b. D c. nothing printed d. Dallas0

Dallas

Does the return statement in the following function cause syntax errors? void f() { int max = 0; if (max != 0) cout << max; else return; } Select one: a. No b. Yes

No

Will the following program terminate? int balance = 10; while (true) { if (balance < 9) continue; balance = balance - 9; } Select one: a. Yes b. No

No

A character is stored in Select one: a. four bytes b. three bytes c. two bytes d. one byte

One byte

Which of the following expression will yield 0.5? Select one: a. 1.0 / 2 b. (double) (1 / 2) c. 1 / 2 d. (int) 1 / 2 e. (float)(1 / 2)

1.0 / 2

How many times the following code prints "Welcome to C++"? int count = 0; do { cout << "Welcome to C++"; count++; } while (count < 10); Select one: a. 11 b. 9 c. 8 d. 0 e. 10

10

How many times the following code prints "Welcome to C++"? int count = 0; do { cout << "Welcome to C++"; } while (++count < 10); Select one: a. 0 b. 10 c. 11 d. 9 e. 8

10

How many times the following code prints "Welcome to C++"? int count = 0; while (count < 10) { cout << "Welcome to C++"; count++; } Select one: a. 11 b. 0 c. 10 d. 9 e. 8

10

How many times the following code prints "Welcome to C++"? int count = 0; while (count++ < 10) { cout << "Welcome to C++"; } Select one: a. 0 b. 11 c. 9 d. 10 e. 8

10

Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++ > 10). Select one: a. 11 b. 9 c. 10

10

What is the value in count after the following loop is executed? int count = 0; do { cout << "Welcome to C++"; } while (count++ < 9); cout << count; Select one: a. 8 b. 11 c. 0 d. 9 e. 10

10

What is the output of the following code: #include <iostream> using namespace std; int main() { int x[] = {120, 200, 16}; for (int i = 0; i < 3; i++) cout << x[i] << " "; } Select one: a. 120 200 16 b. 16 120 200 c. 200 120 16 d. 16 200 120

120 200 16

Suppose void nPrint(char ch, int n) { while (n > 0) { cout << ch; n--; } } What is k after invoking nPrint('a', k)? int k = 2; nPrint('a', k); Select one: a. 0 b. 2 c. 3 d. 1

2

What is the output of the following code? #include <iostream> using namespace std; int main() { int matrix[4][4] = {{1, 2, 3, 4}, {4, 5, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}}; int sum = 0; for (int i = 0; i < 4; i++) cout << matrix[i][1] << " "; return 0; } Select one: a. 1 3 8 12 b. 4 5 6 7 c. 3 6 10 14 d. 1 2 3 4 e. 2 5 9 13

2 5 9 13

If you declare an array double list[] = {3.4, 2.0, 3.5, 5.5}, list[1] is ________. Select one: a. 2.0 b. 3.4 c. undefined d. 5.5 e. 3.4

2.0

What is Math.floor(3.6)? Select one: a. 3 b. 5.0 c. 4 d. 2

3

How many elements are in array double list[5]? Select one: a. 6 b. 0 c. 5 d. 4

5

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); Select one: a. 6 b. 8 c. 7 d. 5

6

Note that the ASCII for character A is 65. The expression 'A' + 1 evaluates to Select one: a. B b. Illegal expression c. A1 d. 66

66

The ASCII of 'a' is 97. What is the ASCII for 'c'? Select one: a. 98 b. 99 c. 97 d. 96

99

The "less than or equal to" comparison operator is __________. Select one: a. << b. != c. < d. <= e. =<

<= <=

Analyze the following code: #include <iostream> using namespace std; int xfunction(int n, long t) { cout << "int"; return n; } long xfunction(long n) { cout << "long"; return n; } int main() { cout << xfunction(5); } Select one: a. The program does not compile because the compiler cannot distinguish which xfunction to invoke. b. The program displays int followed by 5. c. The program runs fine but displays nothing. d. The program displays long followed by 5.

The program displays long followed by 5.

Analyze the following code. #include <iostream> using namespace std; class B { public: B() { }; int k; }; int main() { B b; cout << b.k << endl; return 0; } Select one: a. The program displays unpredictable number. b. The program displays 1. c. The program has a runtime error because b.k does not have a value. d. The program has a compile error because b.k cannot be accessed. e. The program displays 0.

The program displays unpredictable number.

Analyze the following code: #include <iostream> using namespace std; class A { public: int s; A(int newS) { s = newS; } void print() { cout << s; } }; int main() { A a; a.print(); } Select one: a. The program has a compilation error because class A is not a public class. b. The program compiles and runs fine and prints nothing. c. The program has a compilation error because class A does not have a default constructor. d. The program would compile and run if you change A a to a.

The program has a compilation error because class A does not have a default constructor.

Suppose two header files t1.h and t2.h contain the declarations for class T. What happens if you include both header files in your program? Select one: a. The program will not compile at all. b. The program will compile fine and the first header file that is included is used. c. You will get multiple declaration error if the header files don't have the include guard. d. The compile will automatically decides which implementation to use.

You will get multiple declaration error if the header files don't have the include guard.

What is the printout of the following switch statement? char ch = 'a'; switch (ch) { case 'a': case 'A': cout << ch << endl; break; case 'b': case 'B': cout << ch << endl; break; case 'c': case 'C': cout << ch << endl; break; case 'd': case 'D': cout << ch << endl; } Select one: a. ab b. aa c. a d. abcd

a

Suppose void nPrint(char ch, int n) { while (n > 0) { cout << ch; n--; } } What is the printout of the call nPrint('a', 4)? Select one: a. invalid call b. aaaaa c. aaaa d. aaa

aaaa

What is the output of the following code? string s("abc"); s.append("welcome", 3); cout << s << endl; Select one: a. abcwelcome b. abcwel c. welcomeabc d. abc

abcwel

What is the output of the following code? string s("abc"); s.append("welcome"); cout << s << endl; Select one: a. welcome b. abc c. abcwelcome d. welcomeabc

abcwelcome

A function that is associated with an individual object is called __________. Select one: a. an instance function b. a class function c. a static function d. an object function

an instance function

What is the output of the following code? string s("abcdefg"); s.insert(1, 3, 'w'); cout << s << endl; Select one: a. abcdefg b. awwwbcdefg c. aweldefg d. awelbcdefg

awwwbcdefg

What is the output of the following code? string s("abcdefg"); cout << s.substr(1, 3); Select one: a. bcd b. abc c. a d. c

bcd

Why do computers use zeros and ones? Select one: a. because binary numbers are simplest. b. because digital devices have two stable states and it is natural to use one state for 0 and the other for 1. c. because combinations of zeros and ones can represent any numbers and characters. d. because binary numbers are the bases upon which all other number systems are built.

because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.

Which of the following statements are correct? Select one: a. char charArray[2][2] = {{'a', 'b'}, {'c', 'd'}}; b. char charArray[2][] = {{'a', 'b'}, {'c', 'd'}}; c. char charArray[][] = {'a', 'b'}; d. char charArray[][] = {{'a', 'b'}, {'c', 'd'}};

char charArray[2][2] = {{'a', 'b'}, {'c', 'd'}};

To improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159 Select one: a. constants b. variables c. classes d. functions

constants

Which of the following statement prints smith\exam1\test.txt? Select one: a. cout << "smith\"exam1\"test.txt"; b. cout << "smith"\exam1"\test.txt"; c. cout << "smith\\exam1\\test.txt"; d. cout << "smith\exam1\test.txt";

cout << "smith\\exam1\\test.txt";

The signature of the main function in C++ is __________. Select one: a. Main(String[] args) b. main(String[] args) c. int main() d. Main(String args[]) e. void main(String[] args)

int main()

Which of the following justifies the output to the left? Select one: a. fixed b. left c. right d. showpoint e. setw(width

left

The following code displays ______________. #include <iostream> using namespace std; void maxValue(int value1, int value2, int max) { if (value1 > value2) max = value1; else max = value2; } int main() { int max = 0; maxValue(1, 2, max); cout << "max is " << max << endl; return 0; } Select one: a. max is 1 b. max is 2 c. max is d. max is 0

max is 0

Are the following two declarations the same char city[8] = "Dallas"; char city[] = "Dallas"; Select one: a. yes b. no

no

Are the following two declarations the same char city[] = {'D', 'a', 'l', 'l', 'a', 's'}; char city[] = "Dallas"; Select one: a. no b. yes

no

Given the following two arrays: char s1[] = {'a', 'b', 'c'}; char s2[] = "abc"; Which of the following statements is correct? Select one: a. s2 has three characters b. s2 has four characters c. s1 has two characters d. s1 has four characters

s2 has four characters

Variables that are shared by every instances of a class are __________. Select one: a. static variables b. instance variables c. private variables d. public variables

static variables

When you pass an array to a function, the function receives __________. Select one: a. the length of the array b. the reference of the array c. a copy of the first element d. a copy of the array

the reference of the array

To return an uppercase letter from char variable ch, use Select one: a. toupper(ch) b. isalpha(ch) c. isdigit(ch) d. tolower(ch) e. islower(ch)

toupper(ch)

There are no default value for data fields in a class. Select one: a. false b. true

true

What is the output of the following code? string s("abc"); s.assign("welcome", 3); cout << s << endl; Select one: a. abcwelcome b. welcome c. wel d. abc e. abcwww

wel

To assign a value 1 to variable x, you write Select one: a. x == 1; b. x = 1; c. 1 := x; d. x := 1; e. 1 = x;

x = 1;

To add a value 1 to variable x, you write Select one: a. x = x + 1; b. x := 1; c. x = 1++ x; d. 1 + x = x; e. x ++= 1;

x = x + 1;

What is the output of the following code? #include <iostream> using namespace std; void f(double &p) { p += 2; } int main() { double x = 1; double y = 1; f(x); f(y); cout << "x is " << x; cout << " y is " << y << endl; return 0; } Select one: a. x is 1 y is 1 b. x is 2 y is 2 c. x is 3 y is 3 d. x is 1 y is 2 e. x is 2 y is 1

x is 3 y is 3

Given the declaration Circle x, which of the following statement is most accurate. Select one: a. x is a reference to a Circle object. b. You can assign an int value to x. c. x contains an int value. d. x is an object of the Circle type.

x is an object of the Circle type.

The extension name of a C++ source code file is Select one: a. .cpp b. .exe c. .java d. .class e. .obj

.cpp

Suppose x is 1. What is x after x -= 1? Select one: a. -2 b. 1 c. 2 d. 0 e. -1

0

What is the output of the following code? inline void print(int i) { cout << i << endl; } int main() { print(1); return 0; } Select one: a. 1 b. 0 c. nothing d. 2

1

What is the output of the following code? void f() { cout << 1 << endl; } int main() { f(); return 0; } Select one: a. nothing b. 1 c. 0 d. 0 1 e. 1 0

1

Suppose circle1 and circle2 are two Circle objects. What does the following statement do? circle2 = circle1; Select one: a. It copies the contents of circle2 to circle1. b. This statement is illegal. c. It makes circle2 and circle1 the same object. d. It copies the contents of circle1 to circle2.

It copies the contents of circle1 to circle2.

Does the function call in the following function cause syntax errors? #include <iostream> #include <math> using namespace std; int main() { pow(2.0, 4); } Select one: a. No b. Yes

No

Analyze the following code: #include <iostream> using namespace std; void reverse(int list[], const int size, int newList[]) { for (int i = 0; i < size; i++) newList[i] = list[size - 1 - i]; } int main() { int list[] = {1, 2, 3, 4, 5}; int newList[5]; reverse(list, 5, newList); for (int i = 0; i < 5; i++) cout << newList[i] << " "; } Select one: a. The program displays 5 4 3 2 1 and then raises an ArrayIndexOutOfBoundsException. b. The program displays 5 4 3 2 1. c. The program displays 1 2 3 4 6. d. The program displays 1 2 3 4 5 and then raises an ArrayIndexOutOfBoundsException.

The program displays 5 4 3 2 1.

What is the output of the following code? bool even = false; cout << (even ? "true" : "false") << endl; Select one: a. nothing b. true false c. true d. false

false

The signature of a function consists of ____________. Select one: a. function name and parameter list b. return type, function name, and parameter list c. function name d. parameter list

function name and parameter list

Programming style is important, because Select one: a. a program may not compile if it has a bad style b. good programming style can make a program run faster c. good programming style makes a program more readable d. good programming style eliminates programming errors

good programming style makes a program more readable

What will be the output of the following code? #include <iostream> using namespace std; int j = 1; int main() { int i = 2; cout << "i is " << i << " j is " << j << endl; } Select one: a. i is 1 j is 2 b. i is 1 j is 1 c. i is 2 j is 1 d. i is 2 j is 2

i is 2 j is 1

Suppose the input for number is 9. What is the output from running the following program? #include <iostream> using namespace std; int main() { cout << "Enter an integer: "; int number; cin >> number; int i; bool isPrime = true; for (i = 2; i < number && isPrime; i++) { if (number % i == 0) { isPrime = false; } } cout << "i is " << i << endl; if (isPrime) cout << number << " is prime" << endl; else cout << number << " is not prime" << endl; return 0; } Select one: a. i is 3 followed by 9 is not prime b. i is 3 followed by 9 is prime c. i is 4 followed by 9 is prime d. i is 4 followed by 9 is not prime

i is 4 followed by 9 is not prime

Which of the following code displays the area of a circle if the radius is positive. Select one: a. if (radius != 0) cout << radius * radius * 3.14159; b. if (radius >= 0) cout << radius * radius * 3.14159; c. if (radius > 0) cout << radius * radius * 3.14159; d. if (radius <= 0) cout << radius * radius * 3.14159;

if (radius > 0) cout << radius * radius * 3.14159;

Which of the following function declaration is correct? Select one: a. int f(int a[][], int rowSize, int columnSize); b. int f(int a[3][], int rowSize); c. int f(int a[][3], int rowSize); d. int f(int[][] a, int rowSize, int columnSize);

int f(int a[][3], int rowSize)

Which of the following statements is valid? Select one: a. int[] i = {3, 4, 3, 2}; b. int i = {3, 4, 3, 2}; c. int i[4] = {3, 4, 3, 2}; d. double [30]; e. int i(30);

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


संबंधित स्टडी सेट्स

VATI Maternal Newborn Health Promotion and Maintenance Quiz

View Set

AP Gov Unit 2 Progress Check: MCQ Part A

View Set

Sadlier-Oxford Vocabulary Level G Units 4-6 synonyms

View Set

FP515 Retirement Savings and Income Planning

View Set

TEST #1- Ch. 12,13,14 (Business Communication/ UCA Carson Fall 2019)

View Set

APUSH Unit 5 College Board Review Questions

View Set

RPRACTICES16: Taxes, Tax Year, Prop 13, Capitol Gains, Determining a Profit or Loss, Depreciation

View Set