标题:类和对象
关键词:析构函数 整数翻译函数
内容:
A今日完成情况
关键词:析构函数 整数翻译函数
内容:
A今日完成情况
1.看类70%
B具体内容
折构函数在对象创建时执行,提供了初始化对象的一种简便手段。
析构函数在对象被撤销时执行,用于完成对象被撤销前的一些清理工作。
析构函数的格式:
<类名>::~<类名>()
{
函数体
}
C明日计划
Aperson类的设计
B实际意义的折构函数
整数翻译函数
#include<iostream>
#include<string.h>
using namespace std;
class
static char *num1[]=
{
"","one","two","three","four","five","six","seven","eight","nine","ten",
"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
"eighteen","nineteen"
};
static char *num10[]=
{
"",",","twenty","thirty","forty","fifty","sixty","seventy","eighty",
"ninety"
};
robot
{
private:
char name[20];
char type[20];
public:
robot()
{
strcpy(name,"啊啊啊");
strcpy(type,"嘤嘤嘤");
}
void set(char n[],char t[])
{
strcpy(name,n);
strcpy(type,t);
}
void out(int a);
void train_int(int n);
~robot(){};
};
void robot::out(int a)
{
int b=a%100;
{
cout<<num1[a/100]<<"hundred";
if(b!=0)
cout<<"and";
}
if(b<20)
cout<<num1[b];
else
{
cout<<num10[b/10];
if(b%10!=0)
cout<<"\b-"<<num1[b%10];
}
}
void robot::tran_int(int n)
{
if(n>1999999999)
cout<<"dev c++无法处理1999999999位的数"<<endl;
else
{
int a=n/1000000000,b=(n%1000000000)/1000000,c=(n%1000000)/1000,
d=n%1000;
if(a!=0)
{ out(a);
cout<<"billion";
}
if(b!=0)
{ out(b);
cout<<"million";
}
if(c!=0)
{
out(c);
cout<<"thousand";
}
if(d!=0)
{
if(d<100&&(a!=0||b!=0||c!=0))
cout<<"and";
out(d);
}
cout<<endl;
}
}
int main()
{
int n;
cout<<"请输入n:";
cin>>n;
cout<<n<<endl;
robot brown;
brown.tran_int(n);
return 0;
}