[凡鸽鸽]《实验报告06》 类和对象综合测试实验

《实验报告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();
}

项目测试运行结果如图:

测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值