中国高校课件下载中心 》 教学资源 》 大学文库

南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 3-类的基础部分

文档信息
资源类别:文库
文档格式:PPT
文档页数:75
文件大小:296.5KB
团购合买:点击进入团购
内容简介
南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 3-类的基础部分
刷新页面文档预览

第3章类的基础部分陈哲教授南京航空航天大学计算机科学与技术学院

1 第 3 章 类的基础部分 陈哲 教授 南京航空航天大学 计算机科学与技术学院

3.1.1过程化程序设计的缺陷程序逻辑复杂:程序员难以理解成百上千的函数以及它们之间的关系:函数协作复杂:为了在多个函数之间进行数据传递,使用大量的全局变量或函数参数:,程序难以进行修改和扩充:函数之间互相关联牵一发而动全身

2 3.1.1 过程化程序设计的缺陷 • 程序逻辑复杂: 程序员难以理解成百上千的函数 以及它们之间的关系; • 函数协作复杂:为了在多个函数之间进行数据传 递,使用大量的全局变量或函数参数; • 程序难以进行修改和扩充:函数之间互相关联, 牵一发而动全身

面向对象程序设计的基本思想3.1.21(过程)过程化程序设计是以函数为中心。数据成员floatwidth;面向对象程序设计是以对象为中floatlength;心,把数据和对数据的操作封装floatarea函数成员在一起。回顾:C语言中如何把setData()(...)数据封装在一起?calculateArea((Example:getwidth()getLength()(.)getArea( )

3 3.1.2 面向对象程序设计的基本思想 • 过程化程序设计是以函数 (过程) 为中心。 • 面向对象程序设计是以对象为中 心,把数据和对数据的操作封装 在一起 。 • Example: 回顾:C语言中如何把 数据封装在一起?

3.2类的基本概念类是一种用户自定义类型,声明形式:类名class变量和函数的声明;例如:

4 3.2 类的基本概念 类是一种用户自定义类型,声明形式: class 类名 { 变量和函数的声明; . } ; 例如:

成员变量float width;属性float length;float area;成员函数setData()calcArea()方法getWidthO.getLengthOigetArea()

成员变量 float width ; float length ; float area ; 成员函数 setData( ) { . } calcArea( ) { . } getWidth( ) { . } getLength( ){ . } getArea( ) { . } 属性 方法

classRectangle默认情况下类的成员是私有floatwidth;的,而结构体(struct)中的成floatlength:员是公有的。floatarea;voidsetData(float, float);voidcalcArea();floatgetWidth();floatgetLength();floatgetArea();7

class Rectangle { float width; float length: float area; void setData(float, float); void calcArea( ); float getWidth( ); float getLength( ); float getArea( ); }; 默认情况下类的成员是私有 的,而结构体(struct)中的成 员是公有的

3.2类的基本概念(续)·为了使类的成员能够在类外面被访问,其成员必须定义为publicExample:

7 3.2 类的基本概念(续) • 为了使类的成员能够在类外面被访问,其 成员必须定义为public. • Example:

classRectangleprivate:floatwidth;floatlength:floatarea;public:voidsetData(float, float);voidcalcArea();floatgetWidth(O);floatgetLength();floatgetArea(O);;

class Rectangle { private: float width; float length: float area; public: void setData(float, float); void calcArea( ); float getWidth( ); float getLength( ); float getArea( ); };

classRectanglepublic:voidsetData(float, float);voidcalcArea();floatgetWidth(O);floatgetLength();floatgetAreaO;private:floatwidth;floatlength:floatarea;;

class Rectangle { public: void setData(float, float); void calcArea( ); float getWidth( ); float getLength( ); float getArea( ); private: float width; float length: float area; };

classRectangleHprivate:floatwidth;public:voidsetData(float, float);voidcalcAreaO;floatgetWidth();floatgetLength();floatgetArea();private:floatlength:floatarea;Y

class Rectangle { private: float width; public: void setData(float, float); void calcArea( ); float getWidth( ); float getLength( ); float getArea( ); private: float length: float area; };

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档