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.
#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;
}
Comments
Leave a comment