Answer to Question #180840 in C++ for Deepanshi singh

Question #180840

Write a c++ program to define a class for calculater with data members 1&member2(both as double) and methods as add() ,sub() ,mil(), div() create a array of 5 objects of calculater use paramaterized constructor to intialize the value.display output of all four arthmetic operator.


1
Expert's answer
2021-04-13T16:10:35-0400
#include <iostream>


class Calculater
{
public:
	double add()
	{
		return members_1 + members_2;
	}
	double sub()
	{
		return members_1 - members_2;
	}
	double mil()
	{
		return members_1 * members_2;
	}
	double div()
	{
		return members_1 / members_2;
	}
	void value_display() 
	{
		std::cout << "Add: " << add() << std::endl;
		std::cout << "Sub: " << sub() << std::endl;
		std::cout << "Mul:" << mil() << std::endl;
		std::cout << "Div:" << div() << std::endl;
     }
	Calculater(double x,double y)
	{
		members_1 = x;
		members_2 = y;
	}
	Calculater() {}
	
private:
	double members_1{ 1 };
	double members_2{ 1 };
};


int main()
{
	//test work
	Calculater example[5] = { {10,15},{26,87},{102,58},{28,4.5},{0.25,-741} };
	example[2].value_display();
    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