final cis 201

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

What is the output from the following code snippet? int main() { ostringstream oss; for (int i = 0; i < 6; i = i + 2) { oss << "base-" << setw(3) << i; cout << oss.str() << endl; } } Select one: a. base- 0 base- 0base- 2 base- 0base- 2base- 4 b. base- 0 base- 2 base- 4 c. base-000 base-000base-002 base-000base-002base-004 d. base-100 base-102 base-104

a. base- 0 base- 0base- 2 base- 0base- 2base- 4

What is the value of variable dollars after these 2 statements? double price = 2.9; int dollars = price; Select one: a. 2 b. 3 c. 2.9 d. None of the above

a. 2

Assuming that the "Data.txt" file contains the following lines of text, what is the output on executing the given code snippet? Peter 78 Albert 89 Susan 97 int main() { string str = "Hello World"; string line; int count = 0; ifstream infile; infile.open("Data.txt"); while(getline(infile, line)) { count++; str = line; } cout << count << " " << str << " " << line << endl; return 0; } Select one: a. 3 Susan 97 Susan 97 b. 3 Susan 97 c. 3 Hello World d. 3 Susan 97 Hello World

a. 3 Susan 97 Susan 97

Consider an array of size 3 by 4. What is the offset to reach the array[2][1] element? Select one: a. 9 b. 8 c. 10 d. 7

a. 9

Which of the following is true about function return statements? Select one: a. A function can hold multiple return statements, but only one return statement executes in one function call. b. A function can hold only one return statement. c. A function can hold multiple return statements, and multiple return statements can execute in one function call. d. A function can have maximum of two return statements.

a. A function can hold multiple return statements, but only one return statement executes in one function call.

What is a "dangling pointer"? Select one: a. A pointer which is used after the statement to delete it. b. A pointer which has not been initialized. c. A pointer which points to the end of an array instead of the beginning. d. A pointer whose value varies at runtime.

a. A pointer which is used after the statement to delete it.

Which of the following statements about variables is true? Select one: a. The same variable name can be used in two different functions. b. The same variable name can be used for two different variables in a single function. c. You should use global variables whenever possible. d. A variable is visible from the point at which it is defined until the end of the program.

a. The same variable name can be used in two different functions.

Why do programs sometimes include the srand() function before the rand() function ? Select one: a. Without srand(), the program makes the same sequence of numbers every time it is run. b. Without srand(), the results of rand() are unpredictable. c. srand() doubles the range of values than rand() can produce. d. srand() turns the values of rand() into integers.

a. Without srand(), the program makes the same sequence of numbers every time it is run.

Given the following declaration of the variables p1 and p2, which code fragment prints "Hello" if the value of x in the variable p1 is larger than the value of x in the variable p2? struct Point2D { double x; double y; }; Point2D p1; Point2D p2; Select one: a. if (p1.y > p2.y) { cout << "Hello"; } b. if (p1.x > p2.x) { cout << "Hello"; } c.if (x.p1 > x.p2) { cout << "Hello";} d. if (Point2D.x > Point2D.x) { cout << "Hello"; }

b. if (p1.x > p2.x) { cout << "Hello"; }

Which of the following functions produces the same result as the factorial() function below? int factorial(int num) { if (num <= 1) { return 1; } return num * factorial(num - 1); } Select one: a. int f(int n) { int res=1; for (int i = 1; i < n; i++) res *= i; return res; } b. int f(int n) { int res=1; for (int i = 1; i <= n; i++) res *= i; return res; } c. int f(int n) { int res=1; for (int i = 2; i < n; i++) res *= i; return res; } d. None of these are correct.

b. int f(int n) { int res=1; for (int i = 1; i <= n; i++) res *= i; return res; }

Consider the code snippet below. int ch; ch = 100; int* ptr = &ch; Which of the following statements represents a legal way of obtaining the value that ptr points to? Select one: a. ptr b. *ptr c. &ptr d. *(&ptr)

b. *ptr

What is the value in the variable called ratio after these statements? int apples = 5, oranges = 8; double ratio = apples / oranges; Select one: a. 0.375 b. 0 c. 1.6 d. None of the above

b. 0

Consider the following code snippet: vector<int> vectarr(5); for (int i = 0; i < vectarr.size(); i++) { vectarr[i] = i + 3; } What value is stored in the 0th element of the vector? Select one: a. 0 b. 3 c. 6 d. 9

b. 3

Assuming that a user enters 45, 78, and 12 one after another, separated by spaces, what is the output of the following code snippet? int main() { int num1; int num2; int num3 = 0; cout << "Enter a number: "; cin >> num1; cout << "Enter a number: "; cin >> num2; cout << "Enter a number: "; cin >> num3; if (!(num1 > num2 && num1 > num3)) { cout << num1 << endl; } else if (!(num2 > num1 && num2 > num3)) { cout << num2 << endl; } else if (!(num3 > num1 && num3 > num2)) { cout << num3 << endl; } return 0; } Select one: a. 12 b. 45 c. 78 d. There is no output due to compilation errors.

b. 45

Consider the following code snippet: int arr[4][5] = { { 1, 2, 3 }, { 4, 5, 6 }}; int val = arr[1][2] + arr[1][3]; cout << val; What is the output of the given code snippet on execution? Select one: a. 5 b. 6 c. 7 d. 9

b. 6

Which statements about numeric types in C++ are true? I. There is more than one integer type II. The data type float uses twice the storage of double III. Numeric ranges are typical but not guaranteed to be the same between compilers Select one: a. I, II b. I, III c. II, III d. I, II, III

b. I, III

Consider the following code snippet: int number[5]; // Line 1 number[5] = 5 // Line 2 Which one of the following statements is correct for the given code snippet? Select one: a. Line 2 declares and initializes an array of five elements with value 5. b. Line 2 causes a bounds error because 5 is an invalid index number. c. Line 2 initializes the fifth element of the array with value 5. d. Line 2 initializes all the elements of the array with value 5.

b. Line 2 causes a bounds error because 5 is an invalid index number.

In the following code snippet, assuming the proper headers have been included, which line can cause a compilation error? 1. ofstream outfile; 2. outfile.open("My.txt"); 3. outfile >> "This text is to be inserted!" >> endl >> "This is also to be inserted!!!" >> endl; 4. outfile.close(); Select one: a. Line 4 b. Line 3 c. Line 2 d. Line 1

b. Line 3

An if statement inside another if statement is called a Select one: a. Switch statement b. Nested if statement c. Break statement d. Syntax error, since that is not permitted in C++

b. Nested if statement

What is the error in the following code snippet, which is used for calculating the average score for a student in three subjects? #include <iostream> int main() { int subject1 = 75; int subject2 = 65; int subject3 = 70; int average = subject1 + subject2 + subject3 / 3; cout << "The average is " << average; return 0; } Select one: a. The code snippet has a syntax error from an incorrect use of arithmetic operators. b. The code snippet has a logic error. c. The code snippet uses variable names that are not allowed in C++. d. There is no error; the code snippet is completely accurate.

b. The code snippet has a logic error.

Suppose you want to write an if statement with multiple alternatives to print out the single tax bracket that someone is in, based on their income. Assume the integer variable income holds the annual income. What is wrong with the following if statement? if (income < 10000) { cout << "Lowest tax bracket" << endl; } if (income < 20000) { cout << "Low-Middle tax bracket" << endl; } if (income < 30000) { cout << "Middle tax bracket" << endl; } cout << "High tax bracket" << endl; Select one: a. The if conditions are in the wrong order; the check for the highest bracket should be first b. The conditions should use a sequence of if else/if clauses, not just independent if statements c. The if conditions should be a switch statement instead d. Nothing is wrong - the if statement will correctly print out the tax brackets

b. The conditions should use a sequence of if else/if clauses, not just independent if statements

What is displayed when you execute the following code snippet? int ch = 100; cout <<&ch << endl; Select one: a. The value of ch b. The memory location of ch c. The value at the memory location of 100 d. None of the listed items

b. The memory location of ch

The following code snippet is written to calculate the miles per gallon of two cars and print out both values. #include <iostream> using namespace std; int main() { int miles1 = 420; int miles2 = 500; int gallons1 = 10; int gallons2 = 15; cout << miles1 / gallons1 << endl; cout << miles1 / gallons2 << endl; return 0; } Based on the given code snippet, identify the correct statement: Select one: a. The output is correct, and there are no errors. b. The mileage of the first car is calculated correctly, but the mileage of the second car is incorrect due to a logic error. c. The mileage of the second car is calculated correctly, but the mileage of the first car is incorrect due to a logic error. d. The mileage of both cars is incorrect due to a logic error.

b. The mileage of the first car is calculated correctly, but the mileage of the second car is incorrect due to a logic error.

What is the output of the following code snippet? int main() { bool passed = false; string some_str = "Unknown"; passed = !(passed); if (!passed) { some_str = "False"; } if (passed) { passed = false; } if (!passed) { some_str = "True"; } else { some_str = "Maybe"; } cout << some_str << endl; return 0; } Select one: a. False b. True c. Unknown d. Maybe

b. True

Which of the following declares a C++ string? Select one: a. char b. char* c. string d. string*

b. char*

Which of the following is the correct code snippet for throwing a pair of dice to get a sum of the numbers on two dice between 2 and 12 with different probabilities? Select one: a. rand() % 11 + 2 b. rand() % 12 + 2 c. (rand() % 6 + 1) + (rand() % 6 + 1) d. (rand() % 6) + (rand() % 6)

c. (rand() % 6 + 1) + (rand() % 6 + 1)

What is the value of the cost variable after the following code snippet is executed? int cost = 82; if (cost < 100) { cost = cost + 10; } if (cost > 50) { cost = cost * 2; } if (cost < 100) { cost = cost - 20; } Select one: a. 82 b. 92 c. 184 d. 164

c. 184

Consider the following code snippet: int numarray[ ] = { 1, 2, 3, 4, 5 }; cout << numarray[1]; cout << numarray[4]; What is the output of the code snippet? Select one: a. 15 b. 14 c. 25 d. 04

c. 25

What is the output of the following code snippet? #include <iostream> using namespace std; int main() { cout << 2 * 2 << 6; return 0; } Select one: a. 2 * 26 b. 226 c. 46 d. 4 6

c. 46

How many times does the code snippet given below display "Loop Execution"? int i = 0; while (i != 9) { cout << "Loop Execution" << endl; i++; } Select one: a. Infinite times b. 8 times c. 9 times d. 10 times

c. 9 times

What is a "memory leak" in computer programs? Select one: a. When programs terminate due to run-time errors and their memory is not reclaimed by the operating system b. Accessing null pointers c. Allocating "new" memory dynamically without a corresponding "delete" d. Using out-of-bounds array indices

c. Allocating "new" memory dynamically without a corresponding "delete"

What is the correct way to pass an fstream object as a parameter to a function? Select one: a. Cast as an ifstream object. b. Cast as an ofstream object. c. As a reference parameter. d. As a value parameter.

c. As a reference parameter.

Which one of the following translates high-level descriptions into machine code? Select one: a. Assembler b. Linker c. Compiler d. Editor

c. Compiler

The binary search of an array is called "binary" because: Select one: a. Elements are compared two at a time b. Elements are compared on a bit-by-bit basis c. Each step halves the size ofthe array to search d. None of these are correct

c. Each step halves the size ofthe array to search

Consider the following code snippet: #include <cctype> char ch; ifstream in_file; in_file.open("c:\\File.txt"); while (in_file.get(ch)) { if (isupper(ch)) cout << ch; } return 0; } What is the output of the program if File.txt contains the text "Four And 20"? Select one: a. Won't compile because of unknown function "isupper()". b. F c. FA d. Four And 20

c. FA

Examine the following code snippet. Which statement best describes num_array? int* num_array[100]; Select one: a. It is a pointer to an array of 100 integers. b. It is a pointer to an integer initialized with 100. c. It is an array of 100 integer pointers. d. There is a compilation error.

c. It is an array of 100 integer pointers.

Which option represents the output of the following code snippet? int assign_priority(int priority) { return priority + 2; } int main() { int priority = assign_priority(3); cout << "Priority: " << priority << endl; return 0; } Select one: a. Priority: 2 b. Priority: 3 c. Priority: 5 d. There is no output because the program does not compile.

c. Priority: 5

Consider a scenario in which you develop a C++ program on a computer that has a Pentium processor and compile the program into the corresponding machine language. What step should you take to run the same program on a computer that has a different processor? Select one: a. Copy the compiled machine language instructions to the computer that has a different processor. b. Develop the same program again on the computer that has a different processor and recompile the program. c. Recompile the C++ program on the computer that has a different processor. d. You cannot run the program on a computer with a different processor because C++, being a high-level programming language, is machine dependent

c. Recompile the C++ program on the computer that has a different processor.

Consider the following code snippet: vector<int> num1; vector<int> num2; ... // Code here adds elements to the vectors int cnt = 0; for (int i = 0; i < num1.size() && i < num2.size(); i++) { if (num1[i] == num2[i]) { cnt++; } } Which one of the following descriptions is correct for the given code snippet? Select one: a. The code snippet finds the highest value out of the two vectors. b. The code snippet finds the lowest value out of the two vectors. c. The code snippet compares the values of two vectors and stores the count of total matches found. d. The code snippet adds the values of the two vectors.

c. The code snippet compares the values of two vectors and stores the count of total matches found.

Consider the following code snippet: int marks[3] = { 90, 45, 67 }; for (int i = 0; i <= 3; i++) { cout << marks[i] << endl; } What is the result of executing this code snippet? Select one: a. The code snippet does not give any output. b. The code snippet displays all the marks stored in the array without any redundancy. c. The code snippet has a bounds error or displays redundant data. d. The code snippet executes an infinite loop.

c. The code snippet has a bounds error or displays redundant data

A programmer writes the sum_num_array function, as shown in the following code snippet. The programmer was surprised to find incorrect output from the main program. What is wrong with the following code snippet? int sum_num_array(int num_array[], int size) { int result = 0; for (int i = 0; i < size; i = i + 2) { result = result + num_array[i]; } return result; } int main() { int sum_num_array(int num_array[], int size); int num[6] = { 1, 2, 3, 4, 5, 6 }; int sum = sum_num_array(num, 8); cout << "Sum: " << sum << endl; return 0; } Select one: a. The sum_num_array function works only with an array with an even number of values. b. It is not possible to pass an array as an argument to a function. c. The main function passes an incorrect size for the num array. d. The main function does not initialize the num array correctly before passing it to the sum_num_array function.

c. The main function passes an incorrect size for the num array.

Consider the following code snippet: int val = arr[0][2]; Which value of arr is stored in the val variable? Select one: a. The value in the first row and the second column b. The value in the first row and the first column c. The value in the first row and the third column d. The value in the third row and the second column

c. The value in the first row and the third column

What will be the value inside the variables a and b after the given set of assignments? int a = 20; int b = 10; a = (a + b) / 2; b = a++; Select one: a. a = 15, b = 16 b. a = 16, b = 16 c. a = 16, b = 15 d. a = 15, b = 15

c. a = 16, b = 15

Which of the following loops executes the statements inside the loop before checking the condition? Select one: a. for b. while c. do-while d. None of the listed items

c. do-while

Consider a situation where multiple if else/if statements are combined into a chain to evaluate a complex condition. Which of the following reserved words is used to define the branch to be executed when none of the conditions are true? Select one: a. if b. else if c. else d. All of the above items

c. else

What are the values of i and j obtained after the following code fragment is run? int i = 40; int j = 30; int count = 0; while (count < 5) { i = i + i; i = i + 1; j = j - 1; j = j - j; count++; } cout << i<< endl << j; Select one: a. i = 45, j = 1 b. i = 45, j = 35 c. i = 1311, j = 0 d. i = 1311, j = 35

c. i = 1311, j = 0

Assuming that "out_file" is an ofstream object, what is the correct way of opening a file "Employees.txt" for writing? Select one: a. out_Employees.open(Employees.txt); b. out_file(Employees.txt); c. out_file.open("Employees.txt"); d. out_file("Employees.txt");

c. out_file.open("Employees.txt");

Consider the following line of code for calling a function named func1: func1(vectdata, vardata); Which one of the following function signatures is valid for func1, where vectdata is an integer vector and vardata is an integer variable? Select one: a. void func1(vectdata, vardata) b. void func1(vector vectdata, int vardata) c. void func1(vector<int> vectdata, int vardata) d. void func1(vector<int>, int)

c. void func1(vector<int> vectdata, int vardata)

What is the output of the following code snippet? int main() { int num = 100; if (num < 100) { if (num < 50) { num = num - 5; } else { num = num - 10; } } else { if (num > 150) { num = num + 5; } else { num = num + 10; } } cout << num << endl; return 0; } Select one: a. 95 b. 100 c. 105 d. 110

d. 110

Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, what is the output of the following code snippet? #include <iostream> #include <string> using namespace std; int main() { cout << "Enter a number: "; string n1; cin >> n1; cout << "Enter another number: "; string n2; cin >> n2; string result = n1 + n2; cout << result << endl; return 0; } Select one: a. 46 b. No output due to a run-time error c. 107 d. 4562

d. 4562

What will be the output of the following code snippet? int i; int j; for (i = 0; i < 7; i++) { for (j = 7; j > i; j--) { cout << "+"; } cout << endl; } Select one: a. A rectangle with seven rows and seven columns of the plus sign. The number of rows increments by one on completion of one iteration of the inner loop. b. A right triangle with seven rows and seven columns of the plus sign. The number of columns increments by one on completion of one iteration of the inner loop. c. A rectangle with seven rows and seven columns of the plus sign. The number of rows increments by one on completion of one iteration of the inner loop. d. An inverted right triangle with seven rows and seven columns of the plus sign. The number of columns decrements by one on completion of one iteration of the inner loop.

d. An inverted right triangle with seven rows and seven columns of the plus sign. The number of columns decrements by one on completion of one iteration of the inner loop.

What does the following code snippet do for a file of unknown size? int i = 0; ifstream in_file; string mystring; in_file.open("test.txt"); while (getline(in_file, mystring)) { i = i + mystring.length(); } cout << i << endl; Select one: a. Counts the number of digits in the file b. Counts the number of words in the file c. Counts the number of lines in the file d. Counts the number of characters (except whitespace) in the file

d. Counts the number of characters (except whitespace) in the file

File.txt contains two lines: This is line1 And this is line2 What is the output of the following code snippet? int main() { ifstream read_file; read_file.open("File.txt"); char line1[80]; string line2; getline(read_file, line1); getline(read_file, line2); cout << line1 << endl; cout << line2 << endl; return 0; } Select one: a.This is line1And this is line2 b.This c.And this is line2 d. Does not compile due to misuse of getline() function.

d. Does not compile due to misuse of getline() function.

Consider the given scenario for describing an algorithm using pseudocode. UML Supermarket has different ways of awarding discounts to its customers for each purchase they make. A 10% discount is given on the total value of the purchase. In addition, a standard loyalty discount is given if customers have a permanent customer card. Your program should indicate the amount payable by the customer after the discounts. Identify the inputs that the program requires from the given set of options. I. The discount percentage II. The total value of the purchase III. The loyalty-discount amount IV. The customer card number V. The amount payable after discount Select one: a. I, II, and III b. I and III c. II, IV, and V d. II and IV

d. II and IV

Assuming that the user inputs "twenty" as the input, what is the output of the following code snippet? int main() { int age = 0; cout << "Please enter your age: "; cin >> age; if (cin.fail()) { cout << "Invalid Data!" << endl; return 0; } if (age < 18) { cout << "You are not eligible to vote!"; return 0; } else { cout << "You are a valid voter!" << endl; if (age > 60) { cout << "You are a senior voter!" << endl; } else { cout << "You are not a senior voter!" << endl; } } return 0; } Select one: a. You are not eligible to vote! b. You are a valid voter! c. You are a valid voter!You are a senior voter! d. Invalid Data!

d. Invalid Data!

What is the type of the following function argument str? void shout(const string& str) { cout << str << "!!!" << endl; } Select one: a. It is a C++ string. b. It is a global variable reference to a string. c. It is the memory address of a string which the function must modify. d. It is the memory address of a string which the function cannot modify.

d. It is the memory address of a string which the function cannot modify.

Which of the functions given below require the dot notation to get invoked? I. len II. length III. substr IV. pow V. sqrt Select one: a. All the five functions are called with the dot notation b. Only I, II and III c. Only IV and V d. Only II and III

d. Only II and III

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? Select one: a. Only IV is a valid C++ variable name. b. Only I and IV are valid C++ variable names. c. Only I, IV, and V are valid C++ variable names. d. Only III, IV, and V are valid C++ variable names.

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

The typical ranges for integers may seem strange but are derived from Select one: a. Base 10 floating point precision b. Field requirements for typical usage and limits c. Overflows d. Powers of two because of base 2 representation within the computer

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

Computer programming is Select one: a. The speed with which a computer operates b. The collection of peripheral devices connected to a computer c. The storage of data in the form of words and pictures d. The act of designing and implementing a computer program

d. The act of designing and implementing a computer program

Which of the following statements is true about the given code snippet? fstream stm; int offset = 16; stm.open("File.bin", ios::in | ios::out | ios::binary); stm.seekp(offset); stm.seekg(offset + 8); stm.put('A'); stm.put('B'); char ch = stm.get(); Select one: a. The variable ch stores the character read from location 17 in File.bin. b. The variable ch stores the character read from location 16 in File.bin. c. The characters "A" and "B" are written into File.bin at locations 24 and 25. d. The characters "A" and "B" are written into File.bin at locations 16 and 17.

d. The characters "A" and "B" are written into File.bin at locations 16 and 17.

Consider a situation where you are planning on purchasing a new cell phone. You are considering two cell phones. These cell phones have different purchase prices. Each mobile service provider charges a different rate for each minute that the cell phone is used. To determine which cell phone is the better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cell phone. What are all the inputs needed for this algorithm? Select one: a. The cost of each cell phone and the rate for each minute for each cell phone b. The cost of each cell phone and the number of minutes provided with each cell phone c. The cost of each cell phone, the rate per minute for each cell phone, and the number of minutes provided with each cell phone d. The cost of each cell phone, the rate per minute for each cell phone, and the number of minutes you would use the cell phone

d. The cost of each cell phone, the rate per minute for each cell phone, and the number of minutes you would use the cell phone

What is the output of the following code snippet, assuming a correct program surrounds it? struct Point2D { double x; double y; }; Point2D p1(2,3); cout << p1.x << " " << p1.y; Select one: a. 2 3 b. x2 y2 c. No output, it won't compile d. Possible runtime error

a. 2 3

An integrated development environment (IDE) bundles tools for programming into a unified application. What kinds of tools are usually included? Select one: a. An editor and a compiler b. A web browser c. Presentation tools d. A multimedia creation package

a. An editor and a compiler

What are the names (in order) of the parts of this function definition? int my_fun (double a) Select one: a. Return type, function name, parameter variable type, parameter variable name b. Return type, function name, parameter variable name, parameter variable type c. Function name, function type, parameter variable type, parameter variable name d. Function name, function type, parameter variable name, parameter variable type

a. Return type, function name, parameter variable type, parameter variable name

What happens after cin.fail() becomes true? Select one: a. The variable that cin was to update is unchanged, and all further cin operations will fail. b. The variable that cin was to update is set to zero, but later cin operations will proceed if valid. c. The variable that cin was to update is unchanged, but later cin operations will proceed if valid. d. The variable that cin was to update becomes false.

a. The variable that cin was to update is unchanged, and all further cin operations will fail.

What is the purpose of the following algorithm? somenum = 0 Repeat the following steps 50 times input variable1 if variable1 > somenum then somenum = variable1 end of if end of repeat print somenum Select one: a. To find the highest among 50 numbers b. To print out the 50 numbers c. To find the smallest among 50 numbers d. To search for a particular number among 50 numbers

a. To find the highest among 50 numbers

Which common error is present in the code below, which is intended to calculate the average value from a sum of numbers? double total; int n; double input; while (cin >> input) { total = total + input; n++; } if (n != 0) { double average = total / n; } Select one: a. Uninitialized variables b. Infinite loop c. Type mismatch d. Division by zero

a. Uninitialized variables

A recursive function is one which: Select one: a. calls itself. b. uses a loop to iterate over data. c. calls the function which called it. d. All of these are correct.

a. calls itself.

What is the output of the following code snippet? #include <iostream> #include <string> using namespace std; int main() { string some_string1 = "his"; string some_string2 = "cycle"; if (some_string1 < some_string2) { cout << some_string2; } else { cout << some_string1; } return 0; } Select one: a. his b. hiscycle c. cycle d. There is no output due to compilation errors.

a. his

Suppose you want to print minutes so that they have a leading zero if they are less than 10, for example 03. Which manipulator do you use? Select one: a. setfill b. setprecision c. fixed d. left

a. setfill

What is true about the statement given below? int* choice; Select one: a. choice is an integer variable b. choice contains the memory location of an integer variable c. choice can store two memory addresses simultaneously d. choice can also store a string value

b. choice contains the memory location of an integer variable

Consider a function named avg, which accepts four numbers as integers and returns their average as a double. Which of the following is the correct statement to call the function avg? Select one: a. avg(2, 3.14, 3, 5); b. double average = avg(2, 3, 4, 5); c. avg(); d. double average = avg("2", "3", "4", "5");

b. double average = avg(2, 3, 4, 5);

Suppose you need to write a function that calculates the volume of rectangular boxes. Which of the following is the best choice for the declaration of this function? Select one: a. void volume(int a) b. double volume(double w, double h, double l) c. void volume(double w, double h, double l) d. double volume(double w)

b. double volume(double w, double h, double l)

Which one of the following reserved words is used in C++ to represent a value without a fractional part? Select one: a. integer b. int c. Int d. Integer

b. int

How do you extract first 5 characters from the string str? Select one: a. substr(str, 5) b. substr.str(0, 5) c. str.substr(5) d. str.substr(0, 5)

d. str.substr(0, 5)

Which of the following operators is used to combine two Boolean conditions? Select one: a. ## b. $$ c. %% d. & &

d. & &

Which of the following activities can be simulated using a computer? Select one: a. Picking stocks b. Tossing a coin c. Shuffling cards for a card game d. All of the listed items

d. All of the listed items

Which line of code in the snippet below is the recursive invocation of function my_fun? 1 int my_fun(int perfect) 2 { 3 return ((perfect -1) * (perfect -1)); 4 } 5 int main() 6 { 7 cout << my_fun(my_fun(12)); 8 return 0; 9 } Select one: a. 1 b. 3 c. 7 d. There is no recursive invocation.

d. There is no recursive invocation.

What is the output of the code snippet given below? string s = "abcde"; int i = 1; while (i < 5) { cout << s.substr (i, 1); i++; } Select one: a. No output b. abcd c. abcde d. bcde

d. bcde


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

TestOut Network Pro v6.0 | 3.1 Copper Cables and Connectors | 3.1.7 Practice Questions

View Set

Biotechnology Exam #3 Ch. 6, CHEM 527 Exams, Biotechnology Exam #2 Ch.18 Plant Biotechnology, Biotechnology Ch. 3 Exam 1, Biotechnology Exam #2 Ch. 5 (Genomics), Biotechnology Ch. 2 Exam #1, Biotechnology Ch. 1 Exam 1, Biotech Test 3, Biotechnology E...

View Set

Chapter 5: Competitive Advantage, Firm Performance, and Business Models

View Set

GS2102 Unit Three Exam Study Guide

View Set

Unit 5 Driver Education Questions

View Set

IGCSE History: Causes of the First World War

View Set

Ap psychology myers modules 31-36

View Set