Computer Science, asked by julie37, 3 months ago

Create a Distance Class, having two attributes, Feet and Inches. Overload Unary Decrement operator to support following statements in main() :
1. --D;
2. D--;
3. D2=D--;
4. D2=--D;

Answers

Answered by Reshma9071
0

Answer:

4.D2=_ _D;

Explanation:

please make me as brainlist

Answered by yash2437
2

Explanation:

#include <iostream>

using namespace std;

class Check

{

private:

int i;

public:

Check(): i(0) { }

void operator ++()

{ ++i; }

void Display()

{ cout << "i=" << i << endl; }

};

int main()

{

Check obj;

// Displays the value of data member i for object obj

obj.Display();

// Invokes operator function void operator ++( )

++obj;

// Displays the value of data member i for object obj

obj.Display();

return 0;

}

Output

i=0

i=1

Initially when the object obj is declared, the value of data member i for object obj is 0 (constructor initializes i to 0).

When ++ operator is operated on obj, operator function void operator++( ) is invoked which increases the value of data member i to 1.

This program is not complete in the sense that, you cannot used code:

obj1 = ++obj;

It is because the return type of operator function in above program is void.

Here is the little modification of above program so that you can use code obj1 = ++obj.

Similar questions