下载此文档

c 课件7.ppt


文档分类:幼儿/小学教育 | 页数:约88页 举报非法文档有奖
1/88
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/88 下载此文档
文档列表 文档介绍
C++ Programming Language
Lecture 6&7: Classes
1
Contents
Characteristics of OOP
The definition and declaration of class
Accessing manners
Member of class
Constructor
Copy-constructor
Destructor
bination
Static members
2
OOP Language
Main Viewpoint:
OOP Language can describe the existing things (object) in the nature and their relations directly.
Characteristics:
Belonging to advanced language.
Looking on the impersonal things as objects with some attributes and behaviors.
Describing the objects with same attributes and behaviors as a Class.
Realizing code reuse through inheritance and polymorphism.
3
Example of structure:
struct Date{
int year;
int month;
int day;
};
void print(Date s){
('0');
cout<<setw(4)<<<<'-'<<setw(2)<<<<'-'<<setw(2)<<<<'\n';
(' ');
}
bool isLeapYear(Date d){
return ( % 4==0 && % 100!=0)||( % 400==0);}
4
#include<iostream>
#include<iomanip>
using namespace std;
void main(){
Date d;
= 2000;
= 12;
= 6;
if(isLeapYear(d))
print(d);
}
5
Example of class:
class person{
char Name[20];
int Age;
char Sex;
public:
void Register(char *, int, char);
char *GetName(){return Name;}
int GetAge(){return Age;}
char GetSex(){return Sex;}
void show() {cout<<GetName()<<'\t'<<GetAge()<<'\t'<<
GetSex()<<endl;}
};
6
void person::Register(char * name, int age, char sex)
{
strcpy(Name,name);
Age=age;
Sex=sex;
}
#include<iostream>
#include <string>
using namespace std;
void main()
{
char name[20],sex;
int age;
cin>>name>>age>>sex;
person per1;
(name,age,sex);
();}
7
OOP Language(continue)
Basic concept of OOP
Class
Object
Encapsulation and Concealment
Inheritance and Reuse
Polymorphism
8
Class of OOP
Object collection with the same attributes and behaviors.
Providing abstract description for all objects belongs to the same class, prised attributes and behaviors.
9
Class of OOP
Relation between class and ob

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

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数88
  • 收藏数0 收藏
  • 顶次数0
  • 上传人mh900965
  • 文件大小813 KB
  • 时间2018-05-24
最近更新