問題及代碼:
/*
*Copyright (c) 2016,煙臺大學計算機學院
*All rights reserved.
*文件名稱:main.cpp
*作 者:李磊濤
*完成時間:2016年5月7日
*版 本 號:v1.0
*
*問題描述:輸出座標。
*輸入描述:2個整數,代表x,y。
*程序輸出:x,y。
*/
#include<iostream>
using namespace std;
class point
{
private:
int x;
int y;
public:
point(int,int);
void show();
};
point::point(int a,int b)
{
x=a;
y=b;
}
void point::show()
{
cout<<x<<" "<<y<<endl;
}
int main()
{
int a,b;
cin>>a>>b;
point po(a,b);
po.show();
}
運行結果:
通過該程序,強化了我對繼承基類和派生類的認識。
學習心得:
要多做題多熟悉一下繼承機制定義類族。