下载此文档

C++程序设计(part2).ppt


文档分类:IT计算机 | 页数:约90页 举报非法文档有奖
1/90
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/90 下载此文档
文档列表 文档介绍
C++程序设计(part 2)
Object-Oriented Programming
What?
Why?
How?
OOP
What
non-OO Solution
#include <>
#define STACK_SIZE 100
struct Stack
{ int top;
int buffer[STACK_SIZE];
};
void main()
{ Stack st1,st2;
= -1;
= -1;
int x;
push(st1,12);
pop(st1,x);
}
bool push(Stack &s, int i);
{ if ( == STACK_SIZE-1)
{ printf(“Stack is overflow.\n”);
return false; }
else
{ ++; [] = i;
return true; }
}
bool pop(Stack &s, int &i)
{ if ( == -1)
{ printf(“Stack is empty.\n”);
return false; }
else
{ i = []; --;
return true; }
}
OOP
OO Solution
#include <>
#define STACK_SIZE 100
class Stack
{ int top;
int buffer[STACK_SIZE];
public:
Stack() { top = -1; }
bool push(int i);
bool pop(int& i);
};
void main()
{ Stack st1,st2;
int x;
(12); (x);
(20); (x);
}
bool Stack::push(int i);
{ if (top == STACK_SIZE-1)
{ cout << “Stack is overflow.\n”;
return false; }
else
{ top++; buffer[top] = i;
return true; }
}
bool Stack::pop(int& i)
{ if (top == -1)
{ cout << “Stack is empty.\n”;
return false; }
else
{ i = buffer[top]; top--;
return true; }
}
OOP
Concepts
Program=Object1 + Object2 +……+ Objectn
Object: Data + Operation
Message: function call
Class
Object-Oriented
Object-Based
Only Provide Encapsulation
Without Inheritance
Ada, etc
OOP
Why
评价标准
Efficency of Development
Quality
External
Correctness、Efficiency、Robustness、Reliability
Usability、Reusability
Internal
Readability、Maintainability、Portability
HUI
UX
产品在规定的条件下和规定的时间内完成规定功能的能力
( 概率度量:可靠度)
需求
架构设计
构建模式
代码
测试用例
项目组织结构
OOP
Advantages
提高开发效率和软件质量
更高层次的抽象-数据抽象
数据封装
更好的模块化支持(高内聚、低耦合)
软件复用(部分重用)
对需求变更具有更好的适应性
OOP
How
Encapsulation
Object & Class
Object
数据:数据成员、成员变量、实例变量、对象的局部变量
操作:操作、方法、成员函数、消息处理过程
Class
对象属性的描述,是创建对象的模板
对象是类的实例
对象属于值的范畴,而类属于类型的范畴
OOP
Inheritance
is-a
软件重用(部分重用)
父类(Base class)、子类(Derived Class)
Single Inheritance
Multiple Inheritance
OOP
Polymorph

C++程序设计(part2) 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数90
  • 收藏数0 收藏
  • 顶次数0
  • 上传人追风少年
  • 文件大小0 KB
  • 时间2011-07-12