C++ 简单模拟谷歌数字1000以内数字翻译

谷歌翻译 程序翻译 代码: #include #include using namespace std;//对应字符string NUMBER[]

谷歌翻译
在这里插入图片描述
程序翻译
在这里插入图片描述
代码:

#include 
#include 
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;
}```