Hello Uncles and Aunties!
Code:
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
void menu() // main menu
{
printf("A......Addition\n");
printf("S......Subtraction\n");
printf("D......Division\n");
printf("M......Multiplication\n");
printf("F......Factorial\n");
printf("P......Power\n");
printf("G......String Operation\n");
printf("E......Exit\n");
printf("\t\tEnter Your Choice Please");
}
void add() // function for addition
{
char ch;
while(1)
{
int a,b;
clrscr();
cout<<"\t\t\t\tAddition\nEnter 1st number:";
cin>>a;
cout<<"\nEnter 2nd number:";
cin>>b;
cout<<"\n"<<a<<"+"<<b<<"="<<(a+b);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void sub() // function for subtraction
{
char ch;
while(17)
{
int a,b;
clrscr();
cout<<"\t\t\t\tSubtraction\nEnter 1st number:";
cin>>a;
cout<<"\nEnter 2nd number:";
cin>>b;
cout<<"\n"<<a<<"-"<<b<<"="<<(a-b);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Division() // function for division
{
char ch;
while(1)
{
int a,b;
clrscr();
cout<<"\t\t\t\tDivision\nEnter 1st number:";
cin>>a;
cout<<"\nEnter 2nd non-zero number:";
cin>>b;
cout<<"\n"<<a<<"/"<<b<<"="<<(a/b);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Multiplication() // function for multiplication
{
char ch;
while(1)
{
int a,b;
clrscr();
cout<<"\t\t\t\tMultiplication\nEnter 1st number:";
cin>>a;
cout<<"\nEnter 2nd number:";
cin>>b;
cout<<"\n"<<a<<"*"<<b<<"="<<(a*b);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Power() // function for power
{
char ch;
while(1)
{
int a,b;
clrscr();
cout<<"\t\t\t\tPower\nEnter number:";
cin>>a;
cout<<"\nEnter its power:";
cin>>b;
for(int i=1;i<b;i++)
a*=a;
cout<<"\n"<<a<<"^"<<b<<"="<<a;
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Factorial() // function to calculate factorial
{
char ch;
while(1)
{
int a,c;
clrscr();
cout<<"\t\t\t\tFactorial\nEnter a number:";
cin>>a;
c=a;
for(int i=c-1;i>0;i--)
a*=i;
cout<<c<<"!="<<a;
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void printstr() // strings operation menu
{
clrscr();
cout<<"\nR.....Reverse";
cout<<"\nC.....Concatenation";
cout<<"\nX.....Copy";
cout<<"\nL.....Length";
cout<<"\nB.....Back";
cout<<"\nEnter Your Choice";
}
// STRING PORTION START //
void reverse() // string function for reverse
{
char ch;
while(1)
{
clrscr();
char str[100];
cout<<"\nEnter a String:";
scanf("%s",&str);
printf("\nReverse is %s",strrev(str));
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void concat() // string function for concat
{
char ch;
while(1)
{
clrscr();
char str[100],str1[100];
cout<<"\nEnter 1st String:";
scanf("%s",&str);
cout<<"\nEnter 2nd String:";
scanf("%s",&str1);
cout<<str<<"+"<<str1<<"=";
cout<<strncat(str,str1,strlen(str1));
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void copy() // string function for copy
{
char ch;
while(1)
{
clrscr();
char str[100],str1[100];
cout<<"\nEnter 1st String:";
scanf("%s",&str);
cout<<"\nEnter 2nd string";
scanf("%s",&str1);
clrscr();
cout<<"1st String="<<str;
cout<<"\n2nd String="<<str1;
cout<<"\nString 1 copied to string 2.....";
strcpy(str,str1);
cout<<"\nString 1="<<str;
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void length() // string function for determining length
{
char ch;
while(1)
{
clrscr();
char str[100];
cout<<"\nEnter a String:";
scanf("%s",&str);
cout<<"\nLength of"<<str<<"is "<<strlen(str);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Strings() // main string operations
{
cout<<"\t\t\t\tString Operations\n";
char ch='Y',str[10];
while(ch!='b' || ch!='B')
{
printstr();
ch=getch();
switch(ch)
{
case'R':
case'r':
reverse();
break;
case'C':
case'c':
concat();
break;
case'x':
case'X':
copy();
case'l':
case'L':
length();
break;
case'b':
case'B':
break;
default:
clrscr();
}
if(ch=='b' || ch=='B')
{
clrscr();
break;
}
}
}
void main() // The program's Main Function (will display as the program executes)
{
char ch1='Y';
cout<<"\n\n\n\n\t\t\tWelcome\n\n\t\t\tMy Calculator\n\n\t\t\tVersion 1.0\n\n\t\tPress any key.......";
getch();
clrscr();
while(ch1!='e' || ch1!='E')
{
menu(); // will call the function menu
ch1=getch();
switch(ch1)
{
case'A':
case'a':
add();
break;
case'S':
case's':
sub();
break;
case'D':
case'd':
Division();
break;
case'M':
case'm':
Multiplication();
break;
case'F':
case'f':
Factorial();
break;
case'P':
case'p':
Power();
break;
case'G':
case'g':
Strings();
break;
case'E':
case'e':
exit(0);
default:
clrscr();
}
}
}
Hello ! I want this program to be given a GUI, a graphical representation of this calculator, how do I do that?