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 1

Fill in the blanks in each of the following: a. Suppose a and b are integer variables and we form the sum a + b. Now suppose c and d are floating-point variables and we form the sum c + d. The two + operators here are clearly being used for different purposes. This is an example of __________. b. Keyword __________ introduces an overloaded-operator function definition. c. To use operators on class objects, they must be overloaded, with the exception of operators __________, __________ and __________. d. The __________, __________ and __________ of an operator cannot be changed by overloading the operator.

Problem 2

Explain the multiple meanings of the operators << and >> in C++.

Problem 3

In what context might the name operator/ be used in C++?

Problem 4

(True/False) In C++, only existing operators can be overloaded.

Problem 5

How does the precedence of an overloaded operator in C++ compare with the precedence of the original operator?

Problem 6

Give as many examples as you can of operator overloading implicit in C++. Give a reasonable example of a situation in which you might want to overload an operator explicitly in C++.

Problem 11

One nice example of overloading the function call operator () is to allow another form of double-array subscripting popular in some programming languages. Instead of saying chessBoard[ row ][ column ]for an array of objects, overload the function call operator to allow the alternate form chessBoard( row, column ) Create a class DoubleSubscriptedArray that has similar features to class Array in Figs. 11.611.7. At construction time, the class should be able to create an array of any number of rows and any number of columns. The class should supply operator() to perform double-subscripting operations. For example, in a 3-by-5 DoubleSubscriptedArray called a, the user could write a( 1, 3 ) to access the element at row 1 and column 3. Remember that operator() can receive any number of arguments (see class String in Figs. 11.911.10 for an example of operator()). The underlying representation of the double-subscripted array should be a single- subscripted array of integers with rows * columns number of elements. Function operator() should perform the proper pointer arithmetic to access each element of the array. There should be two versions of operator()one that returns int & (so that an element of a DoubleSubscriptedArray can be used as an lvalue) and one that returns const int & (so that an element of a const DoubleSubscriptedArray can be used only as an rvalue). The class should also provide the following operators: ==, !=, =, << (for outputting the array in row and column format) and >> (for inputting the entire array contents).

Problem 12

Overload the subscript operator to return the largest element of a collection, the second largest, the third largest, and so on.

Problem 15

Create a class RationalNumber (fractions) with the following capabilities: a. Create a constructor that prevents a 0 denominator in a fraction, reduces or simplifies fractions that are not in reduced form and avoids negative denominators. b. Overload the addition, subtraction, multiplication and division operators for this class. c. Overload the relational and equality operators for this class.

Problem 17

Develop class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent. The term has the coefficient 2 and the exponent \(4 .\) Develop a complete class containing proper constructor and destructor functions as well as set and get functions. The class should also provide the following overloaded operator capabilities: a. Overload the addition operator \((+)\) to add two Polynomiats. b. Overload the subtraction operator (.) to subtract two Polynomials. c. Overload the assignment operator to assign one Polynomial to another. d. Overload the multiplication operator (*) to multiply two Polynomials. e. Overload the addition assignment operator \((+=),\) subtraction assignment operator \((-=),\) and multiplication assignment operator \(\left(*_{=}\right)\)

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