| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1156 人关注过本帖
标题:考考你,同时也是作业. - -!
取消只看楼主 加入收藏
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
 问题点数:0 回复次数:5 
考考你,同时也是作业. - -!
Many computer programs use menus as part of the user interface. A menu offers the user a choice of responses. The user then enters one of these choices, and the program acts on that choice.
For example:
Enter the operation of your choice:
a. judge character b. print character
c. get a power d. base_n
e. exit/quit
Write a program that shows you a menu offering you the choice of :
a: Write a function that reads characters from the standard input to end-of-file. For each character, have the program report whether it is a letter. If it is a letter, also report its numerical location in the alphabet. For example, c and C would both be letter 3. Incorporate a function that takes a character as an argument and returns the numerical location if the character is a letter and that returns –1 otherwise.
b: Write a function that takes three arguments: a character and two integers. The character is to be printed. The first integer specifies the number of times that the character is to be printed on a line, and the second integer specifies the number of lines that are to be printed. Write a program that makes use of this function.
c: Write a power() function that returned the result of raising a type double number to a positive integer value. Improve the function so that it correctly handles negative powers. Also, build into the function that 0 to any power is 0 and that any number to the 0 power is 1.
d: Write a to_base_n() function that takes a second argument in the range 2–10. It then should print the number that is its first argument to the number base given by the second argument. For example, to_base_n(129,8) would display 201, the base-8 equivalent of 129.
e: end this program
/*请哪为英语好的同时帮忙翻译一下,谢谢了*/
搜索更多相关主题的帖子: 作业 考考 
2006-12-06 14:52
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
得分:0 

麻烦先帮忙把题翻译一下行吗?

2006-12-06 20:19
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
得分:0 
非常感谢你能回帖子,运行了一下你的程序。你写的程序要是进入B选项的话要怎么输入啊?我怎么按照你那输入,然后显示的都是ERROR呢?
2006-12-07 21:09
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
得分:0 

我自己已经写出了a和b的两个函数,请帮我看看有没有错误。
a函数:
int a(charc)
{
if(c>=65&&c<=90||c>=97&&c<=122)
{
a=c-64;
if(a>26) a-=32;
}
else
a=-1;
return a;
}
b函数:
void b(charc,intb,intc)
{
int i m;
for(m=1,m<=c,++m)
{
for(i=1,i<=b,++i)
{printf("%c/n",a);}
}

2006-12-07 21:46
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
得分:0 
我试了一下,Welton 写的程序A选项的功能好象不能用哦。能帮我解释一下A选项吗?
2006-12-12 17:19
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
得分:0 

#include<stdio.h>
int main()
{
int a(char c);
int hua(char a,int b,int c);
float power(float a,int b);
void to_base_n(float f,int n);
char chose,c,d;
int b,f,h,j,k,e;
float g,i;
loop: printf("\nenter the operation of your choice:\na judje character b printf character \nc get a power d bas_n\ne exit\n");
scanf("%c",&chose);
getchar();
switch(chose)
{
case 'a':
{
printf("please typ in a character:");
scanf("%c",&c);
getchar();
b=a(c);
if(b==0) printf("this character is not a letter!!");
else printf("%d",b);
goto loop;
}
case 'b':
{
printf("please typ in a character and two intger number");
scanf("%c%d%d",&d,&e,&f);
getchar();
hua(d,e,f);
goto loop;
}
case 'c':
{
printf("please typ in two number,one is a float another is a intger");
scanf("%f%d",&g,&h);
getchar();
i=power(g,h);
printf("%f",i);
goto loop;
}
case 'd':
{
printf("please typ in two intger number");
scanf("%d%d",&j,&k);
getchar();
to_base_n(j,k);
goto loop;
}
case 'e':
{
break;
}
}
return 0;
}

int a(char c)
{
int a;
if(c>=65&&c<=90||c>=97&&c<=122)
{
a=c-64;
if(a>26){a-=32;}
}
else a=0;
return a;
}

int hua(char a,int b,int c)
{
int i,m;
for(m=1;m<=c;++m)
{
printf("\n");
for(i=1;i<=b;++i)
{ printf("%c",a); }
}
return 0;
}

float power(float a,int b)
{
int i;
float c;
c=a;
for(i=2;i<=b;i+=1)
{
a=a*c;
}
return a;
}

void to_base_n(float f,int n)
{
long a;
float b;
int c[30],i=0,j=0;
if(n>=2&&n<=10)
{
a=(int)f;
b=f-a;
while(a>=n)
{
c[i++]=a%n;
a=a/n;
}
c[i]=a;
for(j=i;j>=0;j--)
printf("%d",c[j]);
if(b!=0)
{
printf(".");
while(j<30)
{
b=b*n;
printf("%d",b);
}

}
}
else
{
printf("n out of the range\n");
}

}
偶自己写的程序,最后一个函数用的是Welton 呵呵。

2006-12-19 16:49
快速回复:考考你,同时也是作业. - -!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018721 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved