which of the following operations are legal? If so, why? If not, why not? a) BaseAmount + 25;

We reproduce the class Money here, in part:
```
class Money
{
public:
Money( ); Money(int dollars, int cents);
Money(int dollars); Money(double amount); // other public members
const Money operator+(const MoneyADD& amt2)ADD;
>>Need to add & and semicolon
int getCents( ) const;
int getDollars( ) const;
private:
int dollars;
int cents;
//other private members
};
```

Note that * is not overloaded in the class, but operator + is overloaded using an operator function with the following declaration:
const Money operator+(const Money& amt2);
The question is: Given the declarations,
```
Money baseAmount(100, 60); // $100.60
Money fullAmount;
```
a) BaseAmount + 25;
b) 25 + BaseAmount;
c) baseAmount = 2 * baseAmount;
d) baseAmount+baseAmount.


All except c) are legal.

Part a) The compiler notes the left hand argument for + is a Money object, and the right hand object is an int. It looks for an operator overloading with a Money left hand argument. It finds the overloading with two Money parameters. So it then looks for a way to convert an int object to a Money object. It finds the Money(int) constructor, which it uses. Then it has the argument-parameter type match necessary to invoke the operator+(const Money&,const Money) overloaded operator.
Part b) The expression is illegal, because the compiler cannot find an overloaded operator function that takes an int as first argument and a Money object as second argument. The first argument is the calling object which must be of type Money for +.
Part c) is illegal, not because we couldn’t overload operator*, but because we did not. Part d) is a straightforward call: baseAmount.operator+(baseAmount)

Computer Science & Information Technology

You might also like to view...

In the accompanying figure, what effect has been applied to the "D" on the left?

A. Inner Bevel Chisel B. Smooth Emboss C. Chiseled Emboss D. Feather Emboss

Computer Science & Information Technology

A ________ is a collection of personal information, including photos, contact information, likes and dislikes, and recent posts for a member of a social networking site

A) status update B) pin C) profile D) post

Computer Science & Information Technology

When editing a PDF file in Word, a copy of the PDF file is converted into a Word document, and then placed into Word, so the original PDF file will remain intact

Indicate whether the statement is true or false

Computer Science & Information Technology

____________________ add signal delay that will cause the collision propagation time to exceed the allowable limit and reduce the pre-assigned interframe gap time in a 10Mbps network.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology