نقل قول ramin_amol
مدل گرافیکی شو
دوست گرامی این رو دارم
اگه کارتو اه ننداخت خبر بده تا یکی دیگشو برات بنویسم
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
void MainMenu();
void MathematicalMenu();
void TriangleMenu();
void ConvertMenu();
void GetNumbers(char ch='1');
char *Dec2Bin(int Dec);
char *Dec2Oct(int Dec);
char *Dec2Hex(int Dec);
char *Bin2Dec(long int Bin);
char *Oct2Dec(long int Oct);
char *Hex2Dec(char *Hex);
double num1,num2;
void main()
{
MainMenu();
}
void MainMenu()
{
clrscr();
cout<<"1-Mathematical Menu";
cout<<"\n2-Triangle Menu";
cout<<"\n3-Convertor Menu";
cout<<"\n4-Exit";
cout<<"\nEnter Menu Number: ";
char c=getche();
switch (c)
{
case '1':
clrscr();
GetNumbers(1);
MathematicalMenu();
break;
case '2':
clrscr();
GetNumbers();
TriangleMenu();
break;
case '3':
ConvertMenu();
break;
default:
exit(0);
}
}
void MathematicalMenu()
{
clrscr();
cout<<"x="<<num1<<"\ty="<<num2<<endl<<"-------------";
cout<<"\n0-Main Menu";
cout<<"\n1-x+y"<<"\n2-x*y";
cout<<"\n3-x-y"<<"\n4-x/y";
cout<<"\n5-sqrt x"<<"\n6-pow(x,y)";
cout<<"\n7-x*x";
cout<<"\n-------------"<<"\nEnter Menu Number: ";
char c=getche();
switch (c)
{
case '1':
cout<<"\nx+y="<<num1+num2;
break;
case '2':
cout<<"\nx*y="<<num1*num2;
break;
case '3':
cout<<"\nx-y="<<num1-num2;
break;
case '4':
cout<<"\nx/y="<<num1/num2;
break;
case '5':
cout<<"\nsqrt(x)="<<sqrt(num1);
break;
case '6':
cout<<"\npow(x,y)="<<pow(num1,num2);
break;
case '7':
cout<<"\nx*x="<<num1*num1;
break;
default:
MainMenu();
}
getch();
MathematicalMenu();
}
void TriangleMenu()
{
clrscr();
cout<<"x="<<num1<<endl<<"-------------";
cout<<"\n0-Main Menu";
cout<<"\n1-Sin(x)"<<"\n2-Cos(x)";
cout<<"\n3-Tan(x)"<<"\n4-log(x)";
cout<<"\n-------------"<<"\nEnter Menu Number: ";
char c=getche();
switch (c)
{
case '1':
cout<<"\nSin(x)="<<sin(num1);
break;
case '2':
cout<<"\nCos(x)="<<cos(num1);
break;
case '3':
cout<<"\nTan(x)="<<tan(num1);
break;
case '4':
cout<<"\nlog(x)="<<log(num1);
break;
default:
MainMenu();
}
getch();
TriangleMenu();
}
void ConvertMenu()
{
clrscr();
//cout<<"x="<<num1<<endl<<"-------------";
cout<<"\n0-Main Menu";
cout<<"\n1-Dec to Bin"<<"\n2-Dec to Oct";
cout<<"\n3-Dec to Hex"<<"\n4-Bin to Dec";
cout<<"\n5-Oct to Dec"<<"\n6-Hex to Dec";
cout<<"\n-------------"<<"\nEnter Menu Number: ";
char c=getche();
switch (c)
{
case '1':
GetNumbers();
cout<<"Dec to Bin(x)="<<Dec2Bin(num1);
break;
case '2':
GetNumbers();
cout<<"Dec to Oct(x)="<<Dec2Oct(num1);
break;
case '3':
GetNumbers();
cout<<"Dec to Hex(x)="<<Dec2Hex(num1);
break;
case '4':
GetNumbers();
cout<<"Bin to Dec(x)="<<Bin2Dec(num1);
break;
case '5':
GetNumbers();
cout<<"Oct to Dec(x)="<<Oct2Dec(num1);
break;
case '6':
char ch[10];
cout<<"\nEnter Number (x): ";
cin>>ch;
cout<<"Hex to Dec(x)="<<Hex2Dec(ch);
break;
default:
MainMenu();
}
getch();
ConvertMenu();
}
void GetNumbers(char ch)
{
cout<<endl<<"Enter Number (x): ";
cin>>num1;
if(ch==1)
{
cout<<"Enter Number (y): ";
cin>>num2;
}
}
// Decimal to Binary
char *Dec2Bin(int Dec)
{
char *bin=new char[0];
int pos = 0;
while(Dec > 0){
int m = Dec % 2;
bin[pos] = m+'0';
Dec = Dec/2;
pos++;
}
bin[pos]='\0';
return strrev(bin);
}
// Decimal to Octal
char *Dec2Oct(int Dec)
{
char *oct=new char[0];
int pos = 0;
while(Dec > 0)
{
int m = Dec % 8;
oct[pos] = m+'0';
Dec = Dec/8;
pos++;
}
oct[pos]='\0';
return strrev(oct);
}
// Decimal to HexaDecimal
char *Dec2Hex(int Dec)
{
char *hex=new char[0];
int pos = 0;
while(Dec > 0)
{
int m = Dec % 16;
hex[pos] = m<10 ? m + '0' : m-10+'A';
Dec = Dec/16;
pos++;
}
hex[pos]='\0';
return strrev(hex);
}
// Binary to Decimal
char *Bin2Dec(long int Bin)
{
char *Dec=new char[0];
ltoa(Bin,Dec,10);
long int result=0;
int pos=0;
int len=strlen(Dec)-1;
while(pos <= len)
{
int m = Dec[pos]-'0';
result+=(m)* (pow(2 ,len-pos));
pos++;
}
char res[10];
ltoa(result,res,10);
return res;
}
// Octal to Decimal
char *Oct2Dec(long int Oct)
{
char *Dec=new char[0];
ltoa(Oct,Dec,10);
long int result=0;
int pos = 0;
int len=strlen(Dec)-1;
while(pos <=len)
{
int m = Dec[pos]-'0';
result+=(m)* (pow(8 ,len-pos));
pos++;
}
char res[10];
ltoa(result,res,10);
return res;
}
// Hexadecimal to Decimal
char *Hex2Dec(char *Hex)
{
char *Dec=new char[0];
Dec=Hex;
long int result=0;
int pos = 0;
int len=strlen(Dec)-1;
while(pos <=len)
{
int m = Dec[pos]-'0'<10 ? Dec[pos]-'0' : Dec[pos]-'A'+10;
result+=(m)* (pow(16 ,len-pos));
pos++;
}
char res[10];
ltoa(result,res,10);
return res;
}