obj prog final 2

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

To quit, a user types 'q'. To continue, a user types any other key. Which expression evaluates to true if a user should continue? a. key == 'q' b. key != 'q' c. (!key) == 'q' d. key == (!'q')

b

What happens if a recursive function in a program never reaches the base case? a. The program will run until the recursive case ends. b. The program will lead to infinite recursion. c. The recursive function will not run. d. The base case will be forced to run by the program.

b

What is the correct syntax for a catch-all handler? a. catch(all_errors& excpt) b. catch(...) c. catch(& excpt) d. catch()

b

What is the ending value of x? int y = 6;int x = (4 / 2) * y + 8; a. 8 b. 20 c. 28 d. 32

b

What is the index of the last element? int numList[50]; a. 0 b. 49 c. 50 d. Unknown, because the array has not been initialized.

b

What is the output, if the input is 3 2 4 5? All variables are integers. cin >> num;for (i = 0; i < num; ++i) { cin >> curr; cout << curr;} a. 24 b. 245 c. 324 d. 3245

b

What is the output? #include <iostream>#include <iomanip>using namespace std;int main() { cout << setfill('-') << setw(7) << "Tim" << endl; return 0;} a. -------Tim b. ----Tim c. Tim------- d. Tim----

b

Which reads an entire line of text into string myString? a. cin >> myString; b. cin >> getline(myString); c. getline(cin, myString); d. getline(cin >> myString);

c

hat is the output? int a = 10;do { cout << a << " "; a = a + 1;} while (a < 15); a. 11 12 13 12 b. 11 12 13 14 15 c. 10 11 12 13 14 d. 10 11 12 13 14 15

c

Choose the correct option. Concrete classes _________ a. do not have any member functions. b. cannot be instantiated, only inherited. c. cannot be inherited, only instantiated. d. do not have any pure virtual functions.

d

For a class SampleCopy, identify the incorrect way to call a copy constructors to copy object1 to object2. a. SampleCopy object2(object1); b. SampleCopy object2 = object1; c. SampleCopy object2; object2 = &object1; d. SampleCopy object2(&object1);

d

For the class Timer, which XXX initializes the variables to 0? class Timer { public: XXX void Print() { cout << minutes << ":" << seconds; }; private: int minutes; int seconds; }; a. Timer { minutes = 0; seconds = 0; } b. Timer::Timer() { minutes = 0; seconds = 0; } c. Timer() = 0; d. Timer() { minutes = 0; seconds = 0; }

d

For what values of integer x will Branch 3 execute? If x < 10 : Branch 1 Else If x > 9: Branch 2 Else: Branch 3 a. Value 10 or larger b. Value 10 only c. Values between 9 and 10 d. For no values (never executes)

d

Given an integer vector of size NUM_ELEMENTS, which XXX, YYY, and ZZZ will count the number of times the value 4 is in the vector? Choices are in the form XXX / YYY / ZZZ. vector<int> myVect(NUM_ELEMENTS);int cntFours;XXXfor (i = 0; YYY; ++i) { if (myVals.at(i) == 4) { ZZZ; }} a. cntFours = myVect.at(0); / i > myVect.size(); / cntFours = myVect.at(i); b. cntFours = myVect.at(1); / i < myVect.size(); / cntFours = myVect.at(i) + 1; c. cntFours = 1; / i > NUM_ELEMENTS; / cntFours = cntFours + 1;

d

Given integer vector x has elements 5, 10, 15, 20. What is the output? int i;for (i = 0; i < x.size(); ++i) { cout << x.at(i) + x.at(i + 1); } a. 10, 15, 20, 5 b. 15, 25, 35, 25 c. 15, 25, 35, 20 d. Error: Invalid vector access

d

Given the two vectors, which code will output all the vectors' elements, in the order key, item followed by a newline? vector<int> keysList(SIZE_LIST);vector<int> itemsList(SIZE_LIST); a. cout << keyList.at(SIZE_LIST - 1) << ", " << itemsList.at(SIZE_LIST - 1) << endl; b. cout << keyList.at(SIZE_LIST) << ", " << itemsList.at(SIZE_LIST) << endl; c. for (i = 0; i < keysList.size() - 1; ++i) { cout << keyList.at(i) << ", " << itemsList.at(i) << endl;} d. for (i = 0; i < keysList.size(); ++i) { cout << keyList.at(i) << ", " << itemsList.at(i) << endl;}

d

Given year is positive, which expressions for XXX, YYY, and ZZZ will output the correct range? Choices are in the form XXX / YYY / ZZZ. If XXX: Output "1-100" Else If YYY: Output "101-200" Else If ZZZ: Output "201-300" Else: Output "Other" a. year > 0 / year > 99 / year > 199 b. year > 0 / year > 100 / year > 200 c. year < 100 / year < 200 / year < 300 d. year < 101 / year < 201 / year < 301

d

How many elements are in the array? int userVals[2][4]; a. 2 b. 4 c. 6 d. 8

d

Mustang is an object of type Car. Which statement invokes drive()? a. Car.drive(150); b. drive(135); c. mustang->drive(115); d. mustang.drive(145);

d

The following program generates an error. Why? const int NUM_ELEMENTS = 5;int userVals[NUM_ELEMENTS];unsigned int i;userVals[0] = 1;userVals[1] = 7;userVals[2] = 4; for (i = 0; i <= NUM_ELEMENTS; ++i) { cout << userVals[i] << endl;} a. Variable i is declared as an unsigned integer. b. The array userVals has 5 elements, but only 3 have values assigned. c. The integer NUM_ELEMENTS is declared as a constant. d. The for loop tries to access an index that is out of the array's valid range.

d

What is the ending value of userNum? vector<int> userValues;int userNum;userNum = 0;userValues.push_back(45);userValues.push_back(55);userNum = userValues.pop_back(); a. 0 b. 45 c. 55 d. Error: pop_back does not return a value

d

What is the output if the input is x and y? #include <iostream> using namespace std;class toShowComplex { public: toShowComplex(int r = 0, int i = 0) { theReal = r; theImag = i; } friend ostream& operator << (ostream& out, const toShowComplex& c); friend istream& operator >> (istream& in, toShowComplex& c); private: int theReal, theImag;};ostream& operator << (ostream& out, const toShowComplex& c) { out << c.theReal; out << "+i" << c.theImag << endl; return out;}int main() { toShowComplex comp; cout << "The complex number is "; cout << comp; return 0;} a. The complex number is x+iy. b. Error: Compiler error. c. Error: Runtime error. d. The complex number is 0+i0.

d

What is the output? #include <iostream>using namespace std;class Line { public: Line () { cout << "No such line"; }};int main() { Line L1, *L2; return 0;} a. Compiler error b. L1 *L2 c. No output d. No such line

d

What is the output? for (i = 0; i <= 10; ++i) { if (i == 6) continue; else cout << i << " "; } a. 0 1 2 3 4 5 b. 0 1 2 3 4 5 6 c. 0 1 2 3 4 5 7 8 9 d. 0 1 2 3 4 5 7 8 9 10

d

What is the output? void printer() { cout << "hello" << endl; printer(); } int main() { printer(); return 0; } a. hello b. hello hello c. hello hello hello d. stack overflow

d

What is the value of fordFusion's odometer at the end of main( )? class SimpleCar { public: SimpleCar(); SimpleCar(int miles); void Drive(int miles); private: int odometer;};SimpleCar::SimpleCar() { odometer = 0;}SimpleCar::SimpleCar(int miles) { odometer = miles;}void SimpleCar::Drive(int miles) { odometer = odometer + miles;} int main() { SimpleCar fordFusion; SimpleCar hondaAccord(30); fordFusion.Drive(100); fordFusion.Drive(20); return 0;} a. 20 b. 30 c. 100 d. 120

d

Which constructor will be called by the statement House myHouse(97373); for the given code? class House { House(); // Constructor A House(int zip, string street); // Constructor B House(int zip, int houseNumber); // Constructor C House(int zip); // Constructor D}; a. Constructor A b. Constructor B c. Constructor C d. Constructor D

d

Which input for char c causes "Done" to be output next? c = 'y';while (c = 'y') { // Do something cout << "Enter y to continue, n to quit: "; cin >> c;}cout << "Done"; a. 'y' only b. 'n' only c. Any value other than 'y' d. No such value (infinite loop)

d

Which of the following is the LinkedList class destructor? a. delete LinkedList(); b. int ~LinkedList(); c. void ~LinkedList(); d. ~LinkedList();

d

Which statement uses buffer manipulators to immediately display the following on the screen? Good morning a. cout << "Good morning"; b. cout <<"Good" << endl << "morning"; c. cout << "Good\nmorning\n"; d. cout << "Good" << endl << "morning" << flush;

d

Binary search begins at the ______ of the range. a. midpoint b. given index c. first element d. last element

a

Given a vector sensorReadings containing the values -2, 5, and 4, what is the output of the code? for (int &sensorVal : sensorReadings) { sensorVal = sensorVal - 1; cout << sensorVal << endl;} a. -3 4 3 b. -2 5 4 c. -1 4 3 d. -1 -1 -1

a

Given an integer vector of size NUM_ELEMENTS, which XXX, YYY, and ZZZ will count the number of times the value 4 is in the vector? Choices are in the form XXX / YYY / ZZZ. vector<int> myVect(NUM_ELEMENTS);int cntFours;XXXfor (i = 0; YYY; ++i) { if (myVals.at(i) == 4) { ZZZ; }} a. cntFours = myVect.at(0); / i > myVect.size(); / cntFours = myVect.at(i); b. cntFours = myVect.at(1); / i < myVect.size(); / cntFours = myVect.at(i) + 1; c. cntFours = 1; / i > NUM_ELEMENTS; / cntFours = cntFours + 1; d. cntFours = 0; / i < NUM_ELEMENTS; / ++cntFours;

a

Given the following function. To change the function to return the product instead of the sum, how many lines of code need to be changed? int Calculate(int a, int b) { return a + b;}int main() { cout << Calculate(3, 4); cout << Calculate(5, 2); cout << Calculate(6, 7); return 0;} a. 1 b. 2 c. 3 d. 4

a

Header file guards are preprocessor directives whose primary role is to cause the compiler to _____ a. only include the contents of the header file once b. allow defining a constant that can be used throughout a user's program c. allow defining a function that can be used throughout a user's program d. link together the object files and libraries

a

Identify the existing statement in the code that results in an error. class Student { public: void SetName(string studentName); void Display(); private: string name; int grade; int Grade();};void Student::Display() { grade = Grade(); ...}int Student::Grade() { ...}void Student::SetName(string studentName) { name = studentName;}int main() { Student student1; student1.Display(); ... student1.Grade();} a. student1.Grade(); b. student1.Display(); c. int Student::Grade() d. void Student::Display() { grade = Grade();}

a

In a linked list, a node is comprised of a(n) _____. a. data element and a pointer to the next node b. member functions and a class c. data element and a class d. object and a pointer to the next node

a

The _____ construct defines a new type to group data and functions to form an object. a. class b. struct c. array d. library

a

The code memory is a region in program memory where _____. a. the program instructions are stored b. global and static local variables are allocated c. the "new" operator allocates memory d. a function's local variables are allocated

a

The ostringstream member function ____ returns the contents of an ostringstream buffer as a string. a. str() b. setw() c. setfill() d. fixed(

a

What are the ending values in itemCount? vector<int> itemCount;itemCount.push_back(6);itemCount.push_back(7);itemCount.push_back(8);itemCount.pop_back(); a. 6, 7 b. 6, 7, 8 c. 7, 8 d. 6, 7, 0

a

What is the ending value of x? x = 160 / 20 / 4; a. 2 b. 16 c. 32 d. No value; runtime error

a

Which XXX (string stream) returns the following output?Hello John Denver #include <iostream>#include <sstream>#include <string>using namespace std;int main() { string userInfo = "John Denver"; XXX string firstName; string lastName; inSS >> firstName; inSS >> lastName; cout << "Hello " << firstName << " " << lastName << endl; return 0;} a. istringstream inSS(userInfo); b. istringstream userInfo; c. inSS(userInfo); d. istringstream inSS;

a

Which XXX completes insertAfter( ) to insert a node after the current node? InsertAfter(IntNode* nodeLoc) { IntNode* tmpNext = nullptr; tmpNext = this->nextNodePtr; XXX nodeLoc->nextNodePtr = tmpNext;} a. this->nextNodePtr = nodeLoc; b. this.nextNodePtr = nodeLoc; c. &nextNodePtr = nodeLoc; d. nextNodePtr = nodeLoc;

a

Which XXX completes the program to read in a list of numbers into a string stream? #include <iostream>#include <sstream>#include <string>using namespace std;int main() { istringstream inSS; int number; int sum = 0; string numList; cout << "Enter a list of numbers separated by spaces: "; XXX while (inSS >> number) { sum = sum + number; } cout << "Sum: " << sum << endl; return 0;} a. getline(cin, numList);inSS.str(numList); b. getline(cin, numList); c. inSS.str(numList); d. getline(cin, inSS);inSS.str();

a

Which XXX generates "Adam is 30 years old." as the output? #include <iostream>using namespace std;int main() { string name = "Adam"; int age = 30; XXX return 0;} a. cout << name << " is " << age << " years old."; b. cout << name << "is" << age << "years old ."; c. cout >> name >> " is " >> age >> " years old ."; d. cout >> name >> "is" >> age >> "years old .";

a

If the input is 12, what is the final value for numItems? int x;int numItems = 12;cin >> x;if (x == 12) { numItems = 100;}else { numItems = 200;}numItems = numItems + 1; a. 100 b. 101 c. 200 d. 201

b

Which code can be used as a recursive function to find the nth element in a Fibonacci series? #include <iostream>using namespace std;int main() { int n; n = 10; cout << Fibo(n) << endl; return 0;} a. int Fibo(int n) { if (n == 1) { return 0; } else if (n == 2) { return 1; } else { return Fibo(n - 1) + Fibo(n - 2); }} b. int Fibo(int n) { if (n == 1) { return 0; } else if (n == 2) { return Fibo(1); } else { return Fibo(n - 1) + Fibo(n - 2); }} c. int Fibo(int n) { if (n == 1) { return Fibo(n - 1); } else if (n == 2) { return Fibo(n - 2); } else { return 0; } } d. int Fibo(int n) { if (n == 1) { return 0; } else if(n == 2) { return 1; } else { return Fibo(n) + Fibo(n - 1); }}

a

Which expression follows the practice of using parentheses to make the intended order of evaluation explicit? x > y && !a == b a. (x > y) && (!a == b) b. (x > (y)) && ((!a == b)) c. ((x > y) && !a == (b)) d. ((x > y)) && ((!a == b))

a

Which input value causes "Goodbye" to be output next? int x;cin >> x;while (x >= 0) { // Do something cin >> x;}cout << "Goodbye"; a. -1 b. 0 c. 1 d. No such value

a

Which operator is the insertion operator? a. << b. >> c. < d. >

a

Which statement declares a copy assignment operator for a class named PatientDetails using inVal as the input parameter name? a. PatientDetails& operator=(const PatientDetails& inVal); b. PatientDetails& operator=(PatientDetails inVal); c. PatientDetails operator=(PatientDetails inVal); d. PatientDetails& operator=(const PatientDetails inVal);

a

Which type of relationship is depicted in the following code? class Dog { int lifespan; int height;};class Poodle : public Dog { string pedigree;};class Greyhound : public Dog { int speed;}; a. Is-a b. Has-a c. Of-a d. Was-a

a

A programmer is overloading the equality operator (==) and has created a function named operator==. What are the return type and arguments of this function? a. Return type: class type, Arguments: 1 const bool reference b. Return type: bool, Arguments: 2 const class type references c. Return type: none, Arguments: 2 const class type references d. Return type: int, Arguments: 2 const bool references

b

A stack overflow typically causes a program to _____. a. return a value b. crash c. give multiple outcomes d. give an incorrect output

b

Assuming char* firstSymbol; is already declared, return a pointer to the first instance of an '!' in userInput. a. firstSymbol = strrchr(userInput,'!'); b. firstSymbol = strchr(userInput, '!'); c. firstSymbol = strrchr('!', userInput); d. firstSymbol = strchr('!', userInput);

b

Declaring a member as ____ in the base class provides access to that member in the derived classes but not to anyone else. a. public b. protected c. private d. constant

b

Given integer vector x has 5 elements with values 4, 7, 3, 0, 8. What are the ending values in x? int i;for (i = 0; i < x.size() - 1; ++i) { x.at(i) = x.at(i + 1);} a. 4, 4, 7, 3, 0 b. 7, 3, 0, 8, 8 c. 7, 3, 0, 8, 4 d. Error: Invalid vector access

b

How many times does the for loop execute? #include <iostream>#include <vector>using namespace std;int main() { vector<int> ages; int result; ages.push_back(8); ages.push_back(4); ages.push_back(10); ages.push_back(6); result = 0; for (auto currentAge : ages) { result = result + currentAge / 2; } cout << result; return 0;} a. 3 b. 4 c. 5 d. Error

b

How many times will the loop iterate, if the input is 105 107 99 103? cin >> x;while (x > 100) { // Do something cin >> x;} a. 1 b. 2 c. 3 d. 4

b

How many x's will be output? Assume row and col are ints. for (row = 0; row < 2; ++row) { cout << "x"; for (col = 0; col < 3; ++col) { // Do something }} a. 1 b. 2 c. 3 d. 6

b

What is the output? #include <iostream>using namespace std;class HomeAppliance { public: void SetDetails(string name, string id) { appName = name; appID = id; }; void PrintDetails() { cout << "Appliance Name: " << appName << endl; cout << "Appliance ID: " << appID << endl; }; protected: string appName; string appID;};class Blender : public HomeAppliance { public: void a. Appliance Name: MyBlender Appliance ID: VS213 b. Appliance Name: MyBlender Appliance Price: $145.5 c. Appliance Name: MyBlender Appliance ID: VS213 Appliance Name: MyBlender Appliance Price: $145.5 d. Appliance Name: MyBlender Appliance Price: $145.5 Appliance Name: MyBlender Appliance ID: VS213

b

What is the output? #include <iostream>using namespace std;class Person { public: virtual void PrintInfo() = 0; void PrintInformation() { cout << "in base class Person" << endl; } protected: string name; int age;};class Teacher : public Person { public: void PrintInfo() { cout << "in child class Teacher" << endl; } private: int experience;};int main() { Teacher mathTeacher; mathTeacher.PrintInfo(); return 0;} a. in base class Person b. in child class Teacher c. in child class Teacher in base class Person d. in base class Person in child class Teacher

b

What is the output? void TimeHour(int hours) { int timeLeft; try { if (hours > 23) { throw runtime_error("Invalid Hour!"); } timeLeft = 24 - hours; cout << "Time Left: " << timeLeft << endl;} catch (runtime_error& excpt) { cout << "Oops" << endl; cout << excpt.what() << endl; } }int main() { TimeHour(24); return 0;} a. Invalid Hour! Time Left: 0 b. Oops Invalid Hour! c. Oops Invalid Hour! Time Left: 0 d. Invalid Hour! Oops

b

When a derived class defines a member function that has the same name, parameters, and return type as a base class's function, the member function is said to _____ the base class's function. a. overload b. override c. inherit d. copy

b

When using outer and inner methods for recursion, typically, the outer method should check for a valid _____ and then call the inner method. a. condition counter b. input value c. output value d. recursive call

b

Which XXX best defines the function's integer vector parameter scores, if scores will have just a few elements, and the function will not change scores? void Quiz1 (XXX) {...} a. scores b. const vector <int> scores c. vector <int>& scores d. const vector<int>& scores

b

Which XXX declares a member function called GetAmount() and returns the variable amount? class Bill { public: void SetProduct(string prodName); void SetAmount(int prodAmount); XXX private: string name; double amount;};int main() { Bill myBill; cout << myBill.GetAmount();} a. void GetAmount(); b. double GetAmount(); c. void Bill::GetAmount(); d. double Bill::GetAmount();

b

Which expression for YYY outputs "Quarter century!" when the input is 25? int x;cin >> x;if (YYY){ cout << "Nothing special";}else { cout << "Quarter century!";} a. x == 25 b. x != 25 c. x <> 25 d. x == !25

b

Which is true about testing a function with three integer parameters and one integer return value? a. A good programmer would test all possible input values for the function b. Using various calls involving assert() is a good way to test the function c. Three test vectors are likely sufficient for testing purposes d. Each test case should include a negative valued parameter

b

Which of the following is true for overloading a class constructor? a. The return types of the constructors should be different. b. The parameter types of the constructors should be different. c. The name of the constructor should be different. d. The access scope of the constructors should be different.

b

Which statement is true about inheritance? a. A derived class cannot serve as a base class for another class. b. A class can serve as a base class for multiple derived classes. c. A class can be derived from only one class. d. A class can serve as a base class for only one class.

b

Which statement properly frees the dynamically allocated array below? Musketeer* musketeers = new Musketeer[8]; a. delete musketeers; b. delete[] musketeers; c. musketeers->delete; d. for(i = 0; i < 8; i++) { delete musketeers[i];}

b

A linked list's head node stores _____ in the list. a. the count of items b. the value of the first item c. a pointer to the first item node d. a pointer to all the nodes

c

A recursive algorithm is based on _____ application(s) of the same algorithm on smaller problems. a. single b. zero c. repeated d. infinite

c

For what values of x will "Medium" be output? If x > 40: Output "Large" Else If x > 20: Output "Medium" Else If x > 10: Output "Small" a. Any x larger than 20 b. Any x smaller than 40 c. Any x from 21 to 40 d. Any x from 10 to 40

c

Given the following function definition, which function call prints x, y, 0? void Test(char a, char b = 'y', int num = 0) { cout << a << ", " << b << ", " << num << endl;} a. Test ('x' 'y'); b. Test(x, y); c. Test('x'); d. Test('x', 'y', 'z');

c

Given two integer vectors origList = {2, 3, 4, 5} and offsetList = {6, 7, 8, 9}, which statement prints out the sum of the second element in the origList with the corresponding element in the offsetList? a. cout << origList + offsetList << endl; b. cout << origList.at(2) + offsetList.at(2) << endl; c. cout << origList.at(1) + offsetList.at(1) << endl; d. cout << origList.at(1) + offsetList.at(2) << endl;

c

Given two vectors, studentNames that maintains a list of students, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX/ YYY. vector<string> studentNames(NUM_STUDENTS);vector<int> studentScores(NUM_STUDENTS); unsigned int i; for (i = 0; i < studentScores.size(); ++i) { if (XXX > 80) { cout << YYY << " "; }} a. studentNames.at(i) / studentNames.at(i) b. studentNames.at(i) / studentScores.at(i) c. studentScores.at(i) / studentNames.at(i) d. studentScores.at(i) / studentScores.at(i)

c

Which operator is overloaded to copy objects? a. Logical operator b. Relational operator c. Assignment operator d. Comparison operator

c

If the input is 5, what is the output? int x;cin >> x;if (x < 10) { cout << "Live "; }else if (x < 20) { cout << "long ";}else if (x < 30) { cout << "and ";}cout << "prosper!"; a. Live b. Live long c. Live prosper! d. Error: The compiler will complain about a missing else statement

c

In the following code, where is variable a stored? #include <iostream>using namespace std;int a = 10; int Add(int x, int y) { int b; b = x + y; return b;}int main() { int c; c = 20; int d; d = Add(a, c); cout << d; return 0; } a. code memory b. stack c. static memory d. heap

c

The following code generates an error. Why? class Player {public: void SetName(string newName) { ... }private: void SetAge(int newAge) { ... }};class SoccerPlayer: public Player { public: void SetDetails(string newName) { ... } string GetLeague() { ... }}; int main() { string leagueName; SoccerPlayer newPlayer; newPlayer.SetName("Jim Allen"); newPlayer.SetAge(21); leagueName = newPlayer.GetLeague(); return 0;} a. leagueName = newPlayer.GetLeague() will generate an error as the derived class members should not be called by the derived class. b. newPlayer.SetName("Jim Allen") will generate an error as SetName is not declared in class SoccerPlayer. c. newPlayer.SetAge(21) will generate an error as SetAge is a private member not inherited by the SoccerPlayer class. d. SoccerPlayer newPlayer will generate an error as an object of a derived class cannot be created.

c

UML uses italics to denote ___ classes. a. base b. derived c. abstract d. built-in

c

What are the ending values in countVal? vector<int> countVal;countVal.resize(3);countVal.at(0) = 22;countVal.at(1) = 33;countVal.at(2) = 44; a. 22, 33, 44, 0 b. 22, 33, 44, 0, 0, 0 c. 22, 33, 44 d. Error: Cannot resize after declaring

c

What is the ending value of y if x is 50? y and x are ints. y = (x < 21) ? 100 : x; a. 'x' b. 21 c. 50 d. 100

c

What is the output? #include <iostream> using namespace std; class School { public: School() { y++; } static int getY() {return y;} private: static int y;}; int School::y = 0; int main() { cout << School::getY() << " "; School t[5]; cout << School::getY(); } a. 0 1 2 3 4 5 b. 5 5 c. 0 5 d. 0 0

c

What is the output? #include <iostream>using namespace std; template<typename MyType>MyType large(MyType var1, MyType var2) { if (var1 > var2) { return var1; } else { return var2; } }int main() { cout << large(3,7) << " "; cout << large('A','B') << " "; cout << large(3.3,3.4) << endl; return 0;} a. 7 A 3 b. Error: The compiler generates an error in all the cout statements because the data type is not specified. c. 7 B 3.4 d. 7 'A' 3.4

c

What is the output? #include <iostream>using namespace std;class Database { public: Database() { cout << "Constructor called" << endl; } ~Database() { cout << "Destructor called" << endl; } void print() { cout << "Database loading" << endl; }}; int main() { Database db1; db1.print(); return 0;} a. Constructor called Destructor called Database loading b. Database loading Constructor called Destructor called c. Constructor called Database loading Destructor called d. Database loading

c

What is the output? int num = 10;while (num <= 15) { cout << num << " "; if (num == 12) { break; } ++num; } cout << "Done"; a. 10 Done b. 10 11 Done c. 10 11 12 Done d. 10 11 12 13 14 15 Done

c

What is the output? int x = 18;while (x > 0) { // Output x and a space x = x / 3; } a. 6 2 b. 6 2 0 c. 18 6 2 d. 18 6 2 0

c

What is the output? void BaggageWeight(int weight) { bool value = false; try { while (!value) { if (weight > 30) { throw runtime_error("Double Max Weight"); } if (weight > 15) { throw runtime_error("Excess Weight"); } value = true; cout << "Accepted" << endl; } } catch (runtime_error& excpt) { cout << excpt.what() << endl; }}int main() { BaggageWeight(42); return 0;} a. Accepted b. Double Max Weight Accepted c. Double Max Weight d. Double Max Weight Excess Weight

c

What is the return type for constructors? a. void b. int c. Constructors do not have a return type. d. The return type depends on the constructors' definition.

c

What is unit testing? a. Checking that the integer values of a function use proper units (yards, meters, etc.) b. Dividing larger function parameters into several smaller parameters known as units c. Individually testing a small part (or unit) of a program, typically a function, using a separate program called a test harness d. Ensuring a program is not one large function but rather consists of numerous smaller functions (units)

c

What is y after executing the statements? x = 4;y = x + 1;x = 3;y = y * 2; a. 6 b. 8 c. 10 d. 12

c

Which XXX calls PromptForUserNameScore() to get the user's name and score and store those values in the userName and userScore variables? void PromptForUserNameScore(string& userName, int& userScore) { cout << "Enter your name: " << endl; cin >> userName; cout << "Enter your score: " << endl; cin >> userScore;}int main() { string userName; int userScore; XXX; cout << userName << ", " << userScore << endl; return 0;} a. PromptForUserNameScore(string& userName, int& userScore); b. PromptForUserNameScore(string userName, int userScore); c. PromptForUserNameScore(userName, userScore); d. PromptForUserNameScore(&userName, &userScore);

c

Which XXX will generate 12 as the output? #include <iostream>#include <vector>using namespace std;int main() { vector<int> scores; int sum; scores.push_back(2); scores.push_back(4); scores.push_back(1); scores.push_back(5); sum = 0; for (XXX) { sum = sum + currentScore; } cout << sum; return 0;} a. currentScore : scores b. auto scores : currentScore c. auto currentScore : scores d. scores : currentScore

c

Which YYY outputs the string in reverse? Ex: If the input is "Oh my", the output is "ym hO". int i;string str;getline(cin, str);for (YYY) { cout << str.at(i);} a. i = str.length(); i < 0; --i b. i = str.length(); i > 0; --i) c. i = str.length() - 1; i >= 0; --i) d. i = str.length() + 1; i > 0; --i)

c

Which best describes what is output? Assume v is a large array of ints. int i;int s;s = v[0];for (i = 0; i < N_SIZE; ++i) { if (s > v[i]) { s = v[i]; }}cout << s; a. first value in v b. max value in v c. min value in v d. last value in v

c

Which best describes what is output? Assume v is a large vector of ints. int i;int s;s = v.at(0);for (i = 0; i < v.size(); ++i) { if (s > v.at(i)) { s = v.at(i); }}cout << s; a. first value in v b. max value in v c. min value in v d. last value in v

c


Set pelajaran terkait

Chapter 20: Nursing Care of the Child With an Alteration in Bowel Elimination/Gastrointestinal Disorder - ML3

View Set

Fraud & Misrepresentation Real Estate

View Set

Group 1 - Chapter 09: Section 9.1-9.2 - Biotechnology and DNA Technology

View Set

ACP 135 (F) Communications Instructions distress and rescue procedures

View Set

Bone Features (Examples/ Pictures)

View Set

Renal Class 2, Glomerular Filtration and Renal Blood Flow

View Set

Ch. 10 purchasing and financing a home-hoyt

View Set