写了个,这题有点意思
#include <iostream.h>
#include <string.h>
#include <alloc.h>
static char* num[]={
"零","一","二","三","四",
"五","六","七","八","九"
};
class money{
float number;
public:
money(float m){number=m;}
~money(){};
void set(float m){number=m;}
void get();
float get(int i){return number;}
};
void money::get (){
float temp=number;
char str[100],tmp[3];
long i;
int Nrest,Nint;
Nint=(int)temp;
//Nrest=temp-Nint;
if(Nint/1000000000>0){ cout<<"\n多于拾亿,自己换算!"; return; }
for(i=1000000000;Nint/i==0;i=i/10);
//cout<<"\ni="<<i<<"\n整数="<<Nint<<"\t小数="<<Nrest<<"temp="<<temp;
while(Nint%i){
Nint=Nint/i;
strcpy(tmp,num[Nint/i]);
strcat(tmp,str);
switch(i){
case 1000000000:strcat("拾亿",str);break;
case
100000000:strcat(
"亿",str);break;
case
10000000:strcat("仟万",str);break;
case
1000000:strcat("佰万",str);break;
case
100000:strcat("拾万",str);break;
case
10000:strcat(
"万",str);break;
case
1000:strcat(
"仟",str);break;
case
100:strcat(
"佰",str);break;
case
10:strcat(
"拾",str);break;
case
1:strcat(
"圆",str);break;
}
i/=10;
}
cout<<endl<<str<<endl;
/*处理小数*/
temp=temp-(int)temp;
if((int(temp*100))!=0){
strcat(num[(int(temp*10))],str);
strcat(
"角",str);
}
if((int(temp*10))!=0){
strcat(num[(int(temp*10))],str);
strcat(
"分",str);
}
cout<<endl<<str<<endl;
}
int main()
{
money m(0);
float y;
cout<<"输入金额:¥";
cin>>y;
//cout<<"\ny="<<y<<endl;
m.set(y);
//cout<<"number="<<m.get(1);
m.get();
//cout<<endl<<str<<endl;
return 0;
}