Simple Calculator Program C++ Using Class With The Help Of Switch Case - HelpMeOutAlways

Thursday, October 4, 2018

Simple Calculator Program C++ Using Class With The Help Of Switch Case

Simple Calculator Program C++ Using Class by HelpMeOutAlways

Source Code

#include<iostream>

#include<conio.h>

using namespace std;

class math{


 public:

   void add(float a, float b)

 {

 cout<<"Enter any two value for add:"<<endl;

 cin>>a>>b; //geting input from user

 cout<<"Sum is : "<<a+b<<endl;//sum operation

}

    void sub(float a,float b){


 cout<<"Enter any two value sub:"<<endl;

    cin>>a>>b;

    cout<<"Subtraction is:"<<a-b<<endl;//sub operation

}


    void multply(float a, float b){

        cout<<"Enter any two value multly:"<<endl;

     cin>>a>>b;

        cout<<"Multiplication is :"<<a*b<<endl;//multly operation

}

   void divid(float a,float b){

    cout<<"Enter any two value for division:"<<endl; //Division operation

 cin>>a>>b;

 cout<<"Division is : "<<a/b<<endl;

}


};

//main function starts

int main(){

 math obj;

 float a,b;

 int menu;

 cout<<"Enter what operation you want(1-4);"<<endl;

 cout<<"1. Addition"<<endl;

 cout<<"2. Subtraction"<<endl;

 cout<<"3. Multiplication"<<endl;

 cout<<"4. Division"<<endl;

 cin>>menu;

 switch(menu){

  case 1:obj.add(a,b);break;

  case 2:obj.sub(a,b);break;

     case 3:obj.multply(a,b);break;

     case 4:obj.divid(a,b);break;

     default:{cout<<"Invalid input"<<endl;

     }

 }


  getche();


}

Output

Simple Program C++ by helpmeoutalways
I hope this source code Simple Calculator Program C++ Using Class helped you alot!

No comments:

@way2themes