Program:
#include<iostream>
#include<string.h>
using namespace std;
class strin
{
char str[50];
public:
strin()
{
strcpy(str," ");
}
strin(char* mystr)
{
strcpy(str,mystr);
}
void operator+(strin s)
{
strcpy(str,s.str);
cout<<str;
}
};
main()
{
strin str1,str2;
int n,n1,dg,y=0,lastzero=0;
cout<<"\t\tOPERATOR OVERLOADING -II (12 --> ONE TWO)\nEnter the number: ";
cin>>n;n1=n;
while(n>0)
{
dg=n%10;
y=y*10+dg;
n=n/10;
}
while(n1%10==0)
{
lastzero++;
n1/=10;
if(lastzero>20)
{
lastzero=1;
break;
}
}
while(y>0)
{
dg=y%10;
switch(dg)
{
case 1: str2=(char*)" one";
str1 + str2;
break;
case 2 :str2=(char*)" two";
str1 + str2;
break;
case 3: str2=(char*)" three";
str1 + str2;
break;
case 4 :str2=(char*)" four";
str1 + str2;
break;
case 5: str2=(char*)" five";
str1 + str2;
break;
case 6 :str2=(char*)" six";
str1 + str2;
break;
case 7: str2=(char*)" seven";
str1 + str2;
break;
case 8 :str2=(char*)" eight";
str1 + str2;
break;
case 9: str2=(char*)" nine";
str1 + str2;
break;
case 0 :str2=(char*)" zero";
str1 + str2;
break;
default:
cout<<"\n\nError.......exiting...";
break;break;
}
y=y/10;
}
while(lastzero!=0)
{
cout<<" zero";
lastzero--;
}
cout<<endl;
}
Output:
nn@ubuntu:~$ g++ op.cpp
nn@ubuntu:~$ ./a.out
OPERATOR OVERLOADING -II (12 --> ONE TWO)
Enter the number: 1234567890
one two three four five six seven eight nine zero
nn@ubuntu:~$
#include<iostream>
#include<string.h>
using namespace std;
class strin
{
char str[50];
public:
strin()
{
strcpy(str," ");
}
strin(char* mystr)
{
strcpy(str,mystr);
}
void operator+(strin s)
{
strcpy(str,s.str);
cout<<str;
}
};
main()
{
strin str1,str2;
int n,n1,dg,y=0,lastzero=0;
cout<<"\t\tOPERATOR OVERLOADING -II (12 --> ONE TWO)\nEnter the number: ";
cin>>n;n1=n;
while(n>0)
{
dg=n%10;
y=y*10+dg;
n=n/10;
}
while(n1%10==0)
{
lastzero++;
n1/=10;
if(lastzero>20)
{
lastzero=1;
break;
}
}
while(y>0)
{
dg=y%10;
switch(dg)
{
case 1: str2=(char*)" one";
str1 + str2;
break;
case 2 :str2=(char*)" two";
str1 + str2;
break;
case 3: str2=(char*)" three";
str1 + str2;
break;
case 4 :str2=(char*)" four";
str1 + str2;
break;
case 5: str2=(char*)" five";
str1 + str2;
break;
case 6 :str2=(char*)" six";
str1 + str2;
break;
case 7: str2=(char*)" seven";
str1 + str2;
break;
case 8 :str2=(char*)" eight";
str1 + str2;
break;
case 9: str2=(char*)" nine";
str1 + str2;
break;
case 0 :str2=(char*)" zero";
str1 + str2;
break;
default:
cout<<"\n\nError.......exiting...";
break;break;
}
y=y/10;
}
while(lastzero!=0)
{
cout<<" zero";
lastzero--;
}
cout<<endl;
}
Output:
nn@ubuntu:~$ g++ op.cpp
nn@ubuntu:~$ ./a.out
OPERATOR OVERLOADING -II (12 --> ONE TWO)
Enter the number: 1234567890
one two three four five six seven eight nine zero
nn@ubuntu:~$
0 comments:
Post a Comment