已阅读5页,还剩15页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 面向对象程序设计 第7章自定义数据类型 2 本章内容 结构体的概念 定义 初始化 引用和赋值结构体数组指向结构体变量的指针结构体作为函数参数new和delete运算符 3 1 结构体 structStudent intnum stringname charsex intage floatscore stringaddress Studentstudent1 10001 ZhangXin M 19 90 5 Shanghai 类型定义 变量定义和初始化 4 结构体变量的另两种定义形式 structStudent intnum stringname charsex intage floatscore stringaddress student1 student2 struct intnum stringname charsex intage floatscore stringaddress student1 student2 形式一 形式二 5 结构体变量的引用和赋值 Students1 s2 s3 s1 s2 s1 num 10010 s3 score s1 score s2 score cout s1 num Students1 s2 s3 s1 10001 ZhangXin M 19 90 5 Shanghai s1 s2 s3 cout s1 正确 错误 6 举例7 1 P206 include include includeusingnamespacestd structStudent intID stringname stringsex floatscore intmain Studentstudent1 student2 10002 张三 女 89 5 student1 student2 cout 学号姓名性别成绩 endl cout setw 6 student1 ID cout setw 8 student1 name cout setw 6 student1 sex cout setw 6 student1 score endl return0 7 2 结构体数组 Studentstu 10101 LiLin M 18 87 5 103BeijingRoad 10102 ZhangFun M 19 99 130ShanghaiRoad 10104 WangMin F 20 78 5 1010ZhongshanRoad 8 举例7 1 2 接续例7 1 include include includeusingnamespacestd constintNUM STU 3 structStudent intID stringname stringsex floatscore intmain Studentstu NUM STU 10002 张三 女 89 5 10102 李四 男 99 10104 王五 男 78 5 cout 学号姓名性别成绩 endl for inti 0 i NUM STU i cout setw 6 stu i ID cout setw 8 stu i name cout setw 6 stu i sex cout setw 6 stu i score endl return0 9 3 指向结构体变量的指针 structStudent intnum stringname charsex intage floatscore stringaddress Studentstudent1 Student p 10 举例7 1 3 接续例7 1 2 链表结构 structStudent intID stringname stringsex floatscore Student pNext intmain Students1 10002 张三 女 89 5 NULL Students2 10102 李四 男 99 NULL Students3 10104 王五 男 78 5 NULL Student pHead p pHead 11 4 结构体作为函数参数 用结构体变量名作参数 用指向结构体变量的指针作参数 用结构体变量的引用作参数 12 举例7 5 P215 include includeusingnamespacestd structStudent intnum stringname floatscore 3 voidprint Studentstu cout stu num stu name stu score 0 stu score 1 stu score 2 endl intmain Studentstu stu num 12345 stu name LiFung stu score 0 67 5 stu score 1 89 stu score 2 78 5 print stu return0 用结构体变量名作参数 13 举例7 5 P215 include includeusingnamespacestd structStudent intnum stringname floatscore 3 voidprint Student p coutnumnamescore 0 score 1 score 2 endl intmain Studentstu stu num 12345 stu name LiFung stu score 0 67 5 stu score 1 89 stu score 2 78 5 print 用指针作参数 14 举例7 5 P215 include includeusingnamespacestd structStudent intnum stringname floatscore 3 voidprint Student intmain Studentstu stu num 12345 stu name LiFung stu score 0 67 5 stu score 1 89 stu score 2 78 5 print stu return0 用引用作参数 15 5 new和delete运算符 动态地分配和撤销内存空间 16 回顾 变量的存储区 inti 1 voidf inta cout i endl cout a endl intmain intj 2 intk 3 cout k endl f j return0 静态存储区 动态存储区 i 1 j 2 k 3 a 2 17 修正 C 的4个内存区间 inti 1 intmain intj 2 int p NULL p newint 10 if NULL p cout p 正确 输出10deletep cout p 错误return0 静态存储区 动态存储区堆 heap i 1 j 2 p NULL 代码区 栈Stack 未命名变量 10 18 举例7 6 P218 include includeusingnamespacestd structStudent stringname intnum charsex intmain Student p NULL p newStudent if NULL p p name WangFun p num 10123 p sex m coutnamenumsex endl deletep p NULL return0 19 举例7 1 4 接续例7 1 3 动态链表结构 structStudent intID stringname stringsex floatscore Student pNext intmain Student pHead NULL p coutpNext pHead pHead p cin pHead ID pHead name pHe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/SDMTGM 0005-2019绿色制造 闭式伺服压力机绿色设计导则
- T/ZNZ 300-2024诸暨水稻绿色生产技术规范
- T/CWAN 0195-2026钛合金蜂窝构件钎缝缺欠评价规范
- T/CSSC 004-202412345政务服务便民热线数据资产评估指南
- T/CSBM 0034-2023溶胶-凝胶法制备的硼硅酸盐生物活性玻璃原料
- T/CPIA 0091-2024温室气体 产品碳足迹量化方法与要求 光伏硅片
- T/CNCA 165-2025掘进机用机载悬臂式液压钻机
- T/CSAE 349-2024轮胎接地印迹形状通用试验方法
- T/ZSA 62-2019餐厨废弃物资源化还田项目温室气体减排量核算技术规范
- T/CGSS 041-2024老年安宁疗护服务规范
- (2026秋新版)部编版道德与法治四年级上册全册教案
- (2026秋新版)青岛版五年级数学上册全册教案(五四制)
- 第19课《培养德智体美劳全面发展的社会主义建设者和接班人》教学设计-2026-2027学年统编版九年级语文上册
- 2026年重庆市公务员真题和答案
- 2026年4月自考00037美学试题及答案含评分参考
- (新教材)2026年部编人教版一年级上册语文 6 j q x 课件
- 挖掘机租赁合同标准范本下载
- 减震垫片施工方案
- 责任心和执行力培训课件
- 2025年山西省教师职称考试(思想政治/道德与法治)历年参考题库含答案详解(5卷)
- 桉树买卖合同(2025版)
评论
0/150
提交评论