哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx

上传人:b****0 文档编号:17862532 上传时间:2023-08-04 格式:DOCX 页数:15 大小:17.76KB
下载 相关 举报
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第1页
第1页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第2页
第2页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第3页
第3页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第4页
第4页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第5页
第5页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第6页
第6页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第7页
第7页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第8页
第8页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第9页
第9页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第10页
第10页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第11页
第11页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第12页
第12页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第13页
第13页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第14页
第14页 / 共15页
哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx

《哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx》由会员分享,可在线阅读,更多相关《哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx(15页珍藏版)》请在冰点文库上搜索。

哈尔滨工业大学C语言MOOC第12周编程题在线测试.docx

哈尔滨工业大学C语言MOOC第12周编程题在线测试

第12周编程题在线测试

1计算时间差V2.0(4分)

题目内容:

用结构体定义时钟类型,编程从键盘任意输入两个时间(例如4时55分和1时25分),计算并输出这两个时间之间的间隔。

要求不输出时间差的负号。

结构体类型定义如下:

typedefstructclock

{

inthour;

intminute;

intsecond;

}CLOCK;

函数原型:

CLOCKCalculateTime(CLOCKt1,CLOCKt2);

函数功能:

计算并返回两个时间t1和t2之间的差

程序运行结果示例1:

Inputtimeone:

(hour,minute):

4,55↙

Inputtimetwo:

(hour,minute):

1,25↙

3hour,30minute

程序运行结果示例2:

Inputtimeone:

(hour,minute):

1,33↙

Inputtimetwo:

(hour,minute):

5,21↙

3hour,48minute

输入提示:

"Inputtimeone:

(hour,minute):

"

"Inputtimetwo:

(hour,minute):

"

输入格式:

"%d,%d"

输出格式:

"%dhour,%dminute\n"

代码:

#include

#include

#include

#include

typedefstructclock

{

inthour;

intminute;

intsecond;

}CLOCK;

CLOCKCalculateTime(CLOCKt1,CLOCKt2);

intmain()

{

CLOCKc1;

CLOCKc2;

printf("Inputtimeone:

(hour,minute):

");

scanf("%d,%d",&c1.hour,&c1.minute);

printf("Inputtimetwo:

(hour,minute):

");

scanf("%d,%d",&c2.hour,&c2.minute);

CLOCKc=CalculateTime(c1,c2);

printf("%dhour,%dminute\n",c.hour,c.minute);

return0;

}

CLOCKCalculateTime(CLOCKt1,CLOCKt2)

{

longstart=t1.hour*60+t1.minute;

longend=t2.hour*60+t2.minute;

longdelta=abs(end-start);

CLOCKc={delta/60,delta%60};

returnc;

}

2奖学金发放(4分)

题目内容:

某校的惯例是在每学期的期末考试之后发放奖学金。

发放的奖学金共有五种,每项奖学金获取的条件分别如下:

1)院士奖学金:

期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生每人均可获得8000元;

2)五四奖学金:

期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生每人均可获得4000元;

3)成绩优秀奖:

期末平均成绩高于90分(>90)的学生每人均可获得2000元;

4)西部奖学金:

期末平均成绩高于85分(>85)的西部省份学生每人均可获得1000元;

5)班级贡献奖:

班级评议成绩高于80分(>80)的学生干部每人均可获得850元;

只要符合上述条件就可获得相应的奖项,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。

例如姚明的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金和班级贡献奖,奖金总数是4850元。

现在给出若干学生的相关数据(假设总有同学能满足获得奖学金的条件),请编程计算哪些同学获得的奖金总数最高。

结构体类型定义如下:

typedefstructwinners

{

charname[20];

intfinalScore;

intclassScore;

charwork;

charwest;

intpaper;

intscholarship;

}WIN;

函数原型:

voidAddup(WINstu[],intn);

函数原型:

intFindMax(WINstudent[],intn);

程序运行结果示例:

Inputn:

4↙

Inputname:

YaoMing↙

Inputfinalscore:

87↙

Inputclassscore:

82↙

Classcadreornot?

(Y/N):

Y↙

StudentsfromtheWestornot?

(Y/N):

N↙

Inputthenumberofpublishedpapers:

0↙

name:

YaoMing,scholarship:

4850

Inputname:

ChenRuiyi↙

Inputfinalscore:

88↙

Inputclassscore:

78↙

Classcadreornot?

(Y/N):

N↙

StudentsfromtheWestornot?

(Y/N):

Y↙

Inputthenumberofpublishedpapers:

1↙

name:

ChenRuiyi,scholarship:

9000

Inputname:

LiXin↙

Inputfinalscore:

92↙

Inputclassscore:

88↙

Classcadreornot?

(Y/N):

N↙

StudentsfromtheWestornot?

(Y/N):

N↙

Inputthenumberofpublishedpapers:

0↙

name:

LiXin,scholarship:

6000

Inputname:

ZhangQin↙

Inputfinalscore:

83↙

Inputclassscore:

87↙

Classcadreornot?

(Y/N):

Y↙

StudentsfromtheWestornot?

(Y/N):

N↙

Inputthenumberofpublishedpapers:

1↙

name:

ZhangQin,scholarship:

8850

ChenRuiyigetthehighestscholarship9000

输入学生人数提示:

"Inputn:

"

输入学生姓名提示:

"Inputname:

"

输入学生期末平均成绩提示:

"Inputfinalscore:

"

输入学生班级评议成绩提示:

"Inputclassscore:

"

输入是否为学生干部提示:

"Classcadreornot?

(Y/N):

"

输入是否为西部学生提示:

"StudentsfromtheWestornot?

(Y/N):

"

输入发表文章数量提示:

"Inputthenumberofpublishedpapers:

"

输入格式:

输入学生人数:

"%d"

输入学生姓名:

"%s"

输入学生成绩:

"%d"

输入是否为学生干部:

"%c"(注意:

%c前面有一个空格)

输入是否为西部学生:

"%c"(注意:

%c前面有一个空格)

输入发表文章数量:

"%d"

输出格式:

输出学生获得的奖学金:

"name:

%s,scholarship:

%d\n"

输出获得奖学金总数最高的学生:

"%sgetthehighestscholarship%d\n"

代码:

#include

typedefstructwinners

{

charname[20];

intfinalScore;

intclassScore;

charwork;

charwest;

intpaper;

intscholarship;

}WIN;

main(){

inti,count=0,n,s;

WINstu[100];

printf("Inputn:

");

scanf("%d",&n);

s=n;

while(n--)

{

stu[count].scholarship=0;

printf("Inputname:

");

scanf("%s",&stu[count].name);

printf("Inputfinalscore:

");

scanf("%d",&stu[count].finalScore);

printf("Inputclassscore:

");

scanf("%d",&stu[count].classScore);

printf("Classcadreornot?

(Y/N):

");

scanf("%c",&stu[count].work);

printf("StudentsfromtheWestornot?

(Y/N):

");

scanf("%c",&stu[count].west);

printf("Inputthenumberofpublishedpapers:

");

scanf("%d",&stu[count].paper);

if(stu[count].finalScore>90)

{

stu[count].scholarship+=2000;

}

if(stu[count].finalScore>85&&stu[count].classScore>80)

{

stu[count].scholarship+=4000;

}

if(stu[count].classScore>80)

{

if(stu[count].work!

=78)

{

stu[count].scholarship+=850;

}

}

if(stu[count].finalScore>85)

{

if(stu[count].west!

=78){

stu[count].scholarship+=1000;

}

}

if(stu[count].finalScore>80&&stu[count].paper)

{

stu[count].scholarship+=8000;

}

printf("name:

%s,scholarship:

%d\n",stu[count].name,stu[count].scholarship);

count++;

}

intmax;

count=0;

max=stu[0].scholarship;

for(i=0;i

{

if(max

{

max=stu[i].scholarship;

count=i;

}

}

printf("%sgetthehighestscholarship%d\n",stu[count].name,max);

}

3评选最牛群主v1.0(4分)

题目内容:

现在要评选最牛群主,已知有3名最牛群主的候选人(分别是tom,jack和rose),有不超过1000人参与投票,最后要通过投票评选出一名最牛群主,从键盘输入每位参与投票的人的投票结果,即其投票的候选人的名字,请你编程统计并输出每位候选人的得票数,以及得票数最多的候选人的名字。

候选人的名字中间不允许出现空格,并且必须小写。

若候选人名字输入错误,则按废票处理。

程序运行结果示例1:

Inputthenumberofelectorates:

8↙

Inputvote1:

tom↙

Inputvote2:

jack↙

Inputvote3:

rose↙

Inputvote4:

tom↙

Inputvote5:

rose↙

Inputvote6:

rose↙

Inputvote7:

jack↙

Inputvote8:

rose↙

Electionresults:

tom:

2

jack:

2

rose:

4

rosewins

程序运行结果示例2:

Inputthenumberofelectorates:

5↙

Inputvote1:

tom↙

Inputvote2:

mary↙

Inputvote3:

rose↙

Inputvote4:

jack↙

Inputvote5:

tom↙

Electionresults:

tom:

2

jack:

1

rose:

1

tomwins

提示输入候选人数量:

"Inputthenumberofelectorates:

"

提示输入候选人:

"Inputvote%d:

"

输入格式:

输入候选人数量:

"%d"

输入候选人姓名:

"%s"

输出格式:

输出候选人得票数:

"%s:

%d\n"

输出票数最多的候选人姓名:

"%swins\n"

输出评选结果提示信息:

"Electionresults:

\n"

代码:

#include

intmain()

{

intn,i,vote1=0,vote2=0,vote3=0;

charname[10];

printf("Inputthenumberofelectorates:

");

scanf("%d",&n);

for(i=0;i

{

printf("Inputvote%d:

",i+1);

scanf("%s",name);

if(strcmp("tom",name)==0)

{

vote1++;

}

elseif(strcmp("jack",name)==0)

{

vote2++;

}

elseif(strcmp("rose",name)==0)

{

vote3++;

}

}

printf("Electionresults:

\n");

printf("%s:

%d\n","tom",vote1);

printf("%s:

%d\n","jack",vote2);

printf("%s:

%d\n","rose",vote3);

if(vote1>vote2&&vote1>vote3)

{

printf("%swins\n","tom",vote1);

}

elseif(vote2>vote1&&vote2>vote3)

{

printf("%swins\n","jack",vote2);

}

else

{

printf("%swins\n","rose",vote3);

}

return0;

}

4.星期判断(4分)

题目内容:

请输入星期几的第一个字母(不区分大小写)来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母(小写),否则输出“dataerror”。

程序运行结果示例1:

pleaseinputthefirstletterofsomeday:

S↙

pleaseinputsecondletter:

u↙

sunday

程序运行结果示例2:

pleaseinputthefirstletterofsomeday:

F↙

friday

程序运行结果示例2:

pleaseinputthefirstletterofsomeday:

h↙

dataerror

第一个字母的输入提示信息:

"pleaseinputthefirstletterofsomeday:

\n"

第二个字母的输入提示信息:

"pleaseinputsecondletter:

\n"

用户输入错误提示信息:

"dataerror\n"

输入格式:

"%c"(注意:

%c前面有一个空格)

输出格式:

星期一:

"monday\n"

星期二:

"tuesday\n"

星期三:

"wednesday\n"

星期四:

"thursday\n"

星期五:

"friday\n"

星期六:

"saturday\n"

星期日:

"sunday\n"

代码:

#include

#include

#include

#include

#include

intmain()

{

chara;

charb;

charday[7][10]={"monday","tuesday","wednesday","thursday","friday","saturday","sunday"};

printf("pleaseinputthefirstletterofsomeday:

\n");

scanf("%c",&a);

a=tolower(a);

intret[7]={0};

inti=0;

intcount=0;

for(i=0;i<7;i++){

if(day[i][0]==a){

ret[count]=i;

count++;

}

}

if(count==0){

printf("dataerror\n");

exit(0);

}

printf("pleaseinputsecondletter:

\n");

scanf("%c",&b);

b=tolower(b);

intflag=0;

for(i=0;i

if(day[ret[i]][1]==b){

printf("%s\n",day[ret[i]]);

flag=1;

break;

}

}

if(!

flag){

printf("dataerror\n");

}

return0;

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2