| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1156 人关注过本帖
标题:考考你,同时也是作业. - -!
只看楼主 加入收藏
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
 问题点数:0 回复次数:11 
考考你,同时也是作业. - -!
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
senyee
Rank: 1
等 级:新手上路
帖 子:422
专家分:0
注 册:2006-11-28
收藏
得分:0 

好象是十进制转换成N进制.........


菜鸟~~请多指教~~
2006-12-06 15:08
w362034710
Rank: 1
等 级:新手上路
帖 子:169
专家分:0
注 册:2006-12-2
收藏
得分:0 

# include<stdio.h>
void change(int n,int a);
char ch[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void main()
{
int n,a;
printf("input the number you want to change:\n"); /*输入要转换的十进制数*/
scanf("%d",&a);
printf("input the way of jinzhi:\n"); /*输入要转成的进制*/
scanf("%d",&n);
printf("the result is:\n");
change(n,a);
getch();
}
void change(int n,int a)
{
char b[80];
int m=20;
while(a)
{
b[--m]=ch[a%n];
a/=n;
}
b[20]='\0';
while(b[m])
{
printf("%c",b[m]);
m++;
}
}
最后一个题,,,

2006-12-06 19:07
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
得分:0 

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

2006-12-06 20:19
w362034710
Rank: 1
等 级:新手上路
帖 子:169
专家分:0
注 册:2006-12-2
收藏
得分:0 
a 是从文件里读取数据,,找出有字母字符来,,并且标明这个字母在26个字母中的排名(c和C排第三,返回3就是了),没有字母就返回-1
b 是定义三个变量,,一个字符,二个整型,字符从主函数接收要查找的字符,,并计数赋值给其中一个变量,另一个整型变量记录行数,
c 求正负数的N次方
d 将一个十进数转换成任意进制的数,,,
2006-12-06 22:56
Welton
Rank: 2
等 级:论坛游民
帖 子:65
专家分:38
注 册:2006-10-25
收藏
得分:0 

#include<math.h>
#include<stdio.h>
void showmenu();
void readfile();
int check(char a);
void print_letter(char a,int i,int j);
void to_base_n(float f,int n);
double power(double f,int n);
main()
{ char choice,a;
int i,j;
float f;
double g;
while(choice!='e')
{
showmenu();
fflush(stdin);
scanf("%c",&choice);
fflush(stdin);
if(choice=='a')
{
readfile();
printf("\n");
}
else if(choice=='b')
{
printf("Please input the arguments(a,i,j)\n");
scanf("%c %d %d",&a,&i,&j);
print_letter(a,i,j);
printf("\n");

}
else if(choice=='c')
{printf("Please input the arguments(g,n)\n");
scanf("%lf %d",&g,&i);
printf("\n%f",power(g,i));
printf("\n");
}
else if(choice=='d')
{
printf("Please input the arguments(f,n)\n");
scanf("%f %d",&f,&i);
to_base_n(f,i);
printf("\n");

}

}

}

void showmenu()
{

printf("a. judge character\tb. print character\nc. get a power\td. base_n\ne. exit/quit\n");

}
void readfile()
{char *file[20];
char a;
FILE *fp;
printf("Please input the file name\n");
scanf("%s",file);
fp=fopen(file,"r");
if(fp!=NULL){while(!feof(fp))
{
fscanf(fp,"%c",&a);
if(a>='A'&&a<='Z')
{
printf("%c is a letter.\t%d\n",a,check(a));
}
else if(a>='a'&&a<='z')
printf("%c is a letter.\t%d\n",a,check(a));
else
printf("%c isn\'t a letter\t%d",a,check(a));
}
fclose(fp);
}
else
printf("Fail to open the file\n");
}

/*我感觉这里不必要,但要求有个函数用字符作参数与上边函数结合*/
int check(char a)
{ if(a>='A'&&a<='Z')
{
return a-'A'+1;
}
else if(a>='a'&&a<='z')
return a-'a'+1;
else
return -1;

}
void print_letter(char a,int i,int j)
{
int p;
if(i!=0&&j!=0)
for(p=0;p<i*j;p++)
{
if(p!=0&&p%i==0)
printf("\n");
printf("%c ",a);

}
else
printf("ERROR!\n");
}

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");
}

}

double power(double f,int n)
{ int i,j;
double result=1;
if(n==0)
return 1;
if(f==0)
return 0;
j=abs(n);
for(i=0;i<j;i++)
result*=f;
if(n<0)
result=1/result;
return result;

}
有什么不正确的地方望指教。


只是喜欢编程而已!
2006-12-07 14:42
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
Welton
Rank: 2
等 级:论坛游民
帖 子:65
专家分:38
注 册:2006-10-25
收藏
得分:0 

这是我编译的,只要输入b回车后,输入字符,每行的个数,行数共三个参数,就可以了!


[IMG]http://blog.bc-cn.net/UploadFiles/2006-12/127782261.jpg[/IMG]

只是喜欢编程而已!
2006-12-07 21:57
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
得分:0 
我试了一下,Welton 写的程序A选项的功能好象不能用哦。能帮我解释一下A选项吗?
2006-12-12 17:19
快速回复:考考你,同时也是作业. - -!
数据加载中...
 
   



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

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