谷歌翻译

程序翻译

代码:
#include <iostream>
#include <string>
using namespace std;
//对应字符
string NUMBER[] = {
"","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ","eleven ","twelve ","thirteen ","fourteen " ,
"fifteen ","sixteen ","seventeen ","eighteen ","nineteen "
};
string NUMBERtwo[] = {
"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"
};
class MyBot
{
public:
void putinfo(int a);//读法
private:
char name[25];
char type[25];
};
//打印信息
void MyBot::putinfo(int a)
{
int b = a % 100;
//翻译1000以内的数
if (a/100 != 0)
{
cout << NUMBER[a / 100] << "hundred ";
if (b!=0)
{
cout << "and ";
}
}
if (b < 20)
{
cout << NUMBER[b];
}
else
{
cout << NUMBERtwo[b / 10];
if (b%10 != 0)
{
cout << "\b-" << NUMBER[b % 10];
}
}
}
int main() {
int number;
cout << "请输入要翻译的数字:";
cin >> number;
MyBot bot;
bot.putinfo(number);
return 0;
}```
本文介绍了一个简单的C++程序,该程序能够将输入的整数(1000以内)转换为其英文读法。通过定义两个字符串数组来表示个位到十几的数字以及二十到九十的数字,程序使用了类和成员函数实现逻辑处理。用户可以输入一个数字,程序将输出该数字的英文表达。
4834

被折叠的 条评论
为什么被折叠?



