Program:
#include<iostream>
#include<string.h>
using namespace std;
class num
{
public:
char str[50],temp[50];
void cnvrt(int t)
{
switch(t){
case 0:
strcpy(str,"zero");
break;
case 1:
strcpy(str,"one");
break;
case 2:
strcpy(str,"two");
break;
case 3:
strcpy(str,"three");
break;
case 4:
strcpy(str,"four");
break;
case 5:
strcpy(str,"five");
break;
case 6:
strcpy(str,"six");
break;
case 7:
strcpy(str,"seven");
break;
case 8:
strcpy(str,"eight");
break;
case 9:
strcpy(str,"nine");
break;
}
}
num operator+(num stin)
{
num temp;
strcpy(temp.str,str);
strcat(temp.str,stin.str);
return temp;
}
};
int main()
{
num a[15],op;
int i=0,j,k=0,l,n,r,ar[15];
cout<<"Enter the number: ";
cin>>n;
while(n!=0)
{
r=n%10;
ar[k++]=r;
i++;
n=n/10;
}
for(j=0,l=(k-1);j<i,l>=0;j++,l--)
{
a[j].cnvrt(ar[l]);
}
strcpy(op.str," ");
for(j=0;j<i;j++)
{
op=op+a[j];
}
cout<<"\n"<<op.str<<endl;
return 1;
}
Output:
nn@ubuntu:~$ g++ n2.cpp
nn@ubuntu:~$ ./a.out
Enter the number: 1234567890
onetwothreefourfivesixseveneightninezero
nn@ubuntu:~$
#include<iostream>
#include<string.h>
using namespace std;
class num
{
public:
char str[50],temp[50];
void cnvrt(int t)
{
switch(t){
case 0:
strcpy(str,"zero");
break;
case 1:
strcpy(str,"one");
break;
case 2:
strcpy(str,"two");
break;
case 3:
strcpy(str,"three");
break;
case 4:
strcpy(str,"four");
break;
case 5:
strcpy(str,"five");
break;
case 6:
strcpy(str,"six");
break;
case 7:
strcpy(str,"seven");
break;
case 8:
strcpy(str,"eight");
break;
case 9:
strcpy(str,"nine");
break;
}
}
num operator+(num stin)
{
num temp;
strcpy(temp.str,str);
strcat(temp.str,stin.str);
return temp;
}
};
int main()
{
num a[15],op;
int i=0,j,k=0,l,n,r,ar[15];
cout<<"Enter the number: ";
cin>>n;
while(n!=0)
{
r=n%10;
ar[k++]=r;
i++;
n=n/10;
}
for(j=0,l=(k-1);j<i,l>=0;j++,l--)
{
a[j].cnvrt(ar[l]);
}
strcpy(op.str," ");
for(j=0;j<i;j++)
{
op=op+a[j];
}
cout<<"\n"<<op.str<<endl;
return 1;
}
Output:
nn@ubuntu:~$ g++ n2.cpp
nn@ubuntu:~$ ./a.out
Enter the number: 1234567890
onetwothreefourfivesixseveneightninezero
nn@ubuntu:~$
0 comments:
Post a Comment