ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:1.07MB ,
资源ID:4591490      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4591490.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C语言程序设计结构体实验报告.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C语言程序设计结构体实验报告.docx

1、C语言程序设计结构体实验报告实 验 报 告 专业 软 件 工 程 班级 X 班 学号_ XXXXXXXXX_ 姓名 实验日期:201X年X月X日 报告退发 (订正 、 重做) 课程 C程序设计实验 实验名称 结 构 体 一、实验目的二、实验环境(描述实验的软件、硬件环境)1软件环境:windows xp/win7等操作系统,Microsoft Visual C+ 6.0编译器;2硬件环境:PC机一台三、实验内容、步骤和结果分析题目一:#include #include struct Stu int num; char name20; char sex; int age; float score

2、3;void fun(struct Stu *stu, int i) float sum = stu-score0 + stu-score1 + stu-score2, aeg = sum / 3.0; printf(n第%d位学生的基本信息如下:nn, i); printf(学号:(%d)t姓名:(%s)t性别:(%c)t年龄:(%d)nn, stu-num, stu-name, stu-sex, stu-age); printf(三科成绩:(%.2f,%.2f,%.2f)nn, stu-score0, stu-score1, stu-score2); printf(总成绩:(%.2f) 平

3、均成绩:(%.2f)n, sum, aeg); printf(n+n);int main() int i, n; printf(The number of students is:); scanf(%d, &n); struct Stu *stu = (struct Stu *)calloc(n, sizeof(struct Stu); for (i = 0; inum); printf(姓名:); scanf(%s, (stu + i)-name); printf(性别:); scanf( %c, &(stu + i)-sex); printf(年龄:); scanf(%d, &(stu +

4、 i)-age); printf(三科成绩:); scanf(%f%f%f, &(stu + i)-score0, &(stu + i)-score1, &(stu + i)-score2); putchar(n); printf(=n); for (i = 0; in; i+) fun(stu + i, i + 1); return 0;题目二:计算每一个结构体的两个变量所表示的长度之和(单位:厘米)要求:(1)分别定义公制METRIC(成员包括:米、厘米)和英制BRITISH(成员包括:英尺、英寸)两个结构体;(2)为每一个结构定义两个变量。#include int main() stru

5、ct METRIC float m; float cm; m1, m2; struct BRITISH float foot; float inches; b1, b2; printf(Enter the info of m1(米,厘米):); scanf(%f%f, &m1.m, &m1.cm); printf(Enter the info of m2(米,厘米):); scanf(%f%f, &m2.m, &m2.cm); printf(nEnter the info of m2(英尺,英寸):); scanf(%f%f, &b1.foot, &b1.inches); printf(Ent

6、er the info of m2(英尺,英寸):); scanf(%f%f, &b2.foot, &b2.inches); printf(nSum of m1 and m2 is:%.2f(厘米)n, (m1.m + m2.m) * 100 + m1.cm + m2.cm); printf(Sum of b1 and b2 is:%.2f(厘米)nn, (b1.inches + b2.inches)*30.48 + (b1.foot + b2.foot)*2.54); return 0;题目三:编写一个函数用于计算某个日期是相应年份的第几天要求:声明一个描述日期(年、月、日)的结构体类型。#

7、include struct time int year; int month; int day; ;void fun(struct time time) int a,b,sum=0; for(a=1;atime.month;a+) if(a=4|a=6|a=9|a=11) sum+=30; else if(a=2) if(time.year%4=0)&(time.year%100!=0|time.year%400=0) sum+=29; else sum+=28; else sum+=31; sum+=time.day; printf(%d-%d-%d 是该年的第 %d 天!nn,time.

8、year,time.month,time.day,sum);int main() struct time time; printf(Enter the date(Example:xxxx xx xx)(End with 0000 00 00):nn); while(scanf(%d%d%d,&time.year,&time.month,&time.day)!=EOF) if(time.year=0&time.month=0&time.day=0) break; fun(time); return 0;题目四:定义两个函数分别用于输入和输出N个STUDENT结构体变量的信息要求:定义两个结构体S

9、TUDENT和BIRTHDAY。 其中结构体STUDENT包含成员有:姓名(char name20),学号(int number),出生日期(BIRTHDAY birth);结构体BIRTHDAY包含的成员有:年份(int year),月份(int month)和日期(int day)。#include #include struct BIRTHDAY int year; int month; int day;struct STUDENT char name20; int number; struct BIRTHDAY birth;void input(struct STUDENT *stu,

10、int n) int i; putchar(n); for (i = 0; i n; i+) printf(第 %d 位学生的信息:n姓名:, i + 1); scanf(%s, stui.name); printf(学号:); scanf(%d, &stui.number); printf(生日:); scanf(%d-%d-%d, &stui.birth.year, &stui.birth.month, &stui.birth.day); if (i != n - 1) putchar(n); else printf(输入完毕!n); void output(struct STUDENT

11、*stu, int n) int i; for (i = 0; i n; i+) printf(n第 %d 位学生的信息如下:n, i + 1); printf(姓名:(%s)t学号:(%d)t生日:(%d-%d-%d)n, stui.name, stui.number, stui.birth.year, stui.birth.month, stui.birth.day); if (i != n - 1) putchar(n); else printf(输出完毕!n); int main() int n; printf(请输入待输入资料的学生的数目N:); scanf(%d, &n); str

12、uct STUDENT *stu = (struct STUDENT *)calloc(n, sizeof(struct STUDENT); input(stu, n); printf(=n); output(stu, n); printf(=n); return 0;题目五:函数sortInfo()是按照总成绩从高到低的顺序进行排序的。如果两位学生的总成绩相等,则按照学号从小到大排序。要求:1声明一个STUDENT结构体,成员有:姓名(char name20),学号(int number),总成绩(float totalScore)2在main函数中定义一个长度为N的结构体数组arr,调用函

13、数sortInfo(struct STUDENT *arr, int n)对N位学生的信息进行排序#include #include struct STUDENT char name20; int number; float totalScore;void input(struct STUDENT *stu,int n) int i; putchar(n); for (i = 0; i n; i+) printf(第 %d 位学生的基本信息:n姓名:, i + 1); scanf(%s, stui.name); printf(学号:); scanf(%d, &stui.number); pri

14、ntf(总成绩:); scanf(%f, &stui.totalScore); putchar(n); void sortInfo(struct STUDENT *stu, int n) int i,j; struct STUDENT temp; for (i = 0; i n; i+) for (j = 1; j n - i; j+) if (stui.totalScore (stui + j.number) temp = stui; stui = stui + j; stui + j = temp; void output(struct STUDENT *stu, int n) int i

15、; for (i = 0; i n; i+) printf(姓名:(%s)t学号:(%d)t总成绩:(%.2f)n, stui.name, stui.number, stui.totalScore); int main() int n; printf(请输入待输入资料的学生的数目N:); scanf(%d, &n); struct STUDENT *stu = (struct STUDENT *)calloc(n, sizeof(struct STUDENT); input(stu, n); printf(=n); printf(排序之前的初始状态:n); output(stu, n); pr

16、intf(=n); sortInfo(stu, n); printf(排序之后的最终状态:n); output(stu, n); printf(=n); return 0;题目六:编程模拟一个时钟(时间实时更新)要求:1声明一个时间结构体TIME,包含成员:时(int hour),分(int minute),秒(int second)。定义函数updata()用于更新时间。2假设当前时刻为23:59:59,则调用函数updata将得到的下一刻时间为00:00:00假设当前时刻为23:45:56,则调用函数updata将得到的下一刻时间为23:45:57#include #include str

17、uct TIME int hour; int minute; int second;updata(struct TIME *t) if (t-second = 59) t-second = 0; if (t-minute = 59) t-minute = 0; if (t-hour = 23) t-hour = 0; else (t-hour)+; else (t-minute)+; else (t-second)+;int main() struct TIME t; printf(请设定此刻时钟的时间(XX:XX:XX):); scanf(%d:%d:%d,&t.hour,&t.minute,&t.second); putchar(n); while (1) printf(%02d:%02d:%02dr, t.hour, t.minute, t.second); updata(&t); Sleep(1000); return 0;四、讨论

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1