A simple programme

Submitted By: Sanjidur
Rating: star (Rate It)
Share: Share By Email By Email

Visit


Description

Its only an example...



#include<iostream.h>
#include<cstdlib>
//using namespace std;
char a[60],c[60];
class Integer{
int i;
public:
Integer();
Integer(int i);
int setint(int i);
char *toString(int radix);
int isprime();
//char *binary(int b);
};
Integer::Integer(){i=0;}
Integer:: Integer(int i){
this->i = i;
}
int Integer:: setint(int i){
this->i=i;
return 0;
}
char* Integer:: toString(int radix)
{ int j=0,k;
switch(radix){
case 2:
while(i>0)
{
a[j]=(i%2)+48;
i=i/2;j++;
}
break;
case 8:
while(i>0)
{
a[j]=(i%8)+48;
i=i/8;j++;
}
break;
case 16:
while(i>0)
{
int m;
m=i%16;
if(m<=9)a[j]=m+48;
else if(m==10)a[j]='A';
else if(m==11)a[j]='B';
else if(m==12)a[j]='C';
else if(m==13)a[j]='D';
else if(m==14)a[j]='E';
else a[j]='F';
i=i/16;j++;
}
break;
default:
cout<<"Unrecognised number system"<<endl;
}
int l=j-1;
for( k=0;k<j;k++)
{c[k]=a[l];l--;}
return c;

}
int Integer::isprime()
{
return 0;
}

int main()
{
Integer x(2);
x.setint(13);
char *s;
s=(char*)malloc(sizeof(char)*60);
s=x.toString(16);
cout<<s<<endl;
return 0;
}

Comments (1)

Against most coding styles star   Posted by: bilderbikkel on Sunday, May 16, 2010

This example shows how not to program. Examples of bad style are
- #include of iostream.h instead of iostream
- use of malloc in C++
- use of globals
- use of C-style casts
- the method IsPrime that always returns zero (instead of returning an int depending on the integer in Integer)

Add Your Rating

(Not published)
star
starstar
starstarstar
starstarstarstar
starstarstarstarstar
 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.