




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验七 结构体和共用体实验课程名: C语言程序设计专业班级: 15级工管1班 学号: 201540620104 姓名: 张润泽 实验时间: 12.1912.23 实验地点: k4508 指导教师: 吴桂芳 一、实验目的及要求1. 掌握结构体类型变量的定义和使用;2. 掌握结构体类型数组的概念和使用;3. 掌握链表的概念,初步学会对链表进行操作;4. 掌握共用体的概念与使用。二、实验内容1、编写input()和output()函数,输入,输出5个学生的数据记录。程序源代码如下:#define N 5struct studentchar num6;char name8;int score4;stu
2、N;input(struct student stu)int i,j;for(i=0;iN;i+)printf(n please input %d of %dn,i+1,N);printf(num: );scanf(%s,stui.num);printf(name: );scanf(%s,);for(j=0;j3;j+)printf(score %d.,j+1);scanf(%d,&stui.scorej);printf(n);print(struct student stu)int i,j;printf(nNo. Name Sco1 Sco2 Sco3n);for(i=0;
3、iN;i+)printf(%-6s%-10s,stui.num,);for(j=0;j3;j+)printf(%-8d,stui.scorej);printf(n);void main()input();print();解答:(1) 运行结果:(2)(2)运行结果分析: 运行结果正确。2、有5个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入5个学生数据,要求打印出3门课总平均成绩,以及及最高分的学生的数据(包括学号、姓名、3门课的成绩、平均分数)。程序源代码如下:#define N 5struct studentchar num 6 ;char name 8 ;
4、int score 4 ;float avr;stuN;void main()int i,j,max,maxi,sum;float average;for(i=0;iN;i+)printf(n please input %d of %dn,i+1,N);printf(num: );scanf(%s,stui.num);printf(name: );scanf(%s,);for(j=0;j3;j+)printf(score %d.,j+1);scanf(%d,&stui.scorej);printf(n);average=0;max=0;maxi=0;for(i=0; iN;
5、i+ )sum = 0;for( j=0; j max ) max=sum; maxi=i; average/=N;printf(nNo. Name Sco1 Sco2 Sco3 averagen); /*print*/for(i=0; iN; i+)printf(%-8s%-10s,stu i .num, stu i .name);for( j=0; j3; j+ )printf (%-8d, stu i .score j );printf ( %6.2f n , stu i .avr);printf (average is %5.2fn,average);printf (The best
6、student is %s, total score is %d.,,max);解答:(1) 运行结果: (2)运行结果分析:运行结果正确。3、使用结构体类型数组编写一个程序用来输入并显示教师的基本情况信息。教师的基本情况信息包括:姓名、性别、出生年月日、住址、电话、月收入。要求使用嵌套的结构体类型表示出生年月日,模拟输如下列两个教师的信息,并按下列格式输出在屏幕上。 姓名 性别 出生日期 住址 电话 月收入 1. 李四 女 1965年5月8日 莲花小区6号 7432156 1200.00 2. 王五 男 1972年8月9日 和平里12号 8654367 950.00解
7、答:(1)源代码:#include#includestruct data int year; int month; int day;struct techer/结构体变量 char name20;/姓名 char sex4;/性别 struct data birthday;/出生日期 char addr100; int tel; float revenue;techers100;int main() char in; int count = 0,i = 0; while (1) printf(请输入教师信息,确认按y,取消按n:); scanf( %c,&in); if (in = y) |
8、(in = Y) printf(请输入教师姓名:); scanf( %s, ); printf(请输入教师性别:); scanf( %s, techerscount.sex); printf(请输入教师出生日期(格式:xxxx.xx.xx):); scanf(%d.%d.%d, &techerscount.birthday.year, &techerscount.birthday.month, &techerscount.birthday.day); printf(请输入教师住址:); scanf( %s, techerscount.addr); printf
9、(请输入教师电话:); scanf(%d, &techerscount.tel); printf(请输入教师收入:); scanf(%f, &techerscount.revenue); count+; else break; printf( 姓名t性别t出生日期t住址tt电话t 月收入n); for (i = 0; i count; i+) printf(%d. %st%st%d年%d月%d日t%st%dt %.2fn ,i+1 ,, techersi.sex , techersi.birthday.year, techersi.birthday.month, techersi.birthday.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO 5821:2025 EN Resistance welding - Spot welding electrodes - Female electrode caps
- 【正版授权】 ISO/IEC TR 23090-27:2025 EN Information technology - Coded representation of immersive media - Part 27: Media and architectures for render-based systems and applications
- 【正版授权】 ISO/TR 4752:2025 EN Biotechnology - Inventory of methods for detection of microbiological contamination in mammalian cell culture
- 【正版授权】 ISO 11680:2025 EN Machinery for forestry - Safety requirements and testing for portable pole mounted powered pruners
- 【正版授权】 ISO 13400-2:2025 EN Road vehicles - Diagnostic communication over Internet Protocol (DoIP) - Part 2: Transport protocol and network layer services
- 古筝课件教学计划
- 2020-2025年期货从业资格之期货法律法规全真模拟考试试卷B卷含答案
- 【深圳】2025年4月广东深圳光明区政务服务和数据管理局招聘一般类岗位专干5人笔试历年典型考题及考点剖析附带答案详解
- 电位滴定法仪器分析测试技术系列32课件
- Brand KPIs for milk:a2 in the United States-英文培训课件2025
- 2025年广东省深圳市中考历史试卷(含解析)
- 百万销售日常管理办法
- 天津市南开区2024-2025学年七年级下学期期末考试数学试卷及答案
- 安全培训-重大事故隐患判定标准-专家版
- 2025年数据科学与大数据技术试题及答案
- 土木工程结构力学课件
- 【课件】《科学记数法》说课课件2024-2025学年人教版数学七年级上册
- 消防检测和消防评估服务方案
- 旧钢板桩买卖合同范本
- 安卓课程设计开发指南
- 健康服务合作协议书
评论
0/150
提交评论