Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 14

In a class, why do you include the function that overloads the stream extraction operator, \(>>,\) as a friend function?

Problem 17

What is the purpose of a dummy parameter in a function that overloads the post-increment or post-decrement operator for a class?

Problem 19

How many parameters are required to overload the pre-increment operator for a class as a member function?

Problem 20

How many parameters are required to overload the pre-increment operator for a class as a member function?

Problem 21

How many parameters are required to overload the pre-increment operator for a class as a friend function?

Problem 22

How many parameters are required to overload the post-increment operator for a class as a friend function?

Problem 25

Find the error(s) in the following code: template //Line 1 class strange //Line 2 { . . . }; strange s1; //Line 3 strange s2; //Line 4

Problem 26

Consider the following declaration: template class strange { . . . private: type a; type b; }; a. Write a statement that declares sObj to be an object of type strange such that the private member variables a and b are of type int. b. Write a statement that shows the declaration in the class strange to overload the operator == as a member function. c. Assume that two objects of type strange are equal if their corresponding member variables are equal. Write the definition of the function operator== for the class strange, which is overloaded as a member function.

Problem 27

Consider the definition of the following function template: template Type surprise(Type x, Type y) { return x + y; } What is the output of the following statements? a. cout << surprise(5, 7) << endl; b. string str1 = "Sunny"; string str2 = " Day"; cout << surprise(str1, str2) << endl;

Problem 28

Consider the definition of the following function template: template Type funcExp(Type list[], int size) { int j; Type x = list[0]; Type y = list[size - 1]; for (j = 1; j < (size - 1)/2; j++) { if (x < list[j]) x = list[j]; if (y > list[size – 1 – j]) y = list[size – 1 – j]; } return x + y; } Further suppose that you have the following declarations: int list[10] = {5, 3, 2, 10, 4, 19, 45, 13, 61, 11}; string strList[] = {"One", "Hello", "Four", "Three", "How", "Six"}; What is the output of the following statements? a. cout << funExp(list, 10); b. cout << funExp(strList, 6) << endl;

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks