Question

In: Computer Science

Code in C++ programming language description about lesson Calculator (multiple, sum, dived, sub) example.

Code in C++ programming language description about lesson Calculator (multiple, sum, dived,  sub) example.

Solutions

Expert Solution

#include

#include

 

using namespace std;

 

class numbers {

  protected:

  float x,y;

  public:

  numbers(float xx=0.0,float yy=0.0)

  :x(xx),y(yy) {

  }

/*void printxy(){

   cout <<"x=" << x<<",y=" << y <

  }*/

};

class OP : 

protected numbers 

{ // int x,y;

  // void printxy()

  public:

 OP(float xx=0.0, float yy=0.0)

   : numbers(xx,yy) {}

   void setxy(float xx,float yy){

     x=xx;

     y=yy;

   }

   void input(){ 

     cout <<"enter x: "; cin>>x;

     cout <<"enter y: "; cin>>y;

   }

   void print() {

     cout <<"x=" << x<<",y=" << y <

   }

   float sum() {

     return x+y;

   }

   float sub() {

     return x-y;

   }

   float mult() {

     return x*y;

   }

   float div() {

     return x/y;

   }

};

void menu() 

{

cout <<"=====menu================\n";

cout <<" Enetr npute number[i]\n";

cout <<" Enter sum [+]\n";

cout <<" Enter sub[-]\n";

cout <<" Enter multiple [*]\n";

cout <<" Enter exit [q]\n";

cout <<"==========================\n";

cout <<"choice:  ";

}

int main() 

{   OP op(2.5,6.5);

    char ch;

  while(1) 

  {

    menu() ; cin.sync();

    cin.get(ch) ;

    switch(ch){

     case 'i': op.input();

                break;

     case 'p': op.print(); break;

     case '+': 

           op.print();

           cout <<"sum=" << op.sum() <

           break;

      case '-': 

           op.print();

           cout <<"sub=" <

           break;

      case '*': 

           op.print();

           cout <<"mult=" << op.mult() <

           break;

      case '/': 

           op.print();

           cout <<"div=" <

           break;

     case 'q': exit(0);

     default :

       cout <<">>sorry invalid op...\n";

       

    }

  }

 

}


Related Solutions

Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson copy constructor example.
Class object in C++ programming language description about lesson copy constructor example.
Class object in C++ programming language description about lesson static variable example.
Class object in C++ programming language description about lesson static variable example.
Class object in C++ programming language description about lesson inheritance multi level example.
Class object in C++ programming language description about lesson inheritance multi level example.
Class object in C++ programming language description about lesson unary overloading function example.
Class object in C++ programming language description about lesson unary overloading function example.
Code in C++ programming language description about chose favorite fruit and wage color of fruit in lesson Class object (Multiple class).
Code in C++ programming language description about chose favorite fruit and wage  color of fruit in lesson Class object (Multiple class).
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
Code in C++ programming language description about read and write data to memory example.
Code in C++ programming language description about read and write data to memory example.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT