C语言程序设计精编教程 教学课件 ppt 作者 陈正权 岳睿 第9章 结构体与共用体

上传人:E**** 文档编号:89351264 上传时间:2019-05-23 格式:PPT 页数:57 大小:2.37MB
返回 下载 相关 举报
C语言程序设计精编教程 教学课件 ppt 作者  陈正权 岳睿 第9章 结构体与共用体_第1页
第1页 / 共57页
C语言程序设计精编教程 教学课件 ppt 作者  陈正权 岳睿 第9章 结构体与共用体_第2页
第2页 / 共57页
C语言程序设计精编教程 教学课件 ppt 作者  陈正权 岳睿 第9章 结构体与共用体_第3页
第3页 / 共57页
C语言程序设计精编教程 教学课件 ppt 作者  陈正权 岳睿 第9章 结构体与共用体_第4页
第4页 / 共57页
C语言程序设计精编教程 教学课件 ppt 作者  陈正权 岳睿 第9章 结构体与共用体_第5页
第5页 / 共57页
点击查看更多>>
资源描述

《C语言程序设计精编教程 教学课件 ppt 作者 陈正权 岳睿 第9章 结构体与共用体》由会员分享,可在线阅读,更多相关《C语言程序设计精编教程 教学课件 ppt 作者 陈正权 岳睿 第9章 结构体与共用体(57页珍藏版)》请在金锄头文库上搜索。

1、 ,:,9.1 -,9.1.1 ,struct . ,struct, :, struct student int num; char name10; char sex; int age; float score; char addr30; ;, ,struct . struct ,9.2 (1) , struct student int num; char name10; char sex; int age; float score; char addr30; ; struct student stu1,stu2;,(2) ,struct . , struct student int num;

2、 char name20; char sex; int age; float score; char addr30; stu1,stu2;,(3) ,struct . , struct int num; char name10; char sex; int age; float score; char addr30; stu1,stu2;, , 1. :棻 : :; :, 2. 3.,9.1.3 , ., struct student int num; char name20; char sex; int age; float score; char addr30; stu1,stu2;,st

3、u1.num=10;,stu1.score=85.5;,stu1.score+=stu2.score; stu1.age+;,() : 1 :, , ,stu1.birthday.month=12;, ,struct . struct =, struct student int num; char name20; char sex; int age; char addr30; ; struct student stu1=112,Wang Lin,M,19, 200 Beijing Road;,struct . =, struct student int num; char name20; ch

4、ar sex; int age; char addr30; stu1=112,Wang Lin,M,19, 200 Beijing Road;,struct . =, struct int num; char name20; char sex; int age; char addr30; stu1=112,Wang Lin,M,19, 200 Beijing Road;,9.2 ,: struct student int num; char name20; char sex; int age; ; struct student stu2;,: struct student int num; c

5、har name20; char sex; int age; stu2;,: struct int num; char name20; char sex; int age; stu30;, struct int num; char name20; char sex; int age; stu =,;,: struct student int num; char name10; char sex; int age; ; struct student stu =100,Wang Lin,M,20, 101,Li Gang,M,19, 110,Liu Yan,F,19;, struct studen

6、t int num; char name10; char sex; int age; float score; stu =,;, .,1 4,struct student int num; char name10; char sex; int age; float score; struct student stu4- ,void main() int i;float a,s; for(i=0;i4;i+) a=a+stui.age s=s+stui.score printf(4a/4 ,2. struct STU int num; float Total; ; void f(struct S

7、TU p) struct STU s2=20044,550,20045,537; p.num = s1.num; p.Total = s1.Total; void main() struct STU s2=20041,703,20042,580; f(s0); printf(%d %3.0fn, s0.num, s0.Total); _ A20045 537 B20044 550 C20042 580 D20041 703,D, ,9.3 struct *; struct student *p;, int n; int *p= ? n=10,struct student stu1; struc

8、t student *p= ? (*p).num=101,(*).,-,., : 1 򣺴,void main() struct student long int num; char name20; char sex; float score; stu,*p; p= , ,struct student int num; char name20; char sex; int age; stu3=10101,Li Lin,M,18, 10102,Zhang Fun,M,19, 10104,Wang Min,F,20; void main() struct student *p; fo

9、r(p=stu; pnum, p-name, p-sex,p-age); ,p-n p-n+ +p-n,pn,pn, 1,pn1, ,1: struct ord int x,y; dt2=1,2,3,4; void main() struct ord *p=dt; printf(%d,+p-x); printf(%dn,+p-y); A)1,2 B)2,3 C)3,4 D)4,1,B,2. struct A int a; char b10;double c; void f(struct A *t); void main() struct A a=1001,ZhangDa,1098.0; f(,

10、1. :stu1.numstu2.num,. 2. 3.飩飩,Nstu33,#include #define N 3 struct student int num; char name20; float score3; float aver; ;,void main() void input(struct student stu ); struct student max(struct student stu ); void print(struct student stu); struct student stuN,*p=stu; input(p); print(max(p); ,void

11、input(struct student stu ) int i; for(i=0;iN;i+) scanf(%d %s %f %f %f, ,struct student max(struct student stu ) int i,m=0; for(i=0;istum.aver) m=i; return stu(m); void print(struct student stud) printf(%d,%s,%5.1f,%5.1f,%5.1f,:%6.2fn, stud.num,stud.name, stud.score0, stud.score1, stud.score2, stud.a

12、ver); , ,: , 塱.,干 union ,磺 union data union data int i int i; char ch char ch; float f float f a,b,c; ; union data a,b,c;,11-24, 1.泤泤 浥 2.泤 ,:涨塱 , ,:涨abc a.i 飩 a.ch裩 a.f 棩, 9.4 ,9.4.1 ,洢 ,11-10,彨 struct student int num float score struct student *next ; numscorenextstruct studentnext,11-11,9.4.2 ,#d

13、efine NULL 0 struct student long num; float score; struct student *next; ;, 1010189.5 1010390.0 1010785.0,void main() struct student a,b,c,*head,*p; a. num=99101; a.score=89.5; b. num=99103; b.score=90; c. num=99107; c.score=85; head= ,9.4.3 2,#include #include #define LEN sizeof(struct student) str

14、uct student int num; float score; struct student *next; ;,void main() struct student *head,*p; head=p=(struct student*)malloc(LEN); scanf(%d,%f, , ,11-19, ,1壬 struct node int data; struct node *next; *p,*q,*r; data next data next data next p q r q_ Ap-next=q-next; Bp-next=p-next-next; Cp-next=r; Dp=

15、q-next;,D,(),: typedef,typedef : typedef ;,INTEGER typedef int INTEGER typedef struct int month int day int yearDATE;, typedef (2) typedef (3) typedef #include (4) typedef, (5) typedef#define磺 typedef int COUNT#define COUNT int COUNTint #define򵥵 滻typedef 򵥵滻 ,1 typedef struct ST long

16、a;int b;char c2;NEW; _ A BST CNEW DNEW,C,2td_ Atypedef struct aa Bstruct aa int n; int n; float m; float m; AA; td; AA td; struct aa td; Cstruct Dstruct int n; int n; float m; float m; aa; td; struct aa td;,C,3 Atypedef struct Bstruct REC; int n; char c;REC; int n; char c; REC t1,t2; REC t1,t2; Ctypedef struct REC ; int n=0; char c=A;t1,t2; Dstruct int n;char c;REC t1,t2;,(4) ,_ #include typedef struct int num;double s; REC; void fun1(REC x) x.num=23;x.s=88.5; main( ) REC a=16,90.0; fun1(a); printf(%dn,a.num); ,

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

当前位置:首页 > 高等教育 > 大学课件

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