بسم الله الرحمن الرحيم
اخوكم زيد العمري من مدينة الموصل\ العراق
لقد انضممت جديدا لهذا المنتدى الرائع نسال الله ان يكون خير انطلاقه للمبرمجين العرب
البرنامج التالي يقوم بالتحويل بين انظمة الاعداد عدا hexa اني اضعه هنا لاعرضه عليكم اذاي خطأ ا به
#include<stdio.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<math.h>
class convert
{ unsigned long int x,y;
public:
convert (unsigned long int a)
{ x=a; y=0;
}
void resety()
{ y=0;}
void dec2bin(int);
void dec2oct(int);
void bin2dec(int);
void oct2dec(int);
};
void convert::dec2bin(int z=1)
{ int i=0,j=0;
while(x>0)
{ j=x%2; x/=2;
y+=pow(10,i++)*j; }
if(z==1)
cout<<" \n"<<y; }
void convert::dec2oct(int z=1)
{ int i=0,j=0;
while(x>0)
{ j=x%8; x/=8;
y+=pow(10,i++)*j; }
if(z==1)
cout<<" \n"<<y; }
void convert::bin2dec(int z=1)
{ int i=0,j=0;
while(x>0)
{ j=x%10; x/=10;
y+=pow(2,i++)*j;
} x=y;
if(z==1)
cout<<" \n"<<y; }
void convert::oct2dec(int z=1)
{ int i=0,j=0;
while(x>0)
{ j=x%10; x/=10;
y+=pow(8,i++)*j;
}x=y;
if(z==1)
cout<<" \n"<<y;
}
void main()
{ clrscr(); char q='y',m[10];
unsigned long int n;
while(q=='y')
{ cout<<" \n number : ";
cin>>n;
convert A(n);
cout<<" from to \n";
gets(m);
if(strcmp(m,"b to d")==0)
{ while(n>0)
{ int r=n%10;
n/=10;
if(r>1)
{ sound(210); delay(300);
cout<<" \n this program will stopped now\n";sleep(1); nosound(); exit(0);}}
A.bin2dec();}
else
if(strcmp(m,"o to d")==0)
{ while(n>0)
{ int r=n%10;
n/=10;
if(r>7)
{ sound(210); delay(300);
cout<<" \n this program will stopped now \n"; nosound(); sleep(1); exit(0);}}
A.oct2dec();
}
else
if(strcmp(m,"d to b")==0)
A.dec2bin();
else
if(strcmp(m,"d to o")==0)
A.dec2oct();
else
if(strcmp(m,"o to b")==0)
{ while(n>0)
{ int r=(n%10);
n/=10;
if(r>7)
{ sound(210); delay(300);
cout<<" \n this program will stopped now\n"; nosound(); sleep(1);exit(0);}}
A.oct2dec(0);
A.resety();
A.dec2bin();}
else
if(strcmp(m,"b to o")==0)
{ while(n>0)
{ int r=n%10;
n/=10;
if(r>1)
{ sound(210); delay(300);
cout<<" \n this program will stopped now\n"; nosound(); sleep(1);exit(0);}}
A.bin2dec(0);
A.resety();
A.dec2oct();}
else
{ sound(100); delay(300);
cout<<"\n Error .. try arain ";
nosound(); sleep(1);
exit(0);}
cout<<" \n again (y/n) \n";
cin>>q;
}}