Sunday, August 28, 2011

C++ menu based program for XI standard


Here is the menu based program on C++ language. I have defined four functions in the class. From 'void main ()' function two numbers and the operator are entered by user and according to the entered operator, function is invoked.

 #include< iostream.h>
#include< conio.h>
class menu
{
 public:
 void add(int a, int b)
 {
  cout<<"\nSum="<<(a+b);
  }
   void sub(int a, int b)
 {
  cout<<"\nResult="<<(a-b);
  }
   void multiplication(int a, int b)
 {
  cout<<"\nResult="<<(a*b);
  }
   void div(int a, int b)
 {
  cout<<"\nResult="<<(a/b);
  }
  } ;

void main()
{
clrscr();
 int a,b;
 char ch;
 menu ob;
 cout<<"\nEnter two numbers:";
 cin>>a>>b;
 cout<<"\nEnter operator(+,-,*,/):";
 cin>>ch;
 switch(ch)
 {
   case '+':
                ob.add(a,b);
                break;
     case '-':
                ob.sub(a,b);
                break;
    case '*':
                ob.multiplication(a,b);
                break;
    case '/':
                ob.div(a,b);
                break;
     default:
     cout<<"\nWrong operator";
     break;
     }
     getch();
     }

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner