c程序设计 实验报告 第九章

上传人:xzh****18 文档编号:46717243 上传时间:2018-06-27 格式:PDF 页数:6 大小:191.28KB
返回 下载 相关 举报
c程序设计 实验报告 第九章_第1页
第1页 / 共6页
c程序设计 实验报告 第九章_第2页
第2页 / 共6页
c程序设计 实验报告 第九章_第3页
第3页 / 共6页
c程序设计 实验报告 第九章_第4页
第4页 / 共6页
c程序设计 实验报告 第九章_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《c程序设计 实验报告 第九章》由会员分享,可在线阅读,更多相关《c程序设计 实验报告 第九章(6页珍藏版)》请在金锄头文库上搜索。

1、 信息科学与工程学院 C 程序设计 实验报告 第九章 结构体和共用体 班级 信科 121 学号 12477218 姓名 孙剑峰 第九章第九章 结构体和共用体结构体和共用体 【实验目的】【实验目的】 1. 学习使用针对复杂对象的调试方法 2. 学习使用结构体和共用体的简单编程 【上机准备】【上机准备】 第一题:某系对某年级学生开出考试课程 10 门,考察课程 12 门,共计 22 门课 程。 每门课程的学时是 32,48,64,80 四种, 分别对应 2,3,4,5 个学分。 如附表。 考试课程的成绩是百分制成绩,而考察课程的成绩是 ABCDE 的级积分制。选 修该门课程并且成绩在分以上或者获得

2、 ABCD 的成绩的同学可以拿到学分。 在一学期内拿到个学分的同学可以参加综合测评。编写程序,输入该系某 班个同学各门功课成绩,并且依次对各门功课的选修同学的成绩做成绩排 序(该排序只列出有资格参加综合测评的同学) 。要求画出流程图,并设计一组 测试用例。 附:考试课程: 课程 学时 课程 学时 课程 学时 口语 英文写作 工程数学 数据库理论 控制理论 模拟电子 数字电路 电路分析 数据结构 操作系统 考察课程: 课程 学时 课程 学时 课程 学时 网页制作 制作 软件工程 编译原理 人工智能 网络原理 解析 信号处理 英文阅读 外国文化 社交礼节 第二题:通常复数具有两种表达形式,一种是笛

3、卡尔表达方式,一种是极坐标 表达方式。设计复数结构体,支持其中一种表达方式。设计一组函数,可以计 算复数的加法() ,减法() ,点乘() , 叉乘() ,输出() ,输入( ) ,由字符串识别()等功能。 【上机内容】【上机内容】 一、P8_1 #include #include #include #define N 30 struct kskc char name12; int grade; ; struct kckc char name12; int grade; ; void main() int i,j,k,m,p=0,q=0,scoreN=0,b,n,d1030; char a12

4、,c,e1230; struct kskc ks10=“口语口语“,80,“英文写作英文写作 “,64,“工程数学工程数学“,32,“数据库理论数据库理论“,48,“控制控制 理论理论“,48,“模拟电子模拟电子“,48,“数字电路数字电路“,48,“电电 路分析路分析“,48,“数据结构数据结构“,64,“操作系统操作系统“,48; struct kckc kc12=“C+“,48,“网页制作网页制作 “,32,“Flash 制作制作“,32,“软件工程软件工程“,32,“编译编译 原 理原 理 “,48,“ 人 工 智 能人 工 智 能 “,32,“ 网 络 原 理网 络 原 理 “,64

5、,“Unix 解析解析“,48,“信号处理信号处理“,48,“英文阅英文阅 读读“,32,“外国文化外国文化“,48,“社交礼节社交礼节“,32; struct kskc *ps=ks; struct kckc *pt=kc; printf(“请输入请输入 30 位同学各门功课成绩位同学各门功课成绩:n“); for(i=0;i=60) scorei+=ksk.grade/16; goto next1; printf(“输入有误输入有误 ,请重新输入请重新输入 n“); goto back1; next1:; system(“cls“); printf(“请输入第请输入第%d 位同学的考察课位

6、同学的考察课 程数目程数目:n“,i+1); scanf(“%d“, for(j=0;jscorej+1) n=scorej; scorej=scorej+1; scorej+1=n; printf(“有资格参加综合测评的同学的总成有资格参加综合测评的同学的总成 绩排序为绩排序为:“); for(i=0;i=22) printf(“%4dt“,scorei); for(i=0;iname); for(j=0;jname); for(j=0;j #include struct complexnum float real; float image; ; struct complexnum add(

7、struct complexnum a,struct complexnum b) struct complexnum c; c.real=a.real+b.real; c.image=a.image+b.image; return c; struct complexnum minus(struct complexnum a,struct complexnum b) struct complexnum c; c.real=a.real-b.real; c.image=a.image-b.image; return c; float dot_product(struct complexnum a,

8、struct complexnum b) float d; struct complexnum c; c.real=a.real*b.real-a.image*b.image; c.image=a.real*b.image+a.image*b.real; d=sqrt(c.real*c.real+c.image*c.image); return d; struct complexnum multiplication_cross(struct complexnum a,struct complexnum b) struct complexnum c; c.real=a.real*b.real-a

9、.image*b.image; c.image=a.real*b.image+a.image*b.real; return c; void main() float e; struct complexnum a,b,c,d,f; printf(“Please input the real part and the image part of complex number a:“); scanf(“%f %f“, printf(“Please input the real part and the image part of complex number b:“); scanf(“%f %f“,

10、 c=add(a,b); d=minus(a,b); e=dot_product(a,b); f=multiplication_cross(a,b); printf(“The real part and the image part after complex number a add complex number b are:n%.2f ,%.2fn“,c.real,c.image); printf(“The real part and the image part after complex number a minus complex number b are:n%.2f ,%.2fn“

11、,d.real,d.image); printf(“The value after complex number a dot product complex number b is:n%.2f n“,e); printf(“The real part and the image part after complex number a multiplication_cross complex number b are:n%.2f ,%.2fn“,f.real,f.image); 错误记录:错误记录:1、函数返回结构体的用法使用错误。2、输出时变量类型用错。 运行结果:运行结果: 输入:1 2 3

12、 4 输出: Please input the real part and the image part of complex number a:1 2 Please input the real part and the image part of complex number b:3 4 The real part and the image part after complex number a add complex number b are: 4.00 ,6.00 The real part and the image part after complex number a minu

13、s complex number b are: -2.00 ,-2.00 The value after complex number a dot product complex number b is: 11.18 The real part and the image part after complex number a multiplication_cross complex number b are: -5.00 ,10.00 【上机小结】【上机小结】 结构体和共用体是很有用的 C 语言工具,可以用来绘制简单的表格。通过本章学习,我掌握了使用结构体和共用体进行简单的编程,有很大收获。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号