Write the function for the following operations, using appropriate OOP concept such that the code is minimized.
Find product of two numbers
Find product of three numbers.
Find product of four numbers
#include<iostream>
using namespace std;
class Product{
public:
void product(int a, int b){
cout<<"The product of "<<a<<" and "<<b<<" is: "<<a * b<<endl;
}
void product(int a, int b, int c){
cout<<"The product of "<<a<<" , "<<b<<" and "<< c<< " is: "<<a * b * c<<endl;
}
void product(int a, int b, int c, int d){
cout<<"The product of "<<a<<" , "<<b<<", "<< c<< " and "<< d<<" is: "<<a * b * c * d<<endl;
}
};
int main(){
Product p;
p.product(3,7);
p.product(3,7,8);
p.product(9,10,45,78);
}
Comments
Leave a comment