合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)结构与对象

由结构到对象 ·通常,C库以一组函数开始,但是还有比这些代 表行为和动作的函数更重要的东西,就是一组表 达相近特性的数据,即结构。 C库中都有各自定义的一组结构和一组作用在这 些结构之上的函数。 从语言的发展来看,对象=结构+函数
由结构到对象 • 通常,C库以一组函数开始,但是还有比这些代 表行为和动作的函数更重要的东西,就是一组表 达相近特性的数据,即结构。 • C库中都有各自定义的一组结构和一组作用在这 些结构之上的函数。 • 从语言的发展来看, 对象 = 结构 + 函数

定义结构(例一:动态数组) //An example of a C-like library, an array-like entity created at runtime typedef struct CstashTag int size /Size of each space Int quantity, /Number of storage spaces int next / next empty space Dynamically allocated array of bytes unsigned char storage; 3 STash
定义结构(例一:动态数组) //An example of a C-like library, an array-like entity created at runtime. typedef struct CstashTag { int size; //Size of each space int quantity; //Number of storage spaces int next; // next empty space // Dynamically allocated array of bytes: unsigned char* storage; } CStash;

定义方法 void initialize( STash*S, int size) void cleanup( STash*s int add(stash*S, const void*element void* fetch(CStash *S, int index int count(STash*S) void inflate(CStash*S, int increase)
定义方法 void initialize ( CStash * s , int size); void cleanup (CStash * s ); int add(CStash * s, const void * element ); void * fetch (CStash * s, int index ); int count (CStash * s ); void inflate (CStash * s , int increase) ; ///

实现方法 /方法 initialize的实现 // Declare structure and functions # include“Clbh #include #include using spacename std const int increment = 100; //Quantity of elements to add when increasing storage void initialize( Stash*, int sz) S-Size sz S->quantity=0 S->storage =0 S->next=0;
实现方法 //方法initialize 的实现 // Declare structure and functions: #include “Clib.h” #include #include using spacename std; const int increment = 100; //Quantity of elements to add when increasing storage void initialize ( CStash * s, int sz ) { s->size = sz; s->quantity = 0; s->storage = 0; s->next = 0; }

定义结构(例二:堆栈) typedef struct CStackTag int size //Size of each space Int quantity; Number of stack spaces int bottom: / Bottom of stack Int top //top of stack 3 STack
定义结构(例二:堆栈) typedef struct CStackTag { int size; //Size of each space int quantity; //Number of stack spaces int bottom;// Bottom of stack int top; // top of stack } CStack;

定义方法 void initialize( Stack *s) void cleanup(stack *s) int push(STack * s, const void*element int pop(stack*s)
定义方法 void initialize ( CStack * s ); void cleanup (CStack * s ); int push(CStack * s, const void * element ); int pop (CStack * s ); ///

存在的问题 问题一: 在这种库机制中,必须向库中的每一个函数传递库中 所定义结构的地址,这是相当笨拙的。 问题二: 这种库机制中,在读取所定义的结构的代码时容易与 函数调用的含义混淆,在理解这些代码时会引起混乱。 问题三: 名字冲突( name clashes),不同的库中使用了相同的 函数名。 为此,C库厂商通常在他们的库函数名前加上一个特殊的 字符串,诸如: STash initialize()和 CStash cleanup()等
存在的问题 • 问题一: – 在这种库机制中,必须向库中的每一个函数传递库中 所定义结构的地址,这是相当笨拙的。 • 问题二: – 这种库机制中,在读取所定义的结构的代码时容易与 函数调用的含义混淆,在理解这些代码时会引起混乱。 • 问题三: – 名字冲突(name clashes),不同的库中使用了相同的 函数名。 • 为此,C库厂商通常在他们的库函数名前加上一个特殊的 字符串,诸如:CStash_initialize ( )和CStash_cleanup( ) 等

解决方法:让函数成为结构的成员 //An example of a C-like library, an array-like entity created at runtime struct Stash int size //Size of each space int quantity //Number of storage spaces int next / next empty space / Dynamically allocated array of bytes unsigned char x storage // Functions void initialize( int size) void cleanup () int add(const void* element void* fetch( int index int count void inflate(int increase)
解决方法:让函数成为结构的成员 //An example of a C-like library, an array-like entity created at runtime. struct Stash { int size; //Size of each space int quantity; //Number of storage spaces int next; // next empty space // Dynamically allocated array of bytes: unsigned char* storage; // Functions! void initialize ( int size); void cleanup ( ); int add(const void * element ); void * fetch ( int index ); int count ( ); void inflate (int increase) ; }///
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第十三章 管理技术与软件质量保证.ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第八章 软件设计的启发式规则面向数据流的设计方法.ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第七章 测试(Testing).ppt
- 合肥工业大学:《软件工程》课程教学资源(参考资料)因果图判定表.doc
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第九章 面向对象方法学引论.ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)OO实例.ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第十一章 OOD续.ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第十一章 OOD.ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第十章 OOA.ppt
- 《C语言程序设计教程》第12章 C语言综合应用程序示例.ppt
- 《Dreamweaver扩展》参考文献(英文版)Extending Dreamweaver 8.pdf
- 上海理工大学:《电子商务基础与应用》课程PPT教学课件资源(第四版)第七章 网络营销策略.ppt
- 上海理工大学:《电子商务基础与应用》课程PPT教学课件资源(第四版)第十一章 电子商务物流.ppt
- 上海理工大学:《电子商务基础与应用》课程PPT教学课件资源(第四版)第十章 电子支付.ppt
- 上海理工大学:《电子商务基础与应用》课程PPT教学课件资源(第四版)第九章 ebXML原理.ppt
- 上海理工大学:《电子商务基础与应用》课程PPT教学课件资源(第四版)第八章 网络促销.ppt
- 上海理工大学:《电子商务基础与应用》课程PPT教学课件资源(第四版)第十二章 电子商务安全管理.ppt
- 《大学计算机基础教程》课程教学资源:计算机基础知识.ppt
- 浙江大学:《电子商务导论》课程PPT教学课件_第十章 电子商务支付工具.ppt
- 浙江大学:《电子商务导论》课程PPT教学课件_第九章 电子商务安全技术.ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第八章 维护.ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)编码语言发展.doc
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)第六章 详细设计(zhhf03).ppt
- 合肥工业大学:《软件工程》课程教学资源(讲义)软件可靠性.doc
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿,共三讲).ppt
- 合肥工业大学:《软件工程》课程教学资源(PPT课件讲稿)需求分析.ppt
- 《ARM编程技巧》讲义.ppt
- 《计算机网络管理》第10章 网络安全管理.ppt
- 《计算机网络管理》第12章 美萍计费.ppt
- 《计算机网络管理》第13章 邮件互发.ppt
- 《计算机网络管理》第1章 网络管理概述.ppt
- 《计算机网络管理》第2章 Intranet、Extranet、Internet(新).ppt
- 《计算机网络管理》第3章 IP地址的管理.ppt
- 《计算机网络管理》第4章 域和活动目录的管理.ppt
- 《计算机网络管理》第5章 存储管理.ppt
- 《计算机网络管理》第6章 组策略的管理.ppt
- 《计算机网络管理》第7章 信息网站.ppt
- 《Java程序设计开发》课程教学资源(PPT课件讲稿)第1章 Java入门.ppt
- 《Java程序设计开发》课程教学资源(PPT课件讲稿)第2章 方法设计.ppt
- 《Java程序设计开发》课程教学资源(PPT课件讲稿)第3章 数据成员设计.ppt