65,211
社区成员
发帖
与我相关
我的任务
分享
//rectangle.h
#ifndef __RECTANGLE_H_H
#define __RECTANGLE_H_H
class rectangle{
private:
int x1,x2,y1,y2;
public:
void setPointP(int x,int y);
void setPointQ(int x,int y);
int calculate();
};
#endif __RECTANGLE_H_H
//rectangle.cpp
#include "rectangle.h"
void rectangle::setPointP(int x,int y) {
x1 = x;
y1 = y;
}
void rectangle::setPointQ(int x,int y) {
x2 = x;
y2 = y;
}
int rectangle::calculate(){
int length;
int wide;
length = x1-x2;
if(length <0) length=-length;
wide = y1-y2;
if(wide <0) wide=-wide;
return (wide*length);
}
//main.cpp
#include <iostream.h>
#include "rectangle.h"
void main() {
int p1,p2,q1,q2,result;
cout < <"请分别输入两个点的x,y的值:";
cin>>p1>>p2>>q1>>q2;
rectangle t;
t.setPointP(p1,p2);
t.setPointQ(q1,q2);
result=t.calculate();
cout < <endl < <"矩形面积为:";
cout < <result;
}