结构(9.1 构建手机通讯录 9.2 结构变量 9.3 结构数组 9.4 结构指针)

Chap9结构 9.1构建手机通讯录 92结构变量 93结构数组 94结构指针
Chap 9 结构 9.1 构建手机通讯录 9.2 结构变量 9.3 结构数组 9.4 结构指针

本章要点 ■什么是结构?结构与数组有什么差别? 有几种结构的定义形式,它们之间有什么不同? ■什么是结构的嵌套? 什么是结构变量和结构成员变量,如何引用结构 成员变量? ■结构变量如何作为函数参数使用? ■什么是结构数组,如何定义和使用结构数组? 什么是结构指针,它如何实现对结构分量的操作? ■结构指针是如何作为函数的参数的?
本章要点 ◼ 什么是结构?结构与数组有什么差别? ◼ 有几种结构的定义形式,它们之间有什么不同? ◼ 什么是结构的嵌套? ◼ 什么是结构变量和结构成员变量,如何引用结构 成员变量? ◼ 结构变量如何作为函数参数使用? ◼ 什么是结构数组,如何定义和使用结构数组? ◼ 什么是结构指针,它如何实现对结构分量的操作? ◼ 结构指针是如何作为函数的参数的?

9.1构建手机通讯录 91.1程序解析 912结构的概念与定义 913结构的嵌套定义
9.1 构建手机通讯录 9.1.1 程序解析 9.1.2 结构的概念与定义 9.1.3 结构的嵌套定义

9.1.1程序解析 例91构建简单的手机通讯录 口联系人的基本信息:姓名、年龄和联系电话 口最多容纳50名联系人的信息 口具有新建和查询功能
9.1.1 程序解析 例9-1 构建简单的手机通讯录 联系人的基本信息:姓名、年龄和联系电话 最多容纳50名联系人的信息 具有新建和查询功能

9.1.1程序解析一程序结构 maino new_ friend search_friend ■程序结构 口主函数main:程序的总体控制 口函数 new friend:新建联系人功能 口函数 search friend:査询联系人功能
9.1.1 程序解析-程序结构 ◼ 程序结构 主函数main:程序的总体控制 函数new_friend:新建联系人功能 函数search_friend:查询联系人功能 main() new_friend() search_friend()

程序解析一数据类型变量 ■数据类型变量 口结构类型 struct friends list::在程序首部定义, 其中的成员分别代表联系人的基本信息 struct friends_ listI char name [10]; /姓名* int age; /年龄* char telephone[13];鬥联系电话 口结构数组 friends:每个元素就是一个结构变量, 对应一个联系人 struct friends_ list friends [50];
程序解析-数据类型/变量 ◼ 数据类型/变量 结构类型struct friends_list:在程序首部定义, 其中的成员分别代表联系人的基本信息 struct friends_list{ char name[10]; /* 姓名 */ int age; /* 年龄 */ char telephone[13]; /* 联系电话 */ }; 结构数组friends:每个元素就是一个结构变量, 对应一个联系人 struct friends_list friends[50];

程序解析一全局变量/函数参数 口全局变量 Count:记录当前的联系人总数 口函数 new friend和 search friend的参数之一是 结构数组: void new_ friend(struct friends_ list friends) void search friend(struct friends list friends[] char *name); 结构数组名作为函数实参与普通数组名作函数参数一样, 将数组首地址传递给函数形参
程序解析-全局变量/函数参数 全局变量Count:记录当前的联系人总数 函数new_friend和search_friend的参数之一是 结构数组: void new_friend(struct friends_list friends[ ] ); void search_friend(struct friends_list friends[ ], char *name); 结构数组名作为函数实参与普通数组名作函数参数一样, 将数组首地址传递给函数形参

程序解析一源程序 include include<string h /手机通讯录结构定义 struct friends list char name[10 姓名* int age /年龄* char telephone[13];/联系电话 } int Count=0;全局变量记录当前联系人总数* void new_ friend(struct friends_ list friends; void search friend(struct friends_ list friends[], char *name);
程序解析-源程序 #include #include /*手机通讯录结构定义*/ struct friends_list{ char name[10]; /* 姓名 */ int age; /* 年龄 */ char telephone[13]; /* 联系电话 */ }; int Count = 0; /* 全局变量记录当前联系人总数 */ void new_friend(struct friends_list friends[ ] ); void search_friend(struct friends_list friends[ ], char *name);

int main(void) i int choice; char name[10] 源程序 struct friends_ list friends50];/包含50个人的通讯录 dot printf("手机通讯录功能选项:1:新建2查询0:退出n"; printf("请选择功能:"); scanf"%d",& choice); switch(choice) case 1 new_ friend(friends); break; case 2. printf("请输入要查找的联系人名"); scanf"%s",name; search_ friend(friends, name); break; case 0: break: ]while(choice=0) printi("谢谢使用通讯录功能!n"); return 0:
源程序 int main(void) { int choice; char name[10]; struct friends_list friends[50]; /* 包含50个人的通讯录 */ do{ printf("手机通讯录功能选项:1:新建 2:查询 0:退出\n"); printf("请选择功能:"); scanf("%d", &choice); switch(choice){ case 1: new_friend(friends); break; case 2: printf("请输入要查找的联系人名:"); scanf("%s", name); search_friend(friends, name); break; case 0: break; } }while(choice != 0); printf("谢谢使用通讯录功能!\n"); return 0; }

新建联系人* 源程序 void new_friend (struct friends_ list friends[D struct friends list f: if(Count ==50) prnt("通讯录已满!n"); return: printf("请输入新联系人的姓名:); scanf( %s, f name) printf("请输入新联系人的年龄"); scanf( d", &f age) printf('请输入新联系人的联系电话:"); scanf(%s", f telephone) friends[Count]=f Count++
/*新建联系人*/ 源程序 void new_friend(struct friends_list friends[ ]) { struct friends_list f; if(Count == 50){ printf("通讯录已满!\n"); return; } printf("请输入新联系人的姓名:"); scanf("%s", f.name); printf("请输入新联系人的年龄:"); scanf("%d", &f.age); printf("请输入新联系人的联系电话:"); scanf("%s", f.telephone); friends[Count] = f; Count++; }
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 浙江大学计算机系:网络图形技术 Chinagraph‘2000 讨论组.ppt
- 浙江大学:《计算机辅助设计与图形学》课程教学资源(PPT讲稿)基于图像的绘制技术 Image Based Rendering, IBR.ppt
- 浙江大学:循环结构(PPT讲稿).pptx
- 浙江大学:程序设计专题(PPT讲稿)结构化程序设计与递归函数(刘新国).pptx
- 耶鲁大学:A Sparse Parametric Mixture Model for BTF Compression, Editing and Rendering.ppsx
- 浙江大学计算机科学与技术学院:C语言程序设计基础与试验(PPT讲稿).ppt
- Python的基本应用(PYTHON的入门应用).pptx
- 浙江大学:《计算机辅助设计与图形学》课程教学资源(PPT讲稿)数据可视化基础.ppt
- 浙江大学:《计算机辅助设计与图形学》课程教学资源(PPT讲稿)简单图形库介绍.pptx
- 数据结构与控制算法分析(PPT专题讲稿)查找与排序.ppt
- 浙江大学:《计算机辅助设计与图形学》课程教学资源(PPT讲稿)查找、排序.pptx
- 浙江大学:《计算机控制装置》课程教学资源(PPT讲稿)计算机控制系统的抗干扰设计.ppt
- 浙江大学信息与电子工程学系:《无线网络应用》课程教学资源(PPT讲稿)网线制作实验.ppt
- 浙江大学:R语言基础(PPT讲稿).pptx
- 分布式虚拟环境:虚拟现实的基础理论、算法及实现项目结题报告(分布并行图形绘制技术及系统).ppt
- 浙江大学:《计算机辅助设计与图形学》课程教学资源(PPT讲稿)程序设计专题——结构.pptx
- 浙江大学:《计算机辅助设计与图形学》课程教学资源(PPT讲稿)程序设计专题——结构化程序设计与递归函数.pptx
- 浙江大学:《计算机辅助设计与图形学》课程教学资源(PPT讲稿)SDL(Simple DirectMedia Layer)图形程序设计.pptx
- 《计算机辅助设计(CD)》课程教学大纲.pdf
- MATLAB简介.ppt
- 大型综合程序范例解析(PPT讲稿).ppt
- 生物信息数据分析技能培训:计算机基础技能培训(linux基础知识).pptx
- 浙江大学:虚拟现实中基于图像的建模和绘制(报告PPT).ppt
- 《E-commerce 2014》电子商务(PPT讲稿)Chapter 9 Online Retail and Services.ppt
- 清华大学出版社:《WEB技术开发》课程教学资源(PPT课件)第1章 WEB开发技术概述.ppt
- 《E-commerce 2014》电子商务(PPT讲稿)Chapter 12 B2B E-commerce:Supply Chain Management and Collaborative Commerce.ppt
- 《WEB技术开发》教学资源(PPT讲稿)HTML AND CSS.ppt
- 《E-commerce 2014》电子商务(PPT讲稿)Chapter 5 E-commerce Security and Payment Systems.ppt
- 杭州电子科技大学:《计算机、互联网和万维网简介》教学资源(PPT课件)Chapter 01 C++ Programming Basics.ppt
- 香港浸会大学:《Data Communications and Networking》课程教学资源(PPT讲稿)Chapter 10 Circuit Switching and Packet Switching.ppt
- 山东大学:《微机原理及单片机接口技术》课程教学资源(PPT课件讲稿)第九章 模数转换器与数模转换器.ppt
- 电子科技大学计算机学院:《现代密码学》课程PPT教学课件(密码学基础)第一章 引言.ppt
- 西安电子科技大学:Operating-System Structures(PPT讲稿).pptx
- 《面向对象程序设计》课程PPT教学课件:第1章 Visual Basic概述(主讲:高慧).ppt
- JavaScript编程基础(JavaScript语法规则).ppt
- 长春大学旅游学院:《计算机网络与网络安全》课程教学资源(PPT课件)第6章 计算机网络与网络安全.ppt
- 《程序设计语言》课程PPT教学课件(章节大纲).ppt
- 《网络搜索和挖掘技术》课程教学资源(PPT讲稿)Lecture 1:Web Search Overview & Web Crawling.ppt
- 《编译原理》课程教学资源(PPT课件讲稿)第四章 语法分析——自上而下分析.ppt
- 赣南师范大学:《计算机网络技术》课程教学资源(PPT课件讲稿)第十章 Internet概述.ppt