設計一個Point類,要求如下:1.私有成員x和y代表一個點的x,y座標值;2.定義一個無參的建構函式,一個有兩?
讓跑步更有力量 發表于 農業2020-03-14
#include “stdafx。h”
#include
#include
using namespace std;
class Point
{
public:
Point(): m_x(0),m_y(0) //無參的建構函式
{
}
Point(double x, double y) //兩個引數的建構函式
{
m_x = x;
m_y = y;
}
Point(const Point& srcPoint) //複製建構函式
{
m_x = srcPoint。m_x;
m_y = srcPoint。m_y;
}
void setPoint(int x, int y)
{
m_x = x;
m_y = y;
}
void dispay()
{
cout<<“X = ”< } private: double m_x; double m_y; }; void main() { Point p1; // 無參的建構函式 Point p2(1, 2); //兩個引數的建構函式 Point p3 = p2; // 複製建構函式 p3。setPoint(3, 4); p3。dispay(); }