CS Final

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

Which statement enables the use of a set within a program?

#include <set>

The _____ enables use of the pair class.

#include <utility>

Which XXX is the base case in the recursive function to find the factorial of a number, where n is the input of the function? int factorial(int n) { if XXX { return n * factorial(n - 1); } else { return 1; } }

(n > 0)

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

----Tim

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; }

14.5

Given a dequemyDQ is: 17 55 98, what remains in the deque after the function myDQ.pop_back() has been called?

17 55

What will be the output if the user enters1 -1 2 2? #include <iostream> #include <list> using namespace std; int main() { list<int>scoreTable; list<int>::iterator eachScore; int num; eachScore = scoreTable.begin(); scoreTable.push_back(2); scoreTable.push_back(4); scoreTable.push_back(1); scoreTable.insert(eachScore,1); for (int i = 0; i < 4; i++) { cin >> num; if(num == -1) { scoreTable.pop_back(); } if(num >= 0) { scoreTable.push_back(num); } } for (auto &currentScore :scoreTable) { cout << currentScore << " "; } return 0; }

2 4 1 1 2 2

If a list has 1024 elements and each comparison takes 2 µs, then what is the longest possible runtime for linear search on this list?

2048µs

If a list has 1024 elements and if each comparison takes 2 µs, then what is the longest possible runtime for binary search on this list?

22µs

How many comparisons are required in an array of 16 elements, if quicksort always chooses the largest element as a pivot. What is the depth of the recursion tree.

64, 15

If the list {29 18 45 7 16} is sorted in ascending order using selection sort, what will be the value of the 0th element after the first pass over the outer loop (i = 0)?

7

In which standard library of C++ is the runtime_error defined?

<stdexcept>

Which of these is a dynamically allocated array?

An array whose size can change during runtime.

Which line generates a compile-time error? why? #include <iostream> using namespace std; class Computers { protected: string brand; int RAM; public: virtual void PrintInfo() = 0; }; class Laptops : public Computers { private: int batteryLife; public: void PrintInfo() { ... } }; class Desktops : public Computers { private: string accessories; public: void PrintInfo() { ... } }; int main() { Laptops laptop1; Computers comp1; laptop1.PrintInfo(); }

Computers comp1 generates an error as Computers is an abstract class and cannot be instantiated.

What is output? #include <iostream> #include <list> using namespace std; int main() { list<string>playerNames; playerNames.push_front("Mike"); playerNames.push_back("Bob"); playerNames.push_front("John"); playerNames.push_back("Miller"); cout << playerNames.front() << ', '; cout << playerNames.back() << ', '; playerNames.pop_front(); playerNames.pop_back(); cout << playerNames.back() << ', '; cout << playerNames.front() << ', '; return 0; }

John, Miller, Bob, Mike

Which of the following statements is not true for 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();

In the following code, the fourth element of the vector after using the sort function sort(petNames.begin(), petNames.end()) is _____. vector<string> petNames; petNames.push_back("Bella"); petNames.push_back("Lucy"); petNames.push_back("Luna"); petNames.push_back("Lola"); petNames.push_back("Lolla"); petNames.push_back("Bailey");

Lolla

Programmers often use a powerful programming paradigm that consists of three key features — classes, inheritance, and abstract classes. What is the paradigm called?

Object-oriented programming

Which of the following statements is true for the following code? class MyParent { ... } class MyChild : protected MyParent { ... }

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

Choose the correct syntax for calling the constructor with arguments. class Sample { public: Sample(double xValue = 0, double yValue = 0); void Print(); double X; double Y; }; void Sample::Print() { cout << "(" << X << ", "; cout << Y << ")" << endl; }

Sample* point2 = new Sample(8, 9);

_____ sort is a sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly picks the proper next value to move from the unsorted part to the end of the sorted part.

Selection

What does a compiler do when a function template small is called in the main function of a program? #include #include using namespace std; template 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 compiler automatically generates a unique function definition for each data type appearing in function calls to the function template.

Which of the following statements is true about the member access operator (->)?

The member access operator is always a non-static member function.

Which keyword can be used instead of class? template T someFunction(T arg) { ... .. ... }

Typename

Which XXX (string stream) returnsHello John Denveras the output? #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; }

istringstream inSS(userInfo);

What XXX will generate 1 3 5 7 8 9 as the output? #include <iostream> using namespace std; void selectSort(int numbers[], int numSize) { int i; int j; int indx; int temp; for (i = 0; i < XXX; ++i) { indx = i; for (j = i + 1; j < numSize; ++j) { if ( numbers[j] < numbers[indx] ) { indx = j; } } temp = numbers[i]; numbers[i] = numbers[indx]; numbers[indx] = temp; } } int main() { int numbers[] = {9,5,7,3,1,8}; const int N_SIZE = 6; int i; selectSort(numbers,N_SIZE); for (i = 0; i < N_SIZE; ++i) cout << numbers[i] << ' '; cout << endl; return 0; }

numSize-1

A queue's _____ function adds an element to the tail of the queue and a queue's _____ function removes the element at the head of the queue.

push(), pop()

The _____ class defines a container of ordered elements that supports element insertion at the tail and element retrieval from the head.

queue

Heap is a region in program memory where _____.

the "new" operator allocates memory

Which XXX will generate a valid output? #include <iostream> #include <stdexcept> using namespace std; int GetDay() { int inDay; cout << "Enter Day: "; cin >> inDay; if (1 > inDay || inDay > 31) { XXX; } return inDay; } int main() { int userDay; int userMonth; try { userDay = GetDay(); cout << "Valid Date: " << userDay << endl; } catch (runtime_error &excpt) { cout << excpt.what() << endl; } return 0; }

throw runtime_error("Invalid Day.")

Which XXX would make the class People an abstract class? class People { protected: string name; int age; public: XXX }; class Teacher : public People { private: int experience; public: void PrintInfo(); }; class Student : public People { private: int grade; public: void PrintInfo(); };

virtual void PrintInfo() = 0;

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 3 7 18 9}


Set pelajaran terkait

chapter 8-9 insuring your life and health

View Set

522 Section 3: Long-Term Care Insurance

View Set

Methods of Resistance Training and Conditioning

View Set

Sociology Chapter 1: Introduction to Sociology

View Set

Module G Practice & Review Questions

View Set

marketing ch 9 learnsmart market segment targeting and positioning,

View Set