بانر

كود برنامج c++ سى بلس بلس لتحويل الارقام من كلوا لكلوا

كود برنامج سى بلس بلس لتحويل الارقام 
برنامج 
number converter by c++ code
مثلا : 
تقدر تحول من 

decimal  ====== > binary
decimal ====== > octal
decimal  ====== > hexdecimal

 binary  ====== > decimal
binary  ====== > octal
binary  ====== > hexdecimal

octal  ====== > decimal
octal  ====== > binary
octal  ====== > hexdecimal

hexdecimal  ====== > decimal
hexdecimal  ====== > binary
hexdecimal  ====== > octal


والان مع كود البرنامج 

#include<iostream.h>
#include<cstdlib>

int menu();
void decimal();
void binary();
void octal();
void hexdecimal();

char v ;
int main()
{
int choice = menu();
switch(choice)

{
case (1):
decimal();
cout << endl<< endl<< endl <<  "        Press c to continue or q to quit  "<< endl << endl ;
cin >> v ;
system("CLS");
if ( v == 'c')
return main() ;
system("CLS");
if (v == 'q' )
cout << endl << endl << " programmed by : " << endl << endl ;
cout <<  endl  << endl << "      ABM    "  << endl ;
cout <<  endl  << endl << "   http://www.3lakefkefak.blogspot.com/   "  << endl  << endl;

cout << endl << "               Thank you for using our program " << endl ;
break;
case (2):
binary();
cout << endl<< endl<< endl <<  "        Press c to continue or q to quit  "<< endl << endl ;
cin >> v ;
system("CLS");
if ( v == 'c')
return main() ;
system("CLS");
if (v == 'q' )
cout << endl << endl << " programmed by : " << endl << endl ;
cout <<  endl  << endl << "      ABM    "  << endl ;
cout <<  endl  << endl << "   http://www.3lakefkefak.blogspot.com/   "  << endl  << endl;

cout << endl << "               Thank you for using our program " << endl ;
break;
case(3):
octal();
cout << endl<< endl<< endl <<  "        Press c to continue or q to quit  "<< endl << endl ;
cin >> v ;
system("CLS");
if ( v == 'c')
return main() ;
system("CLS");
if (v == 'q' )
cout << endl << endl << " programmed by : " << endl << endl ;
cout <<  endl  << endl << "      ABM    "  << endl ;
cout <<  endl  << endl << "   http://www.3lakefkefak.blogspot.com/   "  << endl  << endl;

cout << endl << "               Thank you for using our program " << endl ;
break;
case(4):
hexdecimal();
cout << endl<< endl<< endl <<  "        Press c to continue or q to quit  "<< endl << endl ;
cin >> v ;
system("CLS");
if ( v == 'c')
return main() ;
system("CLS");
if (v == 'q' )
cout << endl << endl << " programmed by : " << endl << endl ;
cout <<  endl  << endl << "      ABM    "  << endl ;
cout <<  endl  << endl << "   http://www.3lakefkefak.blogspot.com/   "  << endl  << endl;

cout << endl << "               Thank you for using our program " << endl ;
break;


default:
cout<<"Wrong choice"<<endl;
cout << endl<< endl<< endl <<  "        Press c to continue or q to quit  "<< endl << endl ;
cin >> v ;
if ( v == 'c')
return main() ;
if (v == 'q' )
cout << endl << endl << " programmed by : " << endl << endl ;
cout <<  endl  << endl << "      ABM    "  << endl ;
cout <<  endl  << endl << "   http://www.3lakefkefak.blogspot.com/   "  << endl  << endl;

cout << endl << "               Thank you for using our program " << endl ;
break;

}
return 0 ;
}
int menu()
{
int choice;

cout << " Program to convert number : " << endl;
cout << " __________________________ " << endl;
cout << "   " << endl;
cout << "1 To convert Decimal number to Binary & Octal & Hexdecimal" << endl;
cout << "2 To convert Binary number to Decimal & Octal & Hexdecimal" << endl;
cout << "3 To convert Octal number to Dicmal & Binary & Hexdecimal" << endl;
cout << "4 To convert Hexdecimal number to Decimal & Binary & Octal" << endl;
cin >> choice;
return choice;
}

void decimal()
{
int num,a,bin=0,i=0,z,m,t,mult=1;
int oct=0,r, j=0, mul=1;
int counter,x,q,hex[100];
cout << "Please enter a decimal number : ";
cin >> num;
{

z = num ;

if(z<0)

{
cout<<"\n ERROR please enter a positive number!!!!!" << endl;
}
else
while(z > 0)
{
a = z % 2;
i = a * mult;
bin = bin + i;
mult = mult * 10;
z = z / 2;
}
cout<<"Binary number is = "<<bin<<endl;
{

m= num ;
if(m<0)
{
cout<<"\nERROR please enter a positive number!!!!!"<< endl;
}
else
while(m > 0)
{
r = m % 8;
j = r * mul;
oct = oct + j;
mul = mul * 10;
m = m / 8;

}
cout<<"Octal number is =  " << oct << endl;
}



{
cout << "Hexdecimal number is = ";
t= num ;
for(counter=0;t!=0;counter++)
{
q=t%16;
hex[counter]=q;
t=t/16;
}
for(x=counter-1;x>=0;x--)

{


if(hex[x]==10)
cout << "A";
else if(hex[x]==11)
cout <<"B";
else if(hex[x]==12)
cout <<"C";
else if(hex[x]==13)
cout <<"D";
else if(hex[x]==14)
cout <<"E";
else if(hex[x]==15)
cout <<"F";

else
cout <<hex[x];

}
cout << endl;

}




}
}


void binary()
{

int a,dec=0,i=0,bin,mult=1;
int oct=0,r, j=0 , m, mul=1;
int counter,x,q,hex[100],t;
cout<<"Enter the Binary Digit : ";
cin>>bin;
while(bin>0)
{
a = bin % 10;
i = a * mult;
dec = dec + i;
mult = mult * 2;
bin = bin / 10;
}
cout<<"Decimal number is = "<<dec<<endl;

{
m= dec ;
if(m<0)
{
cout<<"\nERROR please enter a positive number!!!!!"<< endl;
}
else
while(m > 0)
{
r = m % 8;
j = r * mul;
oct = oct + j;
mul = mul * 10;
m = m / 8;
}
cout<<"Octal number is =  " << oct << endl;
}

{
cout << "Hexdecimal number is = ";

t= dec ;
for(counter=0;t!=0;counter++)
{
q=t%16;
hex[counter]=q;
t=t/16;
}
for(x=counter-1;x>=0;x--)
{

if(hex[x]==10)
cout << "A";
else if(hex[x]==11)
cout <<"B";
else if(hex[x]==12)
cout <<"C";
else if(hex[x]==13)
cout <<"D";
else if(hex[x]==14)
cout <<"E";
else if(hex[x]==15)
cout <<"F";

else
cout <<hex[x];

}
cout << endl;

}

}
void octal()
{

int a,dec=0,prod=0,oct,mult=1;
int bin=0,r, pro=0 , m, mul=1;
int counter,x,q,hex[100],t;

cout<<"Enter the Octal number : ";
cin>>oct;
while(oct>0)
{
a = oct % 10;
prod = a * mult;
dec = dec + prod;
mult = mult * 8;
oct = oct / 10;
}
cout<<"Decimal number is = "<<dec<<endl;

{
m = dec ;
if(m<0)
{
cout<<"\nERROR please enter a positive number!!!!!"<< endl;
}
else
while(m > 0)
{
r = m % 2;
pro = r * mul;
bin = bin + pro;
mul = mul * 10;
m = m / 2;

}
cout<<"Binary number is =  " << bin << endl;
}

{
cout << "Hexdecimal number is = ";
t= dec ;
for(counter=0;t!=0;counter++)
{
q=t%16;
hex[counter]=q;
t=t/16;

}
for(x=counter-1;x>=0;x--)

{


if(hex[x]==10)
cout << "A";
else if(hex[x]==11)
cout <<"B";
else if(hex[x]==12)
cout <<"C";
else if(hex[x]==13)
cout <<"D";
else if(hex[x]==14)
cout <<"E";
else if(hex[x]==15)
cout <<"F";

else
cout <<hex[x];

}
cout << endl;

}

}


void hexdecimal()
{

int rem,mult=1,prod=0,dec=0,num;
int m,r,pro=0,mul=1,bin=0;
int re, k , po=0 , mu=1 , oct=0 ;
cout<<"Enter the Hexdecumal number : ";
cin>>num;


{

}
while(num>0)


{

rem = num % 10;
prod = rem * mult;
dec = dec + prod;
mult = mult * 16;
num = num / 10;


}
cout<<"Decimal number is = "<<dec<<endl;

{
m = dec ;
if(m<0)
{
cout<<"\nERROR please enter a positive number!!!!!"<< endl;
}
else
while(m > 0)
{
r = m % 2;
pro = r * mul;
bin = bin + pro;
mul = mul * 10;
m = m / 2;

}
cout<<"Binary number is =  " << bin << endl;

}

{
k= dec ;
if(k<0)
{
cout<<"\nERROR please enter a positive number!!!!!"<< endl;
}
else
while(k > 0)
{
re = k % 8;
po = re * mu;
oct = oct + po;
mu = mu * 10;
k = k / 8;
}
cout<<" Octal number is =  " << oct << endl;

}

}