M2_Ch13HomeworkQuestions(1)

docx

School

Harvard University *

*We aren’t endorsed by this school

Course

161

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

1

Uploaded by HighnessBatMaster978

Report
CSC161 Chapter 13 Homework Questions 1. Consider the definition of the class dateType given in Chapter 11. a. Write the statement that includes a friend function named before in the class dateType that takes as parameters two objects of type dateType and returns true if the date represented by the first object comes before the date represented by the second object; otherwise, the function returns false. friend bool before(dataType &date1, dataType &date2); b. Write the definition of the function you defined in part a. 2. Consider the following declaration: class strange { . . . }; a. Write a statement that shows the declaration in the class strange to overload the operator >>. friend istream& operator>>(istream&, strange&); b. Write a statement that shows the declaration in the class strange to overload the operator =. const strange& operator=(const strange&); c. Write a statement that shows the declaration in the class strange to overload the binary operator + as a member function. strange operator+(const strange&) const; d. Write a statement that shows the declaration in the class strange to overload the operator == as a member function. bool operator==(const strange&) const; e. Write a statement that shows the declaration in the class strange to overload the post-increment operator ++ as a member function. strange operator++(int); 3. In a class, a. In a class, why do you include the function that overloads the stream insertion operator, <<, as a friend function? Because a class is p rivate by default and in order to extract data we have to do it through a friend function. b. In a class, why do you include the function that overloads the stream extraction operator, >>, as a friend function? Because a class is private by default and in order to insert data we have to do it through a friend function. 4. What type of value should be returned by a function that overloads a relational operator? Boolean 5. How many parameters are required to overload the post-increment operator for a class as a friend function? 2
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help