<< Create and Implement program in C++ to define 2 classes. Addition, subtraction, division, average, power and multiplication of 2 variables must be performed using functions. >> "With Separate Function of {Addition, subtraction, division, average, Multiplication,Power }
#include <iostream>
using namespace std;
class Two;
class One{int a,b;
public:
friend class Two;
void multi (){
cout<< "The Multiply of two no is :" <<a*b<<endl;}
void sub(){
cout<< "The subtraction of two no is :" <<a-b<<endl;}
void sum(){
cout<< "The sum of two no is :" <<a+b<<endl;}
void div(){
cout<< "The division of two no is :" <<a/b<<endl;}void avg(){
cout<< "The Average of two no is :" <<(a+b)/2<<endl;}};
class Two{
int n;
int power;
float base_no;
int res = 1;
public:
friend class One;
using namespace std;
class Two;
class One{int a,b;
public:
friend class Two;
void multi (){
cout<< "The Multiply of two no is :" <<a*b<<endl;}
void sub(){
cout<< "The subtraction of two no is :" <<a-b<<endl;}
void sum(){
cout<< "The sum of two no is :" <<a+b<<endl;}
void div(){
cout<< "The division of two no is :" <<a/b<<endl;}void avg(){
cout<< "The Average of two no is :" <<(a+b)/2<<endl;}};
class Two{
int n;
int power;
float base_no;
int res = 1;
public:
friend class One;
void power1(){
cout << " \t<< Enter Number >>: "<<endl;
cin >> base_no ;
cout << " \t<< Enter power >>: "<<endl;
cin >> power;
cout << base_no << "^" << power << " : ";
while (power != 0) {
res *= base_no;
--power; }
cout << res;}
void cal (One o1) {
int res = 1;
cout << "Enter the two number :" <<endl;
cin>>o1.a>>o1.b;
cout << "Enter Choise \nfor Multiply (*) press 5:\t\nFor subtraction press 4:\t\n For Addition press 3:\t\n For Division press 2:\nFor Average (avg)press 1:\nFor Find Power press 0:" <<endl;
cin>>n;
switch (n)
{case 5:{ o1.multi ();break; }
case 4:{o1.sub(); break; }
case 3:{o1.sum() ; break;}
case 2:{ o1. div(); break; }
case 1:{o1.avg() ; break; }
case 0:{power1() ; break; }
default :{ cout<< "Error Wrong Choice " <<endl; }}}};
int main(){
int n,s;
One obj1;
Two obj2;
obj2.cal(obj1);
cout<< "\n<<\tDo you want to Run Again..!\t>> \n then press 1 \nFor Exit press 0 :" <<endl;
cin>>n;
if (n==1){cout<< "\nHow many time to run calculator function:" <<endl;
cin>>s;
for(int i=0;i<s;i++){
obj2.cal(obj1);}}
else {return 0;}
return 0;}
cin >> base_no ;
cout << " \t<< Enter power >>: "<<endl;
cin >> power;
cout << base_no << "^" << power << " : ";
while (power != 0) {
res *= base_no;
--power; }
cout << res;}
void cal (One o1) {
int res = 1;
cout << "Enter the two number :" <<endl;
cin>>o1.a>>o1.b;
cout << "Enter Choise \nfor Multiply (*) press 5:\t\nFor subtraction press 4:\t\n For Addition press 3:\t\n For Division press 2:\nFor Average (avg)press 1:\nFor Find Power press 0:" <<endl;
cin>>n;
switch (n)
{case 5:{ o1.multi ();break; }
case 4:{o1.sub(); break; }
case 3:{o1.sum() ; break;}
case 2:{ o1. div(); break; }
case 1:{o1.avg() ; break; }
case 0:{power1() ; break; }
default :{ cout<< "Error Wrong Choice " <<endl; }}}};
int main(){
int n,s;
One obj1;
Two obj2;
obj2.cal(obj1);
cout<< "\n<<\tDo you want to Run Again..!\t>> \n then press 1 \nFor Exit press 0 :" <<endl;
cin>>n;
if (n==1){cout<< "\nHow many time to run calculator function:" <<endl;
cin>>s;
for(int i=0;i<s;i++){
obj2.cal(obj1);}}
else {return 0;}
return 0;}
Output:
Comments
Post a Comment