1620-7 唐大智《2016年12月28日》[连续第八十七天总结]
标题:回顾下类与对象
关键词:题目练手
内容(A)
#include<iostream.h>
class A{
int a,b;
public: //设置正确的访问特性,以使后续语句不出现语法错误
A(int ,int); //构造函数
int geta() //取成员数组a;
{return a;}
void print() //输出所有的成员
{cout<<a<<'\t'<<b<<endl;}
A add() //各成员数据自增后返回
{ a++;
b++;
return return *this;
}
};
A::A(int x,int y) //完成构造函数的定义
{a=x;b=y;}
void main()
{ A t1(5,10),t2(0,0);
t2=t1.add(); //将t1的成员数组自增后赋值给t2
t1.print(); //输出t1的所有成员
cout<<t2.geta()<,endl; } //输出t2的成员a
(B)明日计划:快放假了激动,明天继续学习。