题目:
1)设计并定义一个Triangle类来描述三角形,使用Point类的对象来表示端点,在Triangle类中包括Point类的3个对象p1,p2,p3作为其数据成员,Triangle类具有计算三角形的周长和面积,计算过程在成员函数内实现。
2)增加静态成员数据count和静态成员函数,用于统计当前的Point和Line对象的个数。
3)将Triangle类设置成point的友元类,改写Triangle相关的成员函数。并计算p2为顶点的角度值(弧度)
Point.h
#pragma once
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
public:
Point(double nx = 0.0, double ny = 0.0) :x(nx), y(ny) { count++; }
Point(Point& np) :x(np.x), y(np.y) { count++; }
double GetX();
double GetY();
void SetX(double nx);
void SetY(double ny);
~Point() { count--; }//析构函数
static void showpointcount();//静态成员函数
friend class Triangle;//Triangle 是point的友元函数
friend void getAngle(const Point& p1, const Point& p2, const Point& p3);
private:
double x, y;
static int count;//静态成员变量
};
Point.cpp