Uploaded by muthu45711

menudriven

advertisement
#include<iostream>
using namespace std;
// Function
void menu()
{
cout <<
cout <<
cout <<
cout <<
cout <<
cout <<
cout <<
}
to display the menu
"Press
"Press
"Press
"Press
"Press
"Press
"Press
1
2
3
4
5
6
7
to
to
to
to
to
to
to
calculate
calculate
calculate
calculate
calculate
calculate
exit\n";
Sum of Numbers\n";
Difference of Numbers\n";
Product of numbers\n";
Division of numbers\n";
HCF of numbers\n";
LCM of numbers\n";
// Function to calculate and display the result
void result(int choice, int a, int b)
{
// Display the result
switch (choice) {
case 1: {
cout << "Sum is " << (a + b) << "\n";
break;
}
case 2: {
cout << "Difference is " << (a - b) << "\n";
break;
}
case 3: {
cout << "Product is " << (a * b) << "\n";
break;
}
case 4: {
cout << "Division is " << (a / b) << "\n";
break;
}
case 5: {
cout << "GCD is " << __gcd(a, b) << "\n";
break;
}
case 6: {
cout << "LCM is "
<< ((a * b) / __gcd(a, b))
<< "\n";
break;
}
case 7: {
cout << "Thank you\n";
break;
}
default:
printf("Wrong Input\n");
}
}
int main()
{
// Get the two numbers
int a = 5, b = 7;
int choice, res;
// Display the menu
menu();
// Enter the choice
cout << "Enter your choice:\n";
choice = 1;
cout << "Choice is " << choice << endl;
// Display the result
// according to the choice
result(choice, a, b);
return 0;
}
Output:
Press 1 to calculate Sum of Numbers
Press 2 to calculate Difference of Numbers
Press 3 to calculate Product of numbers
Press 4 to calculate Division of numbers
Press 5 to calculate HCF of numbers
Press 6 to calculate LCM of numbers
Press 7 to exit
Enter your choice:
Choice is 1
Sum is 12
#include<iostream>
using namespace std;
class arithmatic
{
public:
inline double add(double a,double b)
{
return (a+b);
}
inline double sub(double a,double b)
{
return (a-b);
}
inline double multip(double a,double b)
{
return (a*b);
}
inline double div(double a,double b)
{
return (a/b);
}
};
void main()
{
int ch;
double x,y,t;
arithmatic obj;
clrscr();
do
{
cout<<“\n\tMENU \n”;
cout<<“1.Addition\n2.Subtraction\n”;
cout<<“3.Multiplication\n4.Division\n5.Exit\n”;
cout<<“\n\tEnter youer choice: “;
cin>>ch;
switch(ch)
{
case 1:
cout<<“\nEnter two number: “;
cin>>x>>y;
t=obj.add(x,y);
cout<<“Addition “<<x<<“+”<<y<<“=”<<t<<endl;
break;
case 2:
cout<<“\nEnter two number: “;
cin>>x>>y;
t=obj.sub(x,y);
cout<<“Subtractin “<<x<<“-“<<y<<“=”<<t<<endl;
break;
case 3:
cout<<“\nEnter two number: “;
cin>>x>>y;
t=obj.multip(x,y);
cout<<“\nMultiplication “<<x<<“*”<<y<<“=”<<t<<endl;
break;
case 4:
cout<<“\nEnter two number: “;
cin>>x>>y;
t=obj.div(x,y);
cout<<“Division “<<x<<“/”<<y<<“=”<<t<<endl;
break;
case 5:
break;
}
}while(ch!=5);
getch();
}
Download