3
This presentation is the property of its rightful owner.
Sponsored Links
1 / 55

第3篇 基于对象的程序设计 PowerPoint PPT Presentation


  • 129 Views
  • Uploaded on
  • Presentation posted in: General

第3篇 基于对象的程序设计. 第8章 类和对象 第9章 关于类和对象的进一步讨论 第10章 运算符重载. 第8章 类和对象. 8.1 面向对象程序设计方法概述 8.2 类的声明和对象的定义 8.3 类的成员函数 8.4 对象成员的引用 8.5 类的封装性和信息隐蔽 8.6 类和对象的简单应用举例. 面向过程的编程思想:. 因此,当程序规模较大时,无论是管理还是调试都显得力不从心。解决办法: 面向对象程序设计方法 。. 传统的面向过程程序设计是围绕功能进行的,用一个函数实现一个功能。一个函数可以使用和修改任何一组共用数据。.

Download Presentation

第3篇 基于对象的程序设计

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


3

3

8

9

10


3

8

8.1

8.2

8.3

8.4

8.5

8.6


3

:


3


3


3

1.


3

()


3

2

101010

C++(class)

(instance)


3

3.


3

4.


3


3

5.

Windows()


8 1 4

8.1.4


3

1. (object oriented analysis,OOA)

()()(class)


3

2. (object oriented design,OOD)

()()

3. (OOP)

(C++)


3

4. (object oriented test,OOT)

5. (object oriented soft maintenance,OOSM)


8 2 8 2 1

8.2 8.2.1

C++

(instance)

private:

,,

,,

public:


3

C++

private:

id

name

major

,,

,

,,

public:

registerFor

pickMajor


3


3

8.2

C++


8 2 2

8.2.2

class

{private:

;

public:

;

};

publicprivatepublic


Private public protected

private

public

protected


3

class Student//class

{

int id;

charname[20];

charmajor[20];

void registerFor( )

{

cin >> id >> name >> major >> fees;

}

};


3

:

class Student

{private:

int id;

charname[20];

charmajor[20];

public:

void registerFor( )

{

cin >> id >> name >> major >> fees;

}

};


8 2 3

8.2.3

private:

id

name

major

Student

public:

registerFor

pickMajor

stu1

stu1

0522240

Network

registerFor pickMajor

0521140

Computer

registerFor pickMajor


3

1.

1 class

class Student stud1, stud2;

classStudent

2

Student stud1stud2;


3

2.

class Student

{private:

int id;

charname[20];

charmajor[20];

public:

void registerFor( )

{

cin >> id >> name >> major >> fees;

}

}stud1,stud2;//Student

StudentStudent


3

3.

class//

{private: //

...

public: //

...

} stud1, stud2; //

1


8 3 8 3 1

8.3 8.3.1

private publicprotected

()


3

public

private(utility function)


8 3 2

8.3.2

class Student

{private:

int id;

charname[20];

charmajor[20];

public:

void registerFor( ) ;

};

voidStudent ::registerFor( )

{

cin >> id >> name >> major;

}


3

(qualifed)(field qualifier)


3

  • display( ) display( )

  • display


3

1

2

3

:


3

1

void Time::setdata(int h=0, int m=0, int s=0)

{

}


3

2

void Time::setdata()

{ }

void Time::setdata(int h, int m, int s)

{ }


3

  • 3

  • switch

  • 1

  • 2inline


3

class Time

{public:

void setdata( )

{cin >> hour >> minute>> second;}

private:

inthour;

intminute;

int second;

};


3

class Time

{public:

inline void setdata( )

private:

inthour;

intminute;

int second;

};

inline void setdata( )

{cin >> hour >> minute>> second;}


8 3 4

8.3.4


3

cout << sizeof(Time) << endl;

12

class Time

{

int hour;

int minute;

int sec;

public:

void set( )

{cin>> hour >> minute >> sec;}

};


3

C++this

(1)

(2) inline()


3

8.4

3

;

;


8 4 1

8.4.1

:

.

stud1.registerFor( ) ;

//stud1

registerFor( );

//registerFor

registerFor( )


3

publicprivateid

stud1.id=10101;

//num


8 4 2

8.4.2

class Time

{public: //

int hour;

int minute;

};

Time t,*p; //tp

p=&t; //pt

cout<<p->hour; //phour

ptp->hour(*p).hourt.hour


8 4 3

8.4.3

Time

Time t1; //t1

Time &t2=t1;

//Timet2t1

cout<<t2.hour;

//t1hour

t2t1(t2t1)t2.hourt1.hour


Length width height 1 2 3

length()width()height()

1

2

3


8 5 2

8.5.2

()


3

C++


3

(1)

(2)(C++)#include


8 5 3

8.5.3

stud.display( );studdisplaydisplay


3


3


  • Login