Operator Overloading (Homework 11)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

If you do not overload an = operator for a class___________________.

C++ provides you with a built-in (default) version

Which of the following operators can be overloaded to be binary? a) > b) & c) ++ d) !

a) >

If you have correctly overloaded the * operator to multiply two members of the Furniture class, and you have declared two Furniture objects, aDesk, and a aChair, then which of the following is a legal expression? a) aChair.operator*(aDesk); b) aChair * aChair; c) aChair * aDesk; d) all of the above

a) aChair.operator*(aDesk);

The difference between the function prototypes for the overloaded prefix and postfix ++ for any class is the ___________.

argument list

Which of the following operators can be overloaded ? a) . b) & c) :: d) ?:

b) &

If you have correctly overloaded the * operator to multiply two members of the Furniture class, and you have declared two Furniture objects, aDesk, and aChair, then which of the following is a legal expression? a) Furniture * Furniture; b) aDesk * aChair; c) Furniture * aChair; d) All of the above

b) aDesk * aChair;

The Student class contains an overloaded addition operator which allows a number of credits to be added to a Student's totalCredits. The function header is Student Student::operator+(int newCredits). The = operator has not been overloaded. Which of the following is correct in a program that initializes a Student object named aStudent? a) aStudent = 3 + aStudent; b) aStudent = aStudent + 3; c) both are correct d) none are correct

b) aStudent = aStudent + 3;

The Shipment class holds information about a shipment, including its weight. An overloaded division operator divides a Shipment's totalWeight field by the number of packages in the Shipment to determine the average package weight. The function header is int Shipment::operator/(int packages). Which of the following statements is correct within the function? (circle all that apply) a) int numPackages = Shipment / packages; b) int numPackages = totalWeight / packages; c) int numPackages = packages.totalWeight / packages; d) int numPackages = packages.totalWeight / totalWeight;

b) int numPackages = totalWeight / packages;

Which of the following is true? a) You overload an operator by making the operator an argument to a method. b) You should overload every C++ operator for each new class you create c) Operators that are normally defined to be only unary must remain unary when you overload them

c) Operators that are normally defined to be only unary must remain unary when you overload them

An overloaded subtraction operator subtracts two Shipment objects from each other, returning an integer that represents the difference in their totalWeight variables. The subtraction operator works as expected, with the object to the right of the minus sign being subtracted from the object to the left. The function header is int Shipment::operator- (Shipment ship). Within the function, which of the following is correct? a) int difference = ship - totalWeight; b) int difference = totalWeight - ship; c) int difference = ship.totalWeight - totalWeight; d) int difference = totalWeight - ship.totalWeight;

d) int difference = totalWeight - ship.totalWeight;

To be able to add three or more objects in sequence, as in x + y + z, you must overload the + operator to __________________.

return an object of the same type as the arguments


संबंधित स्टडी सेट्स

Ap Gov Unit 2 Test: Chapter 4 and 5

View Set

Banking and Financial Institution (Reviewer)

View Set

Leviticus 24 - Flashcard MC questions - Ted Hildebrandt

View Set

Med. Surg Test #1 Study Questions

View Set

Electrical Power Industry Reform Act of 2001

View Set