Final Exam Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following print out a tab space? a. cout << "\t"; b. cout >> "\t"; c. cout << "/t"; d. cout >> "/t";

a. cout << "\t";

Which of the following is the correct way to declare an int variable named num_of_items and initialize it to 10? a. Int num_of_items = 10; b. int num_of_items[10]; c. int num_of_items(10); d. none of the above

c. int num_of_items(10);

Which of the following could be a legal function name? a. 4less b. return c. omg! d. you2

d. you2

Which of the following is correct? a. double a[]; b. double a[10]; c. double []a; d. double [10]a;

double a[10];

What is value of product after the execution of the following code? Assume int product = 1; and int n = 3; before the loop? for (int i = 2; i <= n; i++); product *= i; a. product = 1*2*3 = 6; b. product = 1*2*3*4 = 24; c. product = 1*3 = 3; d. product = 1*4 = 4; e. There is a syntax error

e. there is a syntax error

Which of the following is true about the array? a. Array index starts from 0 b. The last index of array element is (array size-1) c. All the elements in the array have the same data type d. none of the above e. two of the above f. all of the above

f. all of the above

Which of the following is an input device of a computer? a. CPU b. Monitor c. Mouse d. Printer e. Memory

Mouse

True or false: Suppose that I have an int vector variable v, then v[1] = 5; initialize the second element in v to be 5

True

What is the value of sum after the execution of the following loop? int sum = 0; int n = 5; while (n > 0) { sum += n; n = n-1; } a. 15 b. 14 c. infinite d. there is a syntax error

a. 15

Suppose that the function quotient is defined as follows: int quotient(int x, int y) { return x/y; } What will be the return value for the function call quotient(10, 3)? a. 3 b. 3.0 c. 3.3333 d. there is a syntax error in function definition

a. 3

Suppose that you search for 3 in an int array {10, 7, 8, 3, 3, 3, 4, 12} by using linear search algorithm. Which of the following is true about the return value? a. 3 b. 4 c. 5 d. 6 e. Cannot use linear search since the array is NOT sorted

a. 3?

What will be the output of the following code? Assume that originally int type variable x = 6. if(x%3 == 0) cout << x << "is a multiple of 3" << endl; else cout << x << "is not a multiple of 3 " << endl; a. 6 is a multiple of 3 b. 6 is not a multiple of 3 c. x is a multiple of 3 d. x is not a multiple of 3 e. there is a syntax error

a. 6 is a multiple of 3

What is wrong if we try to declare and initialize a c string as follows char str[] = {'a', 'b', 'c'}; a. it does not cause the '\0' to be inserted in the end of the array b. it has syntax error because the string size is missed c. it has syntax error because the right side should be "abc" d. none of the above

a. It does not cause '\0' to be inserted at the end of the array

To convert a Celsius temperature to a Fahrenheit temperature, we use formula F=9/5C + 32 Suppose I implement the function double ctof(double c); which convert a Celsius temperature to a Fahrenheit temperature, as following double ctof(double c) { return 9.0*c/5.0 - 32.0; } What of the following is correct? a. The function implementation is correct b. There is a syntax error in the function implementation c. There is a logic error in the function implementation d. None of the above

a. The function implementation is correct

What is the value of x after the execution of the following code? int x = rand()%10 + 1; a. a random integer between 1 and 10 inclusive b. a random integer between 0 and 9 inclusive c. a random integer between 0 and 10 inclusive d. a random integer between 1 and 9 inclusive e. none of the above

a. a random integer between 1 and 10 inclusive

Which of the following are true? assume char str1[80] = "Good Morning"; has been declared and initialized for each question. All other variables are declared a. after execute strcpy(str1, "Hello"); str1 has context "Hello" b. after execute strcat(str1, "Hello"); str1 has context "HelloGood Morning' c. after execute int x = strcmp(str1, "good morning"); x has value 0 d. after execute int x = strlen(str1); x has value 80

a. after execute strcpy(str1, "Hello"); str1 has context "Hello"

Which of the following statements assign make cstring s have content "Hello"? a. char s[20] = "Hello"; b. char s[20]; s = "Hello"; c. char s[20]; strcpy(s, 'Hello'); d. none of the above

a. char s[20] = "Hello";

How many numbers will the following code print out? Assume int x = 6; before the loop. do { cout << x << endl; x--; } while (x > 6); a. one b. six c. zero d. infinite e. There is a syntax error

a. one

What is the value of product after the execution of the following code? Assume int product = 1; and int n = 3; before the loop? for (int i = 2; i <= n; i++) product *= i; a. product = 1*2*3 = 6; b. product = 1*2*3*4 = 24; c. product = 1*3 = 3; d. product = 1*4 = 4; e. there is a syntax error

a. product = 1 * 2 * 3 = 6;

Which of the following is the correct C/C++ expression for math expression sqrt(2x + y) a. sqrt(2*x+y) b. sqrt(2x+y) c. square(2*x+y) d. square(2x+y)

a. sqrt(2*x+y)

Suppose we have string s = "Hi"; which of the following is true? a. s.length() returns 2 b. s.length() returns 3 c. s.length() has syntax error d. none of the above

a?

Suppose we have string s = "Hello World"; which of the following is true? a. s.substr(5) returns "World" b. s.substr(6) returns "World" c. s.substr(1, 3) returns "ell" d. s.substr(1, 3) returns "el" e. none of the above

b & c

Which of the following are true about convention function atoi? a. in order to use atoi, must include cstdlib b. atoi("1234") returns integer 1234 c. atoi("#1234") has a syntax error d. atoi("#1234") has a running time error

b atoi("1234") returns integer 1234

Which of the following is correct? a. #include < iostream> b. #include <iostream> c. #include <iostream > d. All of a, b, and c

b. #include <iostream>

In order to use vector class, which of the following include is needed? a. #include <cvector> b. #include <vector> c. #include <string> d. none of the above

b. #include <vector>

What is the value of floor (-2.4)? a. -2.0 b. -3.0 c. -2.5 d. 2.0

b. -3.0

C++ source code is saved in a file with extension... a. .obj b. .cpp c. .txt d. .exe

b. .cpp

In order to use the built-in C++ function sqrt, which of the following library needs to be included? a. <iostream> b. <cmath> c. <cstdlib> d. <fstream>

b. <cmath>

If I declare and initialize an array as follows: int scores[] = {3, 5, 1, 4, 2}; Which of the following is true? a. scores[4] has value 4 b. the code: cin >> scores[3]; will allow the user to enter a value from keyboard to replace the old value 4 in the array c. the last index of scores is 5 d. None of the above

b. ?

Which of the following is true? a. A void function can never have a return statement. b. A function with return type int must have a return statement. c. A function can never have more than one return statement d. None of the above

b. A function with return type int must have a return statement

Suppose I have three lines of code: string s; cin >> s; cout << s; and I typed "Hello World on keyboard. What is the output? a. Hello World b. Hello c. World d. none of the above

b. Hello

Suppose that function fun is declared as void fun(int a, int b = 10); when function call fun(5) is made, what happens? a. fun(5) is NOT a legal function call, you must provide two actual parameters b. fun(5) is equivalent to fun(5, 10) c. fun(5) is equivalent to fun(10, 5) d. fun(5) is equivalent to fun(5,5)

b. fun(5) is equivalent to fun(5, 10)

What is the error in the following statement? Assume that x, and y are declared and initialized. if(x>y) cout << x << "is smaller than " << y << endl; a. syntax error b. logic error c. running time error d. no error

b. logic error

Suppose we have string s = "Hello World"; which of the following is true? a. s.at(1) returns 'H' b. s.at(1) returns 'e' c. s.at[1] returns 'H' d. s.at[1] returns 'e'

b. s.at(1) returns 'e'

Suppose we have string s1 = "Hello"; and string s2("hello"); which of the following is true? a. s1 == s2 is true b. s1 < s2 is true c. s2 > s2 is true d. none of the above

b. s1 < s2 is true

Suppose that you have the following declaration and initialization char str[15] = "abcdef"; which of the following is true? a. str[6] has value 'f' b. str[6] has value '\0' c. str[6] has value 'e' d. none of the above

b. str[6] has value '\0'

Evaluate the following Boolean expression: true || false && true a. true || false && true = true || (false && true) = true || false = true b. true || false && true = (true || false) && true = true && true = true c. false d. it cannot be determined. you need add parenthesis

b. true || false && true = (true || false) && true = true && true = true

Which of the following returns the number of elements initialized in a vector v? a. v.length() b. v.size() c. v.capacity() d. none of the above

b. v.size()

Which of the following declaration is true? a. vector v; b. vector<int> v; c. vector(int) v; d. none of the above

b. vector<int> v;

Suppose that I have a function void my_swap(int x, int y) { int temp = x; x = y; y = temp; } What will be the values of x and y after the execution of the following code? int x = 10, y = 100; my_swap(x, y); a. x = 0 and y = 0 b. x = 100 and y = 10 c. x = 10 and y = 100 d. There is a syntax error in function call

b. x = 100 and y = 10

In order to use string class, which of the following include is needed? a. #include <cstring> b. #include <vector> c. #include <string> d. none of the above

c. #include <string>

Suppose that I declare: char s[] = "hi"; What is s[2]? a. 'i' b. '/0' c. '\0' d. none of the above

c. '\0'

Which of the following line of code increase an int variable a by 1? a. a++ b. a+1; c. ++a; d. a = a + 1;

c. ++a;??

What is the value of int x; after the execution of the following code? char s[] = "Hello World"; x = strlen(s); a. 10 b. 11 c. 12 d. 13

c. 12

If I declare and initialize an array as follows: int a[10] = {4, 5, 6, 7}; What will be the value of a[3]? a. 0 b. 6 c. 7 d. Cannot be determined

c. 7

Which of the following is a good way to debug a program? a. Begin to debug after all function implementations are finished b. Randomly change code so that we may get the program works by luck c. Each function should be tested in a program in which it is the only untested function d. None of the above

c. Each function should be tested in a program in which it is the only untested function

What is the output of the following statement? Suppose char grad = 'A'; switch(c) { case A: case a: cout << "Excellent Job!"; case B: case b: cout << "Good Job!:\"; } a. Excellent Job! b. Good Job! c. Excellent Job!Good Job! d. There are syntax errors

c. Excellent Job!Good Job!

Suppose int x = 15; what is the output of the following statement? if (x > 10) cout << "Hello"; if (x > 6) cout << "World"; else cout << "Hi"; a. Hello b. World c. HelloWorld d. hi e. There is a syntax error

c. HelloWorld

Which of the following declares a constant variable named TAX_RATE with type double and initialize it to 0.085? a. constant double x = 0.085. b. const double x = 0.085. c. const double x = 0.085; d. constant double x = 0.085;

c. const double x = 0.085

Which of the following is a legal C/C++ identifier? a. how? b. 2how c. how2 d. #how

c. how2

Which of the following is a correct function declaration? a. int for(int n); b. int for(n); c. int fore(int n); d. int fore(n);

c. int fore(int n);

Which of the following is a declaration of a call-by-value function? a. int fun(int$ a); b. int fun(int@ a); c. int fun(int a); d. int fun(int& a);

c. int fun(int a);

Which of the following code swap the value of a and b? Assume a and b are both of int type and are both initialized. a. a = b; b = a; b. int temp = a; temp = b; b = a; c. int temp = a; a = b; b = temp; d. all of the above

c. int temp = a; a = b; b = temp;

What is the correct way to call function: int my_linear_search(int a[], int size, int key); to search value x in array arr with size SIZE; assume that all variables are declared and initialized. a. int my_linear_search(int arr[], int SIZE, int x); b. my_linear_search(arr[], SIZE, x); c. my_linear_search(arr, SIZE, x); d. my_linear_search(arr, x, SIZE);

c. my_linear_search(arr, SIZE, x);

If I want to write a stub for function double average_score(int scores[ ], int count); which return the average score for count many students, assume the students' scores are stored in the array scores. Which of the following is the correct statement in the stub? a. no statement needed, the stub function has an empty body b. return 0; c. return 0.0; d. return average;

c. return 0.0;

Suppose we have string s1 = "Hello"; and char s2[80]; which of the following assign "Hello" to s2? a. s2 = s2; b. strcpy(s2, s1); c. strcpy(s2, s1.c_str()); d. none of the above

c. strcpy(s2, s1.c_str());

Which of the following declare a string and initialized as "Hello"? a. string s; b. string s('hello'); c. string s("hello"); d. none of the above;

c. string s("hello")

What is wrong in the following code? int factorial(int n) { return n * factorial(n - 1); } a. There is nothing wrong b. the code has a syntax error c. The code will compile, however, the recursive call will never stop d. None of the above

c. the code will compile, however, the recursive call will never stop

Which of the following insert integer 5 into an integer vector v? a. v.insert(5); b. v.add(5); c. v.push_back(5); d. none of the above

c. v.push_back(5);

How many numbers will the following code print out? Assume int x = 6; before the loop. While(x > 6) { cout << x << endl; x--; } a. one b. six c. zero d. infinite e. there is a syntax error

c. zero

Suppose that I have a function int sum(int n) { if (n == 1) return 1; else return n + sum(n - 1); } What is the result of function call sum(3)? a. 1 b. 2 c. 3 d. 6 e. none of the above

d. 6

Which of the following is true about C/C++ local variable. a. A local variable declared in a block cannot be seen outside that block. b. A local variable must be initialized before it can be used. c. Two local variables in different functions can have the same name. d. All of the above is true.

d. All of the above is true

Suppose int x = 5; what is the output of the following statement? if (x > 10) cout << "Hello"; else if(x > 6) cout << "World"; else cout << "Hi"; a. Hello b. World c. HelloWorld d. Hi. e. There is a syntax error

d. Hi

Which of the following pairs are overloaded functions? a. int fun(int a, int b); and void fun(int a, double b); b. int fun(int a, int b); and int fun(double a, int b); c. int fun(int a, int b); and double fun(double a, double b); d. all of the above e. two of the above f. none of the above

d. all of the above

Which of the following is a correct way to print out "Hello World!" on the screen and the cursor goes to the new line after the printing finished. a. cout >> "Hello, World!\n"; b. cout << "Hello, World!/n"; c. cout >> "Hello, World!" << endl; d. cout << "Hello, World!" << endl;

d. cout << "Hello, World!" << endl;

Suppose that I have declared a function void have_fun(int x); What is the correct way to call this function? Assume int a; has been initialized. a. void have_fun(int a); b. have_fun(int a); c. void have_fun(a); d. have_fun(a);

d. have_fun(a);


Set pelajaran terkait

Multiplying Polynomials and Simplifying Expressions (Pre Test)

View Set

AP Govt practice questions test 2

View Set

CompTIA Network+ Certification Exam N10-007 Practice Test 5

View Set

Business Income Taxes - Chapter 9 - Business Income, Deduction, and Accounting Methods

View Set

Micro Econ 500 - Chapter 9 and 10

View Set

Chapter 13: Palliative and End-of-Life Care

View Set

Final Exam finance 4500 Chap 18-22

View Set