c 课件ObjectsandClasses.ppt


文档分类:IT计算机 | 页数:约40页 举报非法文档有奖
1/40
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/40
文档列表 文档介绍
08 Objects and Classes
1
datatype variable_name = initialization_value;
int year = 2010;
float score_of_cpp[124]={0};
char *ptr = {“79 golden medal”};
struct point
{
int x;
int y;
} centre_point;
=0;
=0;
2
Consider puter adventure game
Among the objects in the game might be:
You, the player
Your enemies, . dragons
Your weapons
Obstacles such as locked doors, rivers, etc.
The prize . energy or a fair maiden
3
Consider puter adventure game
Among the objects in the game might be:
You, the player
A player will have data values to represent certain attributes, . the state of their health or the weapons they possess. A player must be able to perform functions such as walk, run, attack an enemy, and rescue the fair maiden to win.
Your enemies, . dragons
Your weapons
Obstacles such as locked doors, rivers, etc.
The prize . energy or a fair maiden
4
pseudo code representations of the classes
class player
{
// functions:
walk( )
run( )
jump( )
attack( )
rescue( )
...
//data:
state_of_health
type_of_weapon
...
} ;
class player Team[4] ;
class dragon
{
//functions:
walk( )
spit_fire( )
use_claws( )
use_tail( )
die( )
...
//data:
size
number_of_claws
state_of_health
...
} ;
class dragon e( 10, 4 ) ;
5
pseudo code representations of the classes
class dragon
{
//functions:
walk( )
spit_fire( )
use_claws( )
use_tail( )
die( )
...
//data:
size
number_of_claws
state_of_health
...
} ;
class dragon e( 10, 4 ) ;
A class
An instance of the class
An object is an instance of a class;
it has:
an identity, . its name
a state, . its data members
a behaviour, . its member functions.
6
Constructing a class in C++
class ount
{
public:
void open( int acc_no, double initial_balance ) ;
void deposit( double amount ) ;
void withdraw( double amount ) ;
void display_balance() ;
private:
int account_number ;
double balance ;
} ;
The class member function prototypes
The class data m

c 课件ObjectsandClasses 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数40
  • 收藏数0 收藏
  • 顶次数0
  • 上传人luciferios02
  • 文件大小247 KB
  • 时间2017-09-12