Answer to Question #262745 in C++ for Yui

Question #262745

Write a program to overload unary (-) operator using

friend function


1
Expert's answer
2021-11-08T17:37:04-0500
#include <iostream>
class Invoice
{
public:
	Invoice() {};
	Invoice(double b, double a, double p) 
	{
		balance = b;
		arenda = a;
		pays = p;
	}
	friend void operator-(const Invoice &ip);
	double balance{ 0 };
	double arenda{ 0 };
	double pays{ 0 };
private:


};
void operator-(const Invoice& ip)
{
	if (ip.balance < 0) 
	{
	std::cout <<"balance: " << ip.balance << "\n";
    }
	if (ip.arenda < 0)
	{
		std::cout << "arenda: " << ip.arenda << "\n";
	}
	if (ip.pays < 0)
	{
		std::cout << "pays: " << ip.pays << "\n";
	}
}


int main()
{
	// A simple example of an overloaded unary operator - displays elements with a negative value
	Invoice first(12, -5, 65);
	-first;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS