![]() |
#2
rjsp2017-10-16 08:43
|

// ConsoleApplication26.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<cstdlib>
using namespace std;
class myrect
{
public:
double getArea() //声明面积
{
return height*width;
}
int getgirth() //声明周长
{
return height * 2 + width * 2;
}
myrect(int x, int yl, int h, int w)
{
this->x = x;
y = yl;
height = h;
width = w;
}
void inflate(int n)//放大倍数
{
height *= n;
width *= n;
}
void reduce(int p)//缩小倍数
{
height = height / p;
width = width / p;
}
void move(int xm, int ym)//移动
{
x += xm;
y += ym;
}
private: //变量
int x, y;
int height, width;
};
int main()
{
int x, y;
myrect rect1(100, 100, 20, 50);
cout << rect1.getArea() << endl; //输出面积
cout << rect1.getgirth() << endl;//输出周长
rect1.inflate(3);//放大3倍
cout << "increase" << 3 << ":" << rect1.getArea() << endl;
rect1.reduce(2);//缩小2倍
cout << "reduce" << 2 << ":" << rect1.getArea() << endl;
rect1.move(30, 40);//x,y分别加的坐标
cout << "x,y" <<x<<y << endl;
system("pause");
return 0;
}
//
#include "stdafx.h"
#include<iostream>
#include<cstdlib>
using namespace std;
class myrect
{
public:
double getArea() //声明面积
{
return height*width;
}
int getgirth() //声明周长
{
return height * 2 + width * 2;
}
myrect(int x, int yl, int h, int w)
{
this->x = x;
y = yl;
height = h;
width = w;
}
void inflate(int n)//放大倍数
{
height *= n;
width *= n;
}
void reduce(int p)//缩小倍数
{
height = height / p;
width = width / p;
}
void move(int xm, int ym)//移动
{
x += xm;
y += ym;
}
private: //变量
int x, y;
int height, width;
};
int main()
{
int x, y;
myrect rect1(100, 100, 20, 50);
cout << rect1.getArea() << endl; //输出面积
cout << rect1.getgirth() << endl;//输出周长
rect1.inflate(3);//放大3倍
cout << "increase" << 3 << ":" << rect1.getArea() << endl;
rect1.reduce(2);//缩小2倍
cout << "reduce" << 2 << ":" << rect1.getArea() << endl;
rect1.move(30, 40);//x,y分别加的坐标
cout << "x,y" <<x<<y << endl;
system("pause");
return 0;
}
void move(int xm, int ym)//移动
{
x += xm;
y += ym;
}
rect1.move(30, 40);//x,y分别加的坐标
cout << "x,y" <<x<<y << endl;
这里有问题,但是不知道怎么改?