![](https://lstatic.shangxueba.com/sxbzda/h5/images/m_q_title.png)
设有一结构体类型变量定义如下,若对结构体变量w1的出生年份year进行赋值,下面正确的赋值语句是()。 struct date { int year; int month; int day; }; struct worker { char name[20]; char sex; struct date birthday; }w1;
A.year=1976
B.birthday.year=1976
C.w1.birthday.year=1976
D.w1.year=1976
![](https://lstatic.shangxueba.com/sxbzda/h5/images/tips_org.png)
A.year=1976
B.birthday.year=1976
C.w1.birthday.year=1976
D.w1.year=1976
第1题
A、year = 2015
B、birthday.year = 2015
C、stu.birthday.year = 2015
D、stu.year = 2015
第2题
A、stu.stuName = "xiaoming"
B、stu.stuName[10] = "xiaoming"
C、stuName = "xiaoming"
D、strcpy(stu.stuName,"xiaoming")
第3题
A、year=1958
B、birthday.year=1958
C、person.birthday.year=1958
D、person.year=1958
第4题
实验十二 C程序的结构体 一、实验目的 1. 掌握结构体的概念和特点。 2. 熟练定义结构体数据类型,掌握结构体变量的定义及使用方法。 3. 了解结构体数组的特点,能使用结构体数组解决简单问题。 4. 掌握结构体指针的特点,能使用结构体指针作函数的参数。 二、实验内容及实验步骤 1. 用结构体类型实现“日期问题”。日期问题:已知一个日期(包括年、月、日),编写程序,计算这一天是这一年的第几天。 参考程序 /* 用结构体类型实现的日期问题程序 */ #include "stdio.h" struct date /* 定义结构体数据类型 */ { int year; int month; int day; }; main() { struct date d; int sum=0; printf("请输入日期(年、月、日之间用空格分隔):\n"); scanf("%d%d%d",&d.year,&d.month,&d.day); switch(d.month) { case 1:sum=0;break; case 2:sum=31;break; case 3:sum=31+28;break; case 4:sum=31+28+31;break; case 5:sum=31+28+31+30;break; case 6:sum=31+28+31+30+31;break; case 7:sum=31+28+31+30+31+30;break; case 8:sum=31+28+31+30+31+30+31;break; case 9:sum=31+28+31+30+31+30+31+31;break; case 10:sum=31+28+31+30+31+30+31+31+30;break; case 11:sum=31+28+31+30+31+30+31+31+30+31;break; case 12:sum=31+28+31+30+31+30+31+31+30+31+30;break; } sum+=d.day; /* 天数累加 */ if(d.month>2) /* 闰年处理 */ if(d.year%400==0||d.year%100!=0&&d.year%4==0) sum+=1; printf("Total: %d\n",sum); } 程序调试: ① 运行程序,输入一个合法日期数据,察看并分析程序结果。 ② 运行程序,输入一个月份非法的日期数据,察看并分析程序结果。 ③ 运行程序,输入一个日子非法的日期数据,察看并分析程序结果。 ④ 完善程序,使得在任何情况下,都能输出一个合理的结果。 ⑤ 用结构体指针改写上面的程序。 2. 学生成绩问题。有10个学生,每个学生的数据包括学号、姓名、3门课的成绩。从键盘输入10个学生数据,要求打印出每门课的总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课的成绩、平均分数)。 参考程序 /* 学生成绩问题程序 */ #include "stdio.h" #define N 10 struct student /* 定义结构体数据类型 */ { char num[5]; /* 学号(不超过4位) */ char name[10]; /* 姓名(不超过9位) */ int score1; /* 成绩1 */ int score2; /* 成绩2 */ int score3; /* 成绩3 */ }; main() { struct student stu[N]; /* 定义结构体数组 */ int max=0,sum1=0,sum2=0,sum3=0; int i,k=0,total,ave1,ave2,ave3,average; for(i=0;i<n;i++) * 输入学生数据,并进行成绩统计 { printf("no.%d: \n",i+1); printf("enter num:"); gets(stu[i].num); name:"); gets(stu[i].name); score1,score2,score3:"); scanf("%d,%d,%d",&stu[i].score1,&stu[i].score2, &stu[i].score3); getchar(); total="stu[i].score1+stu[i].score2+stu[i].score3;" sum1+="stu[i].score1;" sum2+="stu[i].score2;" sum3+="stu[i].score3;" if(total>max) { max=total; k=i; } /* 第k个结构体元素为最高分学生数据 */ } ave1=sum1/N; ave2=sum2/N; ave3=sum3/N; average=(stu[k].score1+stu[k].score2+stu[k].score3)/3; printf("The average score of this class are:\n"); printf("score1=%d, score2=%d, score3=%d\n",ave1,ave2,ave3); printf("The student of maxscore is:\n"); printf("num:%s,name:%s,score1:%d,score2:%d,score3:%d,average:%d\n", stu[k].num,stu[k].name,stu[k].score1,stu[k].score2,stu[k].score3,average); } 程序调试: 先用三个学生的数据调试程序(将程序中符号常量N定义为3): ① 运行程序,输入三个学生的数据:学号不超过4字符,以回车键结束;姓名不超过9字符,以回车键结束;成绩数据之间用逗号分隔,以回车键结束。察看并分析程序结果。 ② 运行程序,输入的学号或姓名信息超过规定长度,察看并分析程序结果。用三个学生的数据调试通过后,再用10个学生数据进行测试。 三、实验报告要求 写明: 1. 实验目的 2. 实验内容与步骤 3. 编写的程序(题目,经调试、运行后正确的程序) 4. 思考题的解决方法。 5. 总结讨论本次实验的结果和收获。
第5题
A、year=2014
B、birthday.year=2014
C、person.birthday.year=2014
D、person.year=2014
第6题
struct DATE { int year;int month; int day;};
请写出一条定义语句,该语句定义 d 为上述结构体 类型 变量,并同时为其成员 year 、 month 、 day 依次赋初值 2006 、 10 、 1 : 【 19 】 。
第7题
struct DATE{int year;int month; int day;};
请写出一条定义语句,该语句定义d为上述结构体变量,并同时为其成员year、month、day 依次赋初值2006、10、1:_________;
第9题
B.birthday.year=1958;
C.person.birthday.year=1958;
D.person.year=1958;
第10题
A、定义了结构体类型名type_date
B、定义了结构体变量type_date
C、定义了结构体type_date
D、这个定义是错误的
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!