Answer to Question #224853 in C++ for Snr

Question #224853

Write a C++ program for the following specification: Create a class Fuzzy with two


data members: x of type integer and memx of type float. memx should range from 0 to 1. Implement the operator overloading for the operators: &, I and ~. i. Operator function for & should return the Fuzzy object with minimum memx, after checking the equality of data member x in both objects.


Sample Data:


f1 (10,0.5) f2= (10,0.2)


f1&f2= (10,0.2) ii. Operator function for should return the Fuzzy object with 1-memx..


Sample Data:


f2=(10,0.2) ~f2=(10,0.8)


Implement the appropriate member functions to get the input and print the output.


Note: In & operator overloading, if x is not equal, then return fuzzy object (0,0)


1
Expert's answer
2021-08-16T01:03:59-0400
#include <iostream>
using namespace std;
class Fuzzy
{
private:
	int x;
	float memx;
public:
	Fuzzy()
	{
		this->x = 0;
		this->memx = 0.0;
	}
	Fuzzy(int _x, float _mm)
	{
		this->x = _x;
		this->memx = _mm;
	}
	int getX()const
	{
		return this->x;
	}
	float getMemX()const
	{
		return this->memx;
	}
	void Display()
	{
		cout << "(" << this->getX() << "," << this->getMemX() << ")";
	}
	friend Fuzzy operator&(const Fuzzy& a, const Fuzzy& b);
	Fuzzy& operator~()
	{
		this->memx = 1 - this->memx;
		return *this;
	}
};
Fuzzy operator&(const Fuzzy& a, const Fuzzy& b)
{
	if (a.getX() == b.getX())
		return Fuzzy(a.getX(), min(a.getMemX(), b.getMemX()));
	else
			return Fuzzy();
}
int main()
{
	int _x;
	float mx;
	cout << "Please enter x data member first object Fuzzy: ";
	cin >> _x;
	cout << "Please enter memx data member first object Fuzzy:";
	cin >> mx;
	Fuzzy f1(_x, mx);
	cout << "Please enter x data member second object Fuzzy: ";
	cin >> _x;
	cout << "Please enter memx data member second object Fuzzy:";
	cin >> mx;
	Fuzzy f2(_x, mx);
	Fuzzy  fand;
	fand = f1 & f2;
	~f1;
	cout << "~f1= ";
	f1.Display();
	cout << endl;
	cout << "f1&f2=";
	fand.Display();
	cout << endl;
	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