《实验报告06》
类和对象综合测试实验
代码使用说明:
在新建项目里对应的 头文件 或 源文件 里,新建对应的文件,并把代码复制进去即可。点我参考上篇博文
代码如下:
// 1、stdafx.h头文件
#pragma once
#include <iostream>
using namespace std;
// 2、矩阵类rectangle.h头文件
#pragma once
#include "Point.h"
#include "stdafx.h"
class rectangle
{
public:
rectangle(double Length , double Width , Point Vertex);
~rectangle(void);
double Area();
double Circumference();
void Print();
private:
double length;
double width;
Point vertex;
};
// 3、矩阵类rectangle.cpp源文件
#include "stdafx.h"
#include "rectangle.h"
//构造方法初始化
rectangle::rectangle(double Length, double Width, Point Vertex)
: length(Length)
,width (Width)
,vertex(Vertex)
{
}
rectangle::~rectangle(void)
{
}
double rectangle::Area()
{
double area = length * width;
return area;
}
double rectangle::Circumference()
{
double circumference = 2 * (length + width);
return circumference;
}
void rectangle::Print()
{
vertex.MoveTo(30, 50);
cout << endl << "矩形firstRectangle的边长为:" << length;
cout << ",宽为:" << width;
cout << ",顶点的坐标为:";vertex.Print();
cout << endl << "矩形firstRectangle的面积为:"<< Area();
cout << ",周长为:" << Circumference() << endl;
}
// 4、项目测试源文件
#include "rectangle.h"
#include "stdafx.h"
#include "Point.h"
int main()
{
system("color F0");
Point Vertex;
Vertex.MoveTo(5, 3);
cout << "顶点Vertex的坐标为:";
Vertex.Print();
rectangle firstRectangle(15,20,Vertex);
firstRectangle.Print();
}