Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am needing someone to help answer all the questions in the attached documents. 1.Which of the following is an input device a computer? a.CPUb.

I am needing someone to help answer all the questions in the attached documents.

1.Which of the following is an input device a computer?

a.CPUb. Monitorc. Mouse4. Printer5. Memory

2.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! " ;

b.cout << "Hello, World!/n" ;

c.cout >> "Hello, World!" << endl ;

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

3.Which of the following is correct?

a.#include < iostream>c. #include

b.#include d. All of a, b, and c

4.Which of the following print out a tab space?

a.cout << "\t";c. cout << "/t";

b.cout >> "\t";d. cout >> "/t";

5.C++ source code is saved in a file with extension

a..objb. .cppc. .txtd. .exe

6.Which of the following is a legal C/C++ identifier?

a.how?b. 2howc. how2d. #how

7.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;c. int num_of_items(10);

b.int num_of_items[10];d. none of the above

8.

Which of the following is the correct C/C++ expression for math expression

a.sqrt(2*x+y)b. sqrt(2x+y)c. square(2*x+y)d. square(2x+y)

9.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 errorb. logic errorc. running time errord. no error

10.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;

elsecout << x << " is not a multiple of 3 " << endl;

a.6 is a multiple of 3b. 6 is not a multiple of 3

c. x is a multiple of 3d. x is not a multiple of 3e. There is a syntax error

11.How many numbers will the following code print out? Assume int x = 6; before the loop. do{

cout << x << endl; xii;

}while (x > 6);

a.oneb. sixc. zerod. infinitee. There is a syntax error

12.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.c. constdouble x = 0.085;

b.const double x = 0.085.d. constant double x = 0.085;

13.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 i 1;

}

a.15b. 14c. infinited. There is a syntax error.

14.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.

15.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.Hellob. Worldc. HelloWorldd. Hie. There is a syntax error

16.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

17.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.Hellob. Worldc. HelloWorldd. Hie. There is a syntax error

18.What is the output of the following statement? Suppose char grade = '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

19.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.

20.How many numbers will the following code print out? Assume int x = 6; before the loop. While(x > 6){

cout << x << endl; xii;

}

a.oneb. sixc. zerod. infinitee. There is a syntax error

21.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

22.What is the output of the following code? int x = 10;

if(++x > 10) cout << ++x; else cout << iix;

a.9b. 10c. 11d. 12e. There is a syntax error

23.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

24.What is the value of floor(i2.4)?

a.i2.0b. i3.0c. i2.5d. 2.0

25.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);c. void have_fun(a);

b.have_fun(int a);d. have_fun(a);

26.Which of the following is a correct function declaration?

a.int for(int n);c. int fore(int n);

b.int for(n);d. int fore(n);

27.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);

d.all of the above

e.two of the above

and

double fun(double a, double b);

f.none of the above

28.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.3b. 3.0c. 3.33333d. There is syntax error in function definition

29.Which of the following is a declaration of a callibyivalue function?

a.int fun(int$ a);b. int f..t@a);c. int fun(int a);d. int fun(int& a);

30.To convert a Celsius temperature to a Fahrenheit temperature, we use formula

! = 9 ! + 32

5

Suppose I implement the function double ctof(double c); which convert a Celsius temperature to Fahrenheit temperature, as following

double ctof(double c){ return 9.0*c/5.0 i32.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 logic error in the function implementation

d.None of the above

31.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 statements

d.None of the above

32.Suppose that function fun is declared as void fun(int a, int b = 10); when function call fun(5) is made, what happen?

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)

33.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 lucky

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

d.None of the above

34.In order to use the builtiin C++ function sqrt, which of the following library needs to be included?

a.b. c. d.

35.Which of the following could be a legal function name?

a.4lessb. returnc. omg!d. you2

36.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;

37.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

38.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

39.Suppose I have a function void zero_all(int& a, int b){

a = 0;

b = 0;

}

What will be the values of x and y after the execution of the following code? int x = 10, y = 100;

zero_all(x, y);

a.x = 0 and y = 0b. x = 0 and y = 10c. x = 0 and y = 100

d. There is a syntax error in function call

40.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 = 0b. x = 100 and y = 10c. x = 10 and y = 100

d. There is a syntax error in function call

41.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)0b) 6c) 7d) cannot be determined.

42.Suppose that you sort the int array {4, 5, 7, 1, 2, 6, 8, 3} by using select sort algorithm. After the third iteration of outer loop, what is the array?

a){1, 2, 3, 4, 5, 6, 7, 8}

b){1, 2, 3, 4, 5, 6, 8, 7}

c){1, 2, 3, 5, 4, 6, 7, 8}

d) none of the above

43.Which of the following is correct?

a.double a[];b. double a[10];c. double [] a;d. double [10]a;

44.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) 3b) 4c) 5d) 6e) cannot use linear search since the array is NOT sorted

45.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

46.What is the value of int x; after the execution of the following code? char s[] = "Hello World";

x = strlen(s);

a. 10b. 11c. 12d. 13

47.Suppose that I have a function int sum(int n){

if(n == 1) return 1; return n + sum(ni1);

}

What is the result of function call sum(3)?

a.1b. 2c. 3d. 6e. None of the above

48.Suppose that I declare: char s[] = "hi";

What is s[2]?

a.'i'b. '/0'c. '\0'd. none of the above

49.If I declare and initialize an array as follows: int scores[ ] = {3, 5, 1, 4, 2}; Which of the follow are 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

50.What is wrong in following code? int factorial(int n){

return n*factorial(ni1);

}

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.

51.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);

52.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

53.What is wrong if we try to declare and initialize an 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 a syntax error because the right side should be "abc"

d.none of the above

54.Which of the following statement assign make cstring s has 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

55.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

56.Which of the following is true about getline function?

a.getline is a member of all input streams

b.getline has two arguments

c.cin.getline(str, 20); will read up to 19 characters from keyboard and assign them to str

d.when cin.getline(str, 5); is executed, and user entered "Hello" and hit the Enter Key, the str will be "Hello".

57.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

58.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

59.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

60.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'

61.Suppose we have string s1 = "Hello"; and string s2("hello"); which of the following is true?

a.s1 == s2 is true

b.s1

c.s2 > s2 is true

d.None of the above

62.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

63.Suppose we have string s1 = "Hello"; and char s2[80]; which of the following assign "Hello" to s2?

a.s2 = s1;

b.strcpy(s2, s1);

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

d.None of the above

64.Suppose I have three line 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

65.Which of the following declaration is true?

a.vector v;

b.vector v;

c.vector(int) v;

d.none of the above

66.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

a.Trueb. false

67.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 abve

68.Which of the following returns the number of element initialized in a vector v?

a.v.length()

b.v.size()

c.v.capacity()

d.none of the above

69.In order to use string class, which of the following include is needed?

a.#include

b.#include

c.#include

d.None of the above

70.In order to use vector class, which of the following include is needed?

a.#include

b.#include

c.#include

d.None of the above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions