用Dev C++写一个程序,急...在线等..
Writeaprogramthatoutputsthelyricsforthesong"Ninety_NineBottlesofBeerontheWall."Yourpr...
Write a program that outputs the lyrics for the song "Ninety_Nine Bottles of Beer on the Wall." Your program should print the number of bottles in English, not as a number. For example:
Ninety_nine bottles of beer on the wall,
Ninety-nine bottles of beer,
Take one down, pass it around, Ninety-eight bottles of beer on the wall.
.....
.....
One bottle of beer on the wall,
one bottle of bber,
Take one down, pass it around,
Zero bottles of beer on the wall.
Design your program with a function that takes as an argument an integer between 0 and 99 and returns a string that contains the integer value in English. Your function should bot have 100 different if-else statements@ Instead, use % and / to extract the tens and ones digits to construct the English string. You may need to test specifically for values such as 0, 10-19, etc.
哪位能帮我写一下这个程序,内容不是很难,但是不知道要怎么写...在线等啊...急要...
翻译一下:
写一个程序,运行之后可以output一首歌的歌词:
Ninety_nine bottles of beer on the wall,
Ninety-nine bottles of beer,
Take one down, pass it around,
Ninety-eight bottles of beer on the wall.
.....
.....
One bottle of beer on the wall,
one bottle of bber,
Take one down, pass it around,
Zero bottles of beer on the wall.
歌词都是一样的,就是前面的数字不一样,一直从ninety-nine唱到zero,而且不要数字,是要英文单词来代替数字的,顺便补充一下,不能用100个if else或者case什么的..要用%和/来弄数字..
哪位高手能帮帮忙啊..在线等啊.. 展开
Ninety_nine bottles of beer on the wall,
Ninety-nine bottles of beer,
Take one down, pass it around, Ninety-eight bottles of beer on the wall.
.....
.....
One bottle of beer on the wall,
one bottle of bber,
Take one down, pass it around,
Zero bottles of beer on the wall.
Design your program with a function that takes as an argument an integer between 0 and 99 and returns a string that contains the integer value in English. Your function should bot have 100 different if-else statements@ Instead, use % and / to extract the tens and ones digits to construct the English string. You may need to test specifically for values such as 0, 10-19, etc.
哪位能帮我写一下这个程序,内容不是很难,但是不知道要怎么写...在线等啊...急要...
翻译一下:
写一个程序,运行之后可以output一首歌的歌词:
Ninety_nine bottles of beer on the wall,
Ninety-nine bottles of beer,
Take one down, pass it around,
Ninety-eight bottles of beer on the wall.
.....
.....
One bottle of beer on the wall,
one bottle of bber,
Take one down, pass it around,
Zero bottles of beer on the wall.
歌词都是一样的,就是前面的数字不一样,一直从ninety-nine唱到zero,而且不要数字,是要英文单词来代替数字的,顺便补充一下,不能用100个if else或者case什么的..要用%和/来弄数字..
哪位高手能帮帮忙啊..在线等啊.. 展开
3个回答
展开全部
#include <iostream>
using namespace std;
int getEn(int i)
{
int j = i%10;
int k = i/10;
if(k > 1)
{
switch(k)
{
case 2:
cout << "Twenty";
break;
case 3:
cout << "Thirty";
break;
case 4:
cout << "Forty";
break;
case 5:
cout << "fifty";
break;
case 6:
cout << "Sixty";
break;
case 7:
cout << "Seventy";
break;
case 8:
cout << "Eighty";
break;
case 9:
cout << "Nighty";
break;
}
switch(j)
{
case 1:
cout << "-one";
break;
case 2:
cout << "-two";
break;
case 3:
cout << "-three";
break;
case 4:
cout << "-four";
break;
case 5:
cout << "-five";
break;
case 6:
cout << "-six";
break;
case 7:
cout << "-seven";
break;
case 8:
cout << "-eight";
break;
case 9:
cout << "-night";
break;
}
}
else if(k==1)
{
switch(j)
{
case 0:
cout << "Ten";
break;
case 1:
cout << "Eleven";
break;
case 2:
cout << "Twelve";
break;
case 3:
cout << "Thirteen";
break;
case 4:
cout << "Fourteen";
break;
case 5:
cout << "Fifteen";
break;
case 6:
cout << "Sixteen";
break;
case 7:
cout << "Seventeen";
break;
case 8:
cout << "Eighteen";
break;
case 9:
cout << "Nighteen";
break;
}
}
else if(k==0)
{
switch(j)
{
case 0:
cout << "Zero";
break;
case 1:
cout << "One";
break;
case 2:
cout << "Two";
break;
case 3:
cout << "Three";
break;
case 4:
cout << "Four";
break;
case 5:
cout << "Five";
break;
case 6:
cout << "Six";
break;
case 7:
cout << "Seven";
break;
case 8:
cout << "Eight";
break;
case 9:
cout << "Night";
break;
}
}
return 1;
}
int main()
{
for(int i=99;i>0;i--)
{
getEn(i);
cout << " bottles of beer on the wall," << endl;
getEn(i);
cout << " bottles of beer." << endl << "Take one down, pass it around." << endl;
}
getEn(0);
cout << " bottles of beer on the wall," << endl;
getEn(0);
cout << " bottles of beer." << endl;
system("pause");
}
我这种写法很适合初学者,呵呵
using namespace std;
int getEn(int i)
{
int j = i%10;
int k = i/10;
if(k > 1)
{
switch(k)
{
case 2:
cout << "Twenty";
break;
case 3:
cout << "Thirty";
break;
case 4:
cout << "Forty";
break;
case 5:
cout << "fifty";
break;
case 6:
cout << "Sixty";
break;
case 7:
cout << "Seventy";
break;
case 8:
cout << "Eighty";
break;
case 9:
cout << "Nighty";
break;
}
switch(j)
{
case 1:
cout << "-one";
break;
case 2:
cout << "-two";
break;
case 3:
cout << "-three";
break;
case 4:
cout << "-four";
break;
case 5:
cout << "-five";
break;
case 6:
cout << "-six";
break;
case 7:
cout << "-seven";
break;
case 8:
cout << "-eight";
break;
case 9:
cout << "-night";
break;
}
}
else if(k==1)
{
switch(j)
{
case 0:
cout << "Ten";
break;
case 1:
cout << "Eleven";
break;
case 2:
cout << "Twelve";
break;
case 3:
cout << "Thirteen";
break;
case 4:
cout << "Fourteen";
break;
case 5:
cout << "Fifteen";
break;
case 6:
cout << "Sixteen";
break;
case 7:
cout << "Seventeen";
break;
case 8:
cout << "Eighteen";
break;
case 9:
cout << "Nighteen";
break;
}
}
else if(k==0)
{
switch(j)
{
case 0:
cout << "Zero";
break;
case 1:
cout << "One";
break;
case 2:
cout << "Two";
break;
case 3:
cout << "Three";
break;
case 4:
cout << "Four";
break;
case 5:
cout << "Five";
break;
case 6:
cout << "Six";
break;
case 7:
cout << "Seven";
break;
case 8:
cout << "Eight";
break;
case 9:
cout << "Night";
break;
}
}
return 1;
}
int main()
{
for(int i=99;i>0;i--)
{
getEn(i);
cout << " bottles of beer on the wall," << endl;
getEn(i);
cout << " bottles of beer." << endl << "Take one down, pass it around." << endl;
}
getEn(0);
cout << " bottles of beer on the wall," << endl;
getEn(0);
cout << " bottles of beer." << endl;
system("pause");
}
我这种写法很适合初学者,呵呵
展开全部
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
const char * num_low[] = {"one","two","three","four","five","six","seven","eight","nine"};
const char * num_0_9[] = {"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
const char * num_high[] = {"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
const char * num_10_19[] = {"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen", "Eighteen", "Nineteen"};
string getNumString(int n)
{
int high = n/10;
if(high == 0) return string(num_0_9[n]);
int low = n%10;
if(high == 1) return string(num_10_19[low]);
string res = string(num_high[high-2]);
if(low != 0)
{
res += "-";
res += num_low[low-1];
}
return res;
}
void writeLyrics(int n)
{
if(n>99) return;
cout<<getNumString(n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer on the wall,"<<endl;
cout<<getNumString(n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer,"<<endl;
cout<<"Take one down, pass it around, "<<endl;
cout<<getNumString(--n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer on the wall."<<endl;
cout<<endl;
if(n > 0) writeLyrics(n);
}
int main(int argc, char *argv[])
{
int n;
cout<<"Input a number:";
cin>>n;
cout<<endl;
writeLyrics(n);
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
#include <string>
using namespace std;
const char * num_low[] = {"one","two","three","four","five","six","seven","eight","nine"};
const char * num_0_9[] = {"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
const char * num_high[] = {"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
const char * num_10_19[] = {"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen", "Eighteen", "Nineteen"};
string getNumString(int n)
{
int high = n/10;
if(high == 0) return string(num_0_9[n]);
int low = n%10;
if(high == 1) return string(num_10_19[low]);
string res = string(num_high[high-2]);
if(low != 0)
{
res += "-";
res += num_low[low-1];
}
return res;
}
void writeLyrics(int n)
{
if(n>99) return;
cout<<getNumString(n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer on the wall,"<<endl;
cout<<getNumString(n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer,"<<endl;
cout<<"Take one down, pass it around, "<<endl;
cout<<getNumString(--n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer on the wall."<<endl;
cout<<endl;
if(n > 0) writeLyrics(n);
}
int main(int argc, char *argv[])
{
int n;
cout<<"Input a number:";
cin>>n;
cout<<endl;
writeLyrics(n);
system("PAUSE");
return EXIT_SUCCESS;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个程序倒是不难,但是真的需要时间的。只有分数恐怕解决不了问题吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询