c++ chapter 7-15

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following is not true for catch blocks? Catch blocks are checked in sequence from top to bottom. The final catch block is catch (...), which matches any object type, so that block will execute. Catch blocks are checked in sequence from bottom to top. When a catch block matches, any subsequent catch blocks are skipped.

Catch blocks are checked in sequence from bottom to top.

What is output? class Greet {public:string g1;string g2;string g3;string g4;void Print() const;Greet() {g1 = "Hi! ";g3 = "Good morning! ";g4 = "Good night! ";}}; void Greet::Print() const {cout << g1 << g2 << g3;} int main() {Greet user1;user1.Print();user1.g2 = "Hello!";return 0;} Hi! Hello! Good morning! Good night! Hi! Hello! Good morning! Hi! Good morning! Good night! Hi! Good morning!

Hi! Good morning!

What is output? class Shapes {public:void Print();Shapes(int x);private:int sides = 4;}; Shapes::Shapes(int x) {this->sides = x;} void Shapes::Print() {if(this->sides == 4) {cout << "It's a Square!" << endl;}else {cout << "Oops!";}} int main() {Shapes s(7);s.Print();return 0;} Oops, It's a Square! It's a Square! It's a Square, Oops! Oops!

Oops!

Which of the following exception-handling constructs is known as handler? try throw keep catch

catch

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

catch(...)

Which syntax is used to create a template object of data type myData for a class className? className myData classObject; className<myData> :: classObject; className<myData> classObject; className myData : classObject;

className<myData> classObject;

_____ is a predefined ostream object that is pre-associated with a system's standard output, usually a computer screen. cin << >> cout

cout

Which line in the code generates 10 as the output? #include <iostream>#include <deque>using namespace std; void myDq(deque <int> g) { deque <int> :: iterator ITR; } int main() { deque <int>myQuiz; myQuiz.push_back(10); myQuiz.push_front(20); myQuiz.push_back(30); myQuiz.push_front(15); cout << myQuiz.size() << endl; cout << myQuiz.max_size() << endl;cout << myQuiz.at(2) << endl;cout << myQuiz.front() << endl; cout << myQuiz.back() << endl; return 0; } cout << myQuiz.front(); cout << myQuiz.at(2); cout << myQuiz.back(); cout << myQuiz.size();

cout << myQuiz.at(2);

Which statement will generate 3.140e+00 as the output? cout << setprecision(3) << scientific << 3.14; cout << setprecision(2) << scientific << 3.14; cout << setprecision(3) << scientific << 31.4; cout << setprecision(2) << scientific << 31.4;

cout << setprecision(3) << scientific << 3.14;

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

data element and a pointer to the next node

Which statement is the correct way to declare a deque class for a string? string newDeque deque<>; deque<string> newDeque; newDeque deque<string>; deque<newDeque string>;

deque<string> newDeque;

Which XXX condition generates the following output? Not found #include <iostream>#include <string>#include <vector>using namespace std;int BinarySearch(vector<int> numberList, int element, int lowVal, int highVal) {int midVal;if (XXX) {midVal = (highVal + lowVal) / 2;if (numberList.at(midVal) == element) {return midVal;}else if (numberList.at(midVal) > element) {return BinarySearch(numberList, element, lowVal, midVal - 1);}else {return BinarySearch(numberList, element, midVal + 1, highVal);}}else {return -1;}}int main() {vector<int> numberList(0);int element = 20;int matchPos;for (int i = 0; i <= 10; i++) {numberList.push_back(i);}matchPos = BinarySearch(numberList, element, 0, numberList.size() - 1);if (matchPos >= 0) {cout << "Found at position " << matchPos << "." << endl;}else {cout << "Not found. " << endl;}return 0;} lowVal + highVal == 0 lowVal <= highVal lowVal >= highVal lowVal == highVal

lowVal <= highVal

Assuming a class has been defined, which of the following statements is correct for declaring a vector? vector[Student] studList; vector Student <studList>; vector Student studList; vector<Student> studList;

vector<Student> studList;

Identify the correct statement for defining the public function. #include <iostream>using namespace std; class School {public:XXX {numClassrooms = crNum;numGrades = grNum;numTeachers = tNum;}private:int numClassrooms;int numGrades;int numTeachers;}; int main() {School newSchool;int classroomNum;int gradeNum;int teacherNum;cout << "Enter the number of classrooms in the new school:" << endl;cin >> classroomNum;cout << "Enter the number of grades in the new school:" << endl;cin >> gradeNum;cout << "Enter the number of teachers the new school:" << endl;cin >> teacherNum;newSchool.SetDetails(classroomNum, gradeNum, teacherNum);return 0;} int SetDetails(int crNum, int grNum, int tNum) School.SetDetails(int crNum, int grNum, int tNum) char SetDetails(int crNum, int grNum, int tNum) void SetDetails(int crNum, int grNum, int tNum)

void SetDetails(int crNum, int grNum, int tNum)

If the list {3 9 7 18 1} is being sorted in ascending order using selection sort, what will be the list after completing the second outer loop iteration? {1 9 7 18 3} {1 3 9 18 7} {1 3 7 18 9} {1 3 7 9 18}

{1 3 7 18 9}

Which of the following is the LinkedList class destructor? void ~LinkedList(delete); ~LinkedList(int); void ~LinkedList(); ~LinkedList();

~LinkedList();

Given the following list of sorted elements, how many elements of the list will be checked to find 25 using binary search? {12, 13, 15, 20, 23, 24, 25, 36, 40} 7 8 3 2

2

How many base cases are required to print the Fibonacci series? #include <iostream>using namespace std;int fibo(int n) {if(n == 0 || n == 1) {return n;}return fibo(n - 1)+fibo(n - 2);}int main() {int n = 10;for(int i = 0; i <= n; i++)cout << fibo(i) << " ";return 0;} 3 1 2 0

2

Which function by default aborts the program when the exception handling mechanism cannot find a handler for a thrown exception? return() terminate() catch() exit()

terminate()

The sort() function can be used with numerous STL containers, but the container elements should be any C++ data type that supports the use of _____. the right shift operator (>>) the greater than operator (>) the left shift operator (<<) the less than operator (<)

the less than operator (<)

Which XXX and YYY complete the class School's member function correctly? class School {public:void SetDetails(int numStudents, string name);void Print();private:int nStudents;string schoolName;}; void School::SetDetails(int numStudents, string name) {XXXYYYthis->Print();} void School::Print() {cout << this->nStudents << " Students are in " << this->schoolName << endl;} int main() {School mySchool;mySchool.SetDetails(100, "New School");mySchool.SetDetails(35, "New School"); mySchool.Print();return 0;} this->nStudents;this->schoolName; this->numStudents = nStudents;this->name = schoolName; this->numStudents;this->name; this->nStudents = numStudents;this->schoolName = name;

this->nStudents = numStudents;this->schoolName = name

Which keyword can be used instead of class? template <class T>T someFunction(T arg) {... .. ...} typeclass datatype typename name

typename

Which XXX adds indent in the output statements for debugging a recursive function to find the value of Nk ? #include <iostream>using namespace std;int NPowerK(int n, int k, string indent) {int value;if (k == 0) { cout << indent << "Base Condition Reached: K = 0" << endl;return 1;}else {cout << indent << "Recursive call: K = " << k - 1 << endl;XXX;cout << indent << "Recursion Return Value for K = " << k - 1 << endl;;return n * value;}}int main () {int n = 2;int k = 2;string indent = " ";cout << n << " to the power " << k << " = " << NPowerK(n,k,indent) << endl; return 0;} value = NPowerK(n, k, indent) value = NPowerK(n, k - 1, indent + " ") value = NPowerK(n, k + 1, indent + " ") value = NPowerK(n, k + 1, indent - " ")

value = NPowerK(n, k - 1, indent + " ")

The _____ enables use of the pair class. #include <utility> #include <list> #include <iostream> #include <pair>

#include <utility>

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

----Tim

Which XXX will generate the following output? LIST 3 5 8 11 12 33 46 88 Enter a value: 0 was not found. #include <iostream>using namespace std;int LinearSearch(int list[], int listSize, int key) {int i;for (i = 0; i < listSize; ++i) {if (list[i] == key) { return i; } }return XXX; }int main() {int list[] = { 3, 5, 8, 11, 12, 33, 46, 88 };const int LIST_SIZE = 8;int i;int key;int keyIndex;cout << "LIST ";for (i = 0; i < LIST_SIZE; ++i) {cout << list[i] << ' ';}cout << endl;cout << "Enter a value: ";cin >> key; keyIndex = LinearSearch(list, LIST_SIZE, key);if (keyIndex == -1) {cout << key << " was not found." << endl;}else {cout << "Found " << key << " at index " << keyIndex << "." << endl;}return 0;} 0 1 2 -1

-1

What is output? #include <iostream>#include <queue>#include <map>#include <string>using namespace std;int main () {queue<double>joyTime;double yourNum = 0; joyTime.push(15.5);joyTime.push(14.5);joyTime.front();joyTime.push(13.5);joyTime.pop();joyTime.push(12.5);joyTime.pop();joyTime.push(11.5);joyTime.pop();yourNum = joyTime.front() + joyTime.size();cout << yourNum;return 0;} 13.5 14.5 16.5 12.5

14.5

What is output? #include <iostream>#include <ios>#include <iomanip>using namespace std; int main() {int num = 5;for(int i = 0; i < 3; i++) {cout << num << setw(5) << setfill('*') << num << endl;num = num * 5;}return 0;} 5****25***125** ****5***25**125 5 525 25125 125 5****525***25125**125

5****5 25***25 125**125

For the list {12, 15, 13, 20, 23, 27, 25, 36, 40}, how many elements will be compared to find 25 using linear search? 3 7 6 2

7

The _____ operator is used to inherit one class from another. : -> :: .

:

Which of these is a dynamically allocated array? An array whose address can change during compile time. An array whose size can change during runtime. An array whose size can change during compile time. An array whose address can change during runtime.

An array whose size can change during runtime.

What is output? #include <iostream>using namespace std;class HomeAppliances {public:void SetDetails(string name, string use) {appName = name;appUse = use;};void PrintDetails() {cout << "Appliance Name: " << appName << endl;cout << "Appliance Use: " << appUse << endl;};protected:string appName;string appUse;};class MixerGrinder : public HomeAppliances {public:void SetPrice(double price) {appPrice = price;};void PrintDetails () {cout << "Appliance Name: " << appName << endl;cout << "Appliance Price: $" << appPrice << endl;};private:double appPrice;};int main() {MixerGrinder mxCompany;mxCompany.SetDetails("MyMixer", "Grind objects");mxCompany.SetPrice(145.50);mxCompany.PrintDetails();return 0;} Appliance Use: Grind objectsAppliance Price: $145.5 Appliance Name: MyMixerAppliance Use: Grind objects Appliance Name: MyMixerAppliance Use: Grind objectsAppliance Price: $145.5 Appliance Name: MyMixerAppliance Price: $145.5

Appliance Name: MyMixerAppliance Price: $145.5

To search for 10 in the array, the first function call is BSearch(arr, 0, 4, 10), what is the second function call? #include <iostream>using namespace std;int BSearch(int arr[], int lowVal, int highVal, int num) { if (highVal >= lowVal) { int mid = lowVal + (highVal - lowVal) / 2; if (arr[mid] == num) return mid; if (arr[mid] > num) return BSearch(arr, lowVal, mid - 1, num); elsereturn BSearch(arr, mid + 1, highVal, num); } return -1; }int main() {int arr[] = { 2, 3, 4, 10, 40}; int n = 5; int num = 10;int result = BSearch(arr, 0, n - 1, num); if(result == -1) {cout << "Element is not present in array"; }else { cout << "Element is present at index " << result; }return 0; } BSearch(arr, 0, 1, 10) BSearch(arr, 3, 4, 10) BSearch(arr, 2, 4, 10) BSearch(arr, 0, 2, 10)

BSearch(arr, 3, 4, 10)

Which of the following is true if a programmer has to create a class with the following data members and functions? class Clinic {int patientRecNum;string patientName;void Set Details(int num, string name);Clinic GetDetails();}; Data members should be private items and function declarations should be public items. The function SetDetails should be a public item and all other members should be private items. The data member patientName should be a private item and all other members should be public items. Data members should be public items and function declarations should be private items.

Data members should be private items and function declarations should be public items.

Which of the following statements is about destructors? Destructors are used to reallocate the memory that has been allocated for the object. Destructors have parameters and a return value. Destructors are declared using the '&' symbol. Destructors are used to deallocate the memory that has been allocated for the object.

Destructors are used to deallocate the memory that has been allocated for the object.

Identify the error in the recursive function that finds the sum of the digits. int digitSum(int number) {static int sum = 0;if(number >= 0) {sum += (number % 10);digitSum(number / 10);}else {return sum;} } There is no base case, and hence the recursive calls do not come out of the function. There is no recursive case, and hence the function is not recursive. Error: Incorrect base case condition. The recursive calls do not reach the base case leading to infinite recursion. Error: Incorrect base case condition. The recursive calls straight away go to the base case leading to no recursion.

Error: Incorrect base case condition. The recursive calls do not reach the base case leading to infinite recursion.

What is output? #include <iostream>#include <utility>using namespace std;int main() {pair<string, int> playerName;captainName = make_pair("Roy", 10);cout << captainName.first;return 0;} 10 Error: Variable not declared in this scope. Error: Operator mismatch. Roy

Error: Variable not declared in this scope.

What error does the following code generate? #include <iostream>#include <queue>#include <map>#include <string>using namespace std;int main () {queue<double>joyTime;int yourNum = 0;joyTime.push(1);joyTime.clear();joyTime.push(2);joyTime.push(3);joyTime.pop();joyTime.push(4);yourNum = joyTime.back() + joyTime.front();cout << yourNum;return 0;} Error: yourNum is calculated incorrectly No error Error: no member named 'clear' Error: queue declared incorrectly

Error: no member named 'clear'

The codes for classhas been defined in two separate files Hotel.h, and Hotel.cpp. Which of the following statements is true? Hotel.cpp contains member function definitions and includes Hotel.h. Hotel.h contains the class definition with only data members. Hotel.h contains the class and member function definitions. Hotel.cpp contains the class definition with data members and function declarations.

Hotel.cpp contains member function definitions and includes Hotel.h.

Which statement is true for the find(iteratorBegin, iteratorEnd, item) function? iteratorEnd is the iterator to the range's last element. If the item is not found in the range of elements, then the find() will return iteratorEnd. If the item is not found in the range of elements, then find() returns iteratorBegin. Both iteratorBegin's and iteratorEnd's elements are checked by this function.

If the item is not found in the range of elements, then the find() will return iteratorEnd.

Which of the following statements is not true for stack overflow? A stack overflow leads to a segmentation fault. A stack overflow is caused due to deep recursion. A stack overflow occurs when the stack frame for a function call extends past the end of the stack's memory. Large vectors, arrays, or strings declared as local variables, or passed by copy, cannot lead to stack overflow.

Large vectors, arrays, or strings declared as local variables, or passed by copy, cannot lead to stack overflow.

Which is the correct syntax for the class's functions defined outside the class declaration? Larger<varType> largeFunc(); Larger varType largeFunc(); Larger varType : largeFunc(); Larger<varType> :: largeFunc();

Larger<varType> :: largeFunc();

During the merge sort operation for the list [90, 7, 9, 43, 62, 12, 21, 36], at what left and right partition position is 21 added to the temporary list? Left position is 1 and right position is 7 Left position is 4 and right position is 7 Left position is 2 and right position is 5 Left position is 2 and right position is 6

NOT Left position is 4 and right position is 7

Which of the following statements is true for the following code? class MyParent {...}class MyChild : protected MyParent {...} Public, private, and protected members of MyParent are accessible as protected members of MyChild. Public, private, and protected members of MyParent are accessible as public members of MyChild. Public and protected members of MyParent are accessible as protected members of MyChild. Public and protected members of MyParent are accessible as public members of MyChild.

Public and protected members of MyParent are accessible as protected members of MyChild.

Which is not true of Quicksort? Quicksort chooses a pivot to divide the data into low and high parts. Quicksort divides the array into two parts to partition the input. Quicksort chooses a midpoint to divide the data into low and high parts. Quicksort repeatedly partitions the input into low and high parts (each part unsorted).

Quicksort chooses a midpoint to divide the data into low and high parts.

Which statement defines the character search function strrchr()? Returns the position to the first occurrence of the character. Returns a pointer to the last occurrence of the character. Returns the position of the last occurrence of the character. Returns a pointer to the first occurrence of the character.

Returns a pointer to the last occurrence of the character.

For the list {Allen, Barry, Christopher, Daisy, Garry, Sandy, Zac}, what is the second name searched when the list is searched for Garry using binary search? Sandy Barry Christopher Garry

Sandy

What does a compiler do when a function template small is called in the main function of a program? #include <iostream>#include <string>using namespace std;template<typename MyType>MyType small(MyType var1, MyType var2) {if (var1 > var2) {return var1; }else {return var2;}}int main() {int num1 = 4;int num2 = 6;char cr1 = 'g';char cr2 = 'd';double nu1 = 5.6;double nu2 = 6.5;cout << small(num1,num2) << ' ';cout << small(cr1,cr2) << ' ';cout << small(nu1,nu2) << ' ';return 0;} The programmer manually generates a unique function definition for each data type appearing in function calls to the function template. The compiler automatically generates a different function definition only for the first data type appearing in function calls to the function template. The compiler automatically generates a unique function definition for each data type appearing in function calls to the function template. The programmer manually generates a different function definition only for the first data type appearing in function calls to the function template.

The compiler automatically generates a unique function definition for each data type appearing in function calls to the function template.

What is output? #include <iostream>using namespace std;class Players {public:string name;void callPlayer(Players* ptr) {cout << "This player is called at runtime - " << ptr->name << endl;}void callPlayer(string playerName) {cout << "Calling player " << playerName << endl;}void callPlayer() {cout << "No player to call!" << endl;}};int main() {Players* playerPtr = new Players();Players newPlayer;playerPtr->name = "Tim";newPlayer.callPlayer(playerPtr);return 0;} No player to call! Calling player Tim Error: runtime error This player is called at runtime - Tim

This player is called at runtime - Tim

Which of the following statements is the correct replacement for member initialization in the following code? class Toys {public:Toys();void Print();private:int toyID;string desc;};Toys::Toys() {toyID = 1;desc = "New Toy";} Toy::Toy() : toyID(1), desc("New Toy") { } Toy::Toy() :: toyID(1), desc("New Toy") { } Toy::Toy() :: toyID = 1, desc = "New Toy" { } Toy::Toy() : toyID = 1, desc = "New Toy" { }

Toy::Toy() : toyID(1), desc("New Toy") { }

What is output? #include <iostream>#include <stdexcept>using namespace std;int main() {int value = 2;try {if(value == 1)throw 2; else if(value == 2)throw '2'; else if(value == 3)throw 2.0; }catch(int a) {cout << "\n Variable type 1 exception caught.";}catch(char ch) {cout << "\nVariable type 2 exception caught.";}catch(double d) {cout << "\nVariable type 3 exception caught.";}cout << "\nEnd of program.";} Variable type 1 exception caught.End of program. Variable type 2 exception caught.End of program. Variable type 3 exception caught.End of program. End of program.

Variable type 2 exception caught.End of program.

Given the list [23, 6, 19, 92], i = 0, and k = 3, what are the contents of the low partition? Assume quicksort always chooses the smallest element as the pivot. [19, 23, 92] [19, 92] [6] [23].

[6]

UML uses italics to denote ___ classes. derived built-in abstract base

abstract

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

auto currentScore : scoreTable

Which XXX is used to declared member function and return the variable value? class Bill {public:void SetProduct(string prodName);void SetAmount(int prodAmount);XXXprivate:string name;double amount;}; int main() {Bill myBill;cout << myBill.GetAmount();} double Bill::GetAmount(); void GetAmount(); void Bill::GetAmount(); double GetAmount();

double GetAmount();

A recursive function _____. combines data members and functions in a single unit repeatedly calls other member functions of the same class repeatedly calls the main function either calls itself or is in a potential cycle of function calls

either calls itself or is in a potential cycle of function calls

The ____ function returns true if the previous stream operation had an error. fail() eof() bad() close()

fail()

The eof() function of input streams returns _____. false when the end of the file has been reached false when the end of the file has not been reached true when at the start of the file true when the end of the file has not been reached

false when the end of the file has not been reached

Which XXX completes the recursive scrambling function and generates the following output: ABC ACB BAC BCA CBA CAB ? #include <iostream> using namespace std; void Swap(char & v1, char & v2) {char temp;temp = v1;v1 = v2;v2 = temp;}void Scramble(string sstr, int start, int end) { char temp;if (start == end) cout << sstr << endl; else { XXX } } int main() { string sstring = "ABC"; int n = sstring.size(); Scramble(sstring, 0, n - 1); return 0; } for (int i = start; i <= end; i++) { Swap(sstr[start],sstr[i]);Scramble(sstr, start - 1, end);Swap(sstr[start],sstr[i]);} for (int i = start; i <= end; i++) { Swap(sstr[start],sstr[i]);Scramble(sstr, start + 1, end);Swap(sstr[start],sstr[i]);} for (int i = start; i <= end; i++) { Swap(sstr[start],sstr[i]);Scramble(sstr, end, start + 1);Swap(sstr[start],sstr[i]);} for (int i = start; i <= end; i++) { Swap(sstr[start],sstr[i]);Scramble(sstr, end, start - 1);Swap(sstr[start],sstr[i]);}

for (int i = start; i <= end; i++) { Swap(sstr[start],sstr[i]);Scramble(sstr, start + 1, end);Swap(sstr[start],sstr[i]);}

The code below gives all the combinations of the meals in a restaurant along with their respective prices. Which XXX completes the recursive function to identify all the combinations? #include <iostream>#include <string>#include <vector>using namespace std;class Item {public:string foodName; int priceDollars;};const unsigned int MAX_ITEMS = 2;void MealCombinations(vector<Item> currCombo, vector<Item> remainingMenu) { int mealValue; Item tmpMenuItem;unsigned int i; if( currCombo.size() == MAX_ITEMS ) { mealValue = 0;for(i = 0; i < currCombo.size(); ++i) {mealValue += currCombo.at(i).priceDollars;cout << currCombo.at(i).foodName << " ";}cout << "= $" << mealValue << endl;}else { XXX}}int main() {vector<Item> possibleItems(0);vector<Item> mealCombo(0);Item tmpMenuItem;tmpMenuItem.foodName = "Burger";tmpMenuItem.priceDollars = 10;possibleItems.push_back(tmpMenuItem);tmpMenuItem.foodName = "Pizza";tmpMenuItem.priceDollars = 20;possibleItems.push_back(tmpMenuItem);tmpMenuItem.foodName = "Soda";tmpMenuItem.priceDollars = 5;possibleItems.push_back(tmpMenuItem);MealCombinations(mealCombo, possibleItems);return 0;} for(i = 0; i < remainingMenu.size(); ++i) { tmpMenuItem = remainingMenu.at(i);remainingMenu.erase(remainingMenu.begin() + i);currCombo.push_back(tmpMenuItem);MealCombinations(currCombo, remainingMenu);remainingMenu.insert(remainingMenu.begin() + i,tmpMenuItem);currCombo.pop_back();} for(i = 0; i < remainingMenu; ++i) { tmpMenuItem = remainingMenu.at(i);remainingMenu.erase(remainingMenu.begin() + i);currCombo.push_back(tmpMenuItem);MealCombinations(currCombo, remainingMenu);remainingMenu.insert(remainingMenu.begin() + i,tmpMenuItem);currCombo.pop_back();} for(i = 0; i < remainingMenu.size(); ++i) { tmpMenuItem = remainingMenu.at(i);remainingMenu.erase(remainingMenu.begin() - i);currCombo.push_back(tmpMenuItem);MealCombinations(currCombo, remainingMenu);remainingMenu.insert(remainingMenu.begin() - i,tmpMenuItem);currCombo.pop_back();} for(i = 0; i < remainingMenu.size(); ++i) { tmpMenuItem = remainingMenu.at(i);remainingMenu.erase(remainingMenu.begin() + i);currCombo.push_back(tmpMenuItem);MealCombinations(remainingMenu, currCombo);remainingMenu.insert(remainingMenu.begin() + i,tmpMenuItem);currCombo.pop_back();}

for(i = 0; i < remainingMenu.size(); ++i) { tmpMenuItem = remainingMenu.at(i);remainingMenu.erase(remainingMenu.begin() + i);currCombo.push_back(tmpMenuItem);MealCombinations(currCombo, remainingMenu);remainingMenu.insert(remainingMenu.begin() + i,tmpMenuItem);currCombo.pop_back();}

The _____ function reads an input line into a string. getchar(); getline(); clear(); str()

getline();

Which type of relationship is depicted in the following code? class Student {public:string name;int age;int grade;};class Teacher {public:string name;int experience;string forGrades;};class School {vector<Student> students;vector<Teacher> teachers;}; Of-a Kind-of Has-a Is-a

has-a

Which of the following is not an exception-handling construct? try throw keep catch

keep

When a class derives the properties of the base class, the concept is called _____. streaming overlapping inheritance branching

inheritance

Which XXX is used to read and store the data into the variable from the file that is opened by the stream inputFile? #include <iostream>#include <fstream>using namespace std; int main() {ifstream inputFile;int numberPlayers;inputFile.open("playerNumber.txt");if (!inputFile.is_open()) {cout << "Could not open file numFile.txt." << endl;return 1;}XXXcout << "Players Number: " << numberPlayers;return 0;} inputFile >> numberPlayers; inputFile << numberPlayers; inputFile = numberPlayers; inputFile -> numberPlayers;

inputFile >> numberPlayers;

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 << "F_" << N << " is " << Fibo(N) << endl;return 0;} int Fibo(int N) {if(N == 1)return 0;else if(N == 2)return Fibo(1);elsereturn Fibo(N - 1)+Fibo(N - 2); } int Fibo(int N) {if(N == 1){return 0;}else if(N == 2){return 1; }else{return Fibo(N)+Fibo(N - 1); }} int Fibo(int N) {if(N == 1)return Fibo(N - 1);else if(N == 2)return Fibo(N - 2); elsereturn 0; } int Fibo(int N) {if(N == 1)return 0;else if(N == 2)return 1; elsereturn Fibo(N - 1)+Fibo(N - 2); }

int Fibo(int N) { if(N == 1) return 0; else if(N == 2) return 1; else return Fibo(N - 1)+Fibo(N - 2); }

Manipulators are defined in the _____ and _____ libraries in namespace std. iomanip; ios iomanip; iostream istream; iomanip iostream; istream

iomanip; ios

Which XXX (string stream) returns as the output? #include <iostream>#include <sstream>#include <string>using namespace std; int main() {string userInfo = "John Denver ";XXXstring firstName;string lastName;inSS >> firstName;inSS >> lastName;cout << "Hello " << firstName << " " << lastName << endl;return 0;} ostringstreamuserInfo; inSS(userInfo); ostringstreaminSS(userInfo); istringstream inSS(userInfo);

istringstream inSS(userInfo);

What XXX will generate the following output? Enter a value: 0 was not found. #include <iostream>using namespace std;int BinarySearch(int list[], int listSize, int key) {int mid;int low;int high;low = 0;high = listSize - 1;while (high >= low) {mid = (high + low) / 2;if (list[mid] < key) {low = mid + 1; } else if (list[mid] > key) {high = mid - 1; }else {return XXX; }}return -1; }int main() {int list[] = { 2, 4, 7, 10, 11, 32, 45, 87 };const int LIST_SIZE = 8;int i;int key;int keyIndex;cout << "Enter a value: ";cin >> key;keyIndex = BinarySearch(list, LIST_SIZE, key);if (keyIndex == -1) {cout << key << " was not found." << endl;}else {cout << "Found " << key << " at index " << keyIndex << "." << endl;}return 0;} high -1 mid low

mid

What is output? int main() {unsigned int i;vector<int> Xvector;Xvector.push_back(1);Xvector.push_back(2);Xvector.clear();for (i = 0; i < Xvector.size(); ++i)cout << ' ' << Xvector.at(i);return 0;} Runtime error Compiler error ' ' it No output

no output?

Which function has been overridden in the following code snippet? class Games {public:void GameName(string name);protected: void SetNames();string names;private:string type;void GameCategories();};class VideoGames : public Games {public:string PrintNames();void GetName();protected: void SetNames();void GameCategory();};int main() {...} SetNames() PrintNames() GameCategories() GameName()

not GameCategories()

To partition the input, quicksort chooses a _____ to divide the data into low and high parts. midpoint partition table pivot

pivot

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

protected

The _____ function adds an element to the back end of a list and the _____ function adds an element to the beginning of the list. pop_back(), pop_front() back(), front() push_back(), push_front() erase(), insert()

push_back(), push_front()

Which type of polymorphism is depicted in the following code? void PlayerName(string Coach) {cout << "In the team since " << Coach << endl;}void PlayerName(Coach Coach) {cout << "In the team since " << Coach.GetDetails() << endl;}void PlayerName(Players* playerPtr) {cout << "In the team since " << playerPtr->GetDetails() << endl;}int main() {vector<Players*> memberList;Players* playerPtr;Coach* coachPtr;memberList.push_back(playerPtr);memberList.push_back(coachPtr);for (int i = 0; i < memberList.size(); ++i) {PlayerName(memberList.at(i));}} Compile-time No polymorphism Static Runtime

runtime


Ensembles d'études connexes

Definiciones de términos médicos: el cuerpo humano

View Set

Sutures, Bones, and Processes of the Skull

View Set

PSY 108 midterm #2 (cognitive psychology) readings

View Set

Chapter 21: The Newborn at Risk: Congenital Disorders

View Set

Biology - Plants and photosynthesis

View Set

Chapter 4: The Empire in Transition

View Set