Write c++ program to create a menu driven program contains addition,subtraction,division, multiplication, remainder functions

//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;

#include<conio>
#include<iostream>

class calculator
{
   public:
   void addition();
   void subtraction();
   void division();
   void multiplication();
   void remainder();
};
int main()
{
int n;
calculator problem; // object created
   do{

      cout<<"1.addition"<<endl;
      cout<<"2.substraction"<<endl;
      cout<<"3.division"<<endl;
      cout<<"4.multiplication"<<endl;
      cout<<"5.remainder"<<endl;
      cout<<"6.exit.";
      cout<<"\nchoose a number:";
      cin>>n;
      cout<<endl;
      switch(n)
      {
    case 1:
        problem.addition();      break;
  case 2:
        problem.subtraction();  break;
case 3:
        problem.division();      break;
  case 4:
        problem.multiplication();break;
       case 5:
        problem.remainder();     break;
      }
   } while(n!=6);
 return(0);
}
void calculator::addition()
{
int a,b;
    cout<<"Enter 1st number:";
    cin>>a;
    cout<<endl;
    cout<<"Enter 2nd number:";
    cin>>b;
    cout<<"\nAddition of 2 number is: "<<a+b<<endl;

}
void calculator::subtraction()
{
int a,b;
      cout<<"Enter 1st number:";
    cin>>a;
    cout<<endl;
    cout<<"Enter 2nd number:";
    cin>>b;
    cout<<"\nSubstraction of 2 number is: "<<a-b<<endl;

}
void calculator::division()
{
      int a,b;
      cout<<"Enter 1st number:";
    cin>>a;
    cout<<endl;
    cout<<"Enter 2nd number:";
    cin>>b;
    cout<<"\nDivision of 2 number is: "<<a/b<<endl;

}
void calculator::multiplication()
{
     int a,b;
      cout<<"Enter 1st number:";
    cin>>a;
    cout<<endl;
    cout<<"Enter 2nd number:";
    cin>>b;
    cout<<"multiplication of 2 number is: "<<a*b<<endl;

}
void calculator::remainder()
{
      int a,b;
      cout<<"Enter 1st number:";
    cin>>a;
    cout<<endl;
    cout<<"Enter 2nd number:";
    cin>>b;
    cout<<"remainder of 2 number is: "<<a%b<<endl;

}

0 Comments