?? 1-1.cpp
字號:
#include <iostream>
#include <cmath>
using namespace std;
class CPoint
{
private:
int x, y;
public:
CPoint(int, int);
void printPoint();
void setX(int);
void setY(int);
int getX();
int getY();
};
class CRectangle:private CPoint
{
private:
int length, high;
public:
CRectangle(int, int, int, int);
void printRectangle();
void setLength(int);
void setHigh(int);
int getLength();
int getHigh();
};
int main(int argc, char* argv[])
{
CPoint p1(-1, 1), p2(-1, -1);
CRectangle r(1,1,2,3);
double len;
len = sqrt((p1.getX() - p2.getX())^2 + (p1.getY() - p2.getY())^2);
cout <<"P1 : ";
p1.printPoint();
cout <<" P2 : ";
p2.printPoint();
cout <<endl<<"The two points's Distance is: "<<len<<endl<<endl;
r.printRectangle();
return 0;
}
CPoint::CPoint(int x, int y) {
CPoint::x = x;
CPoint::y = y;
}
CRectangle::CRectangle(int x, int y, int length, int high):CPoint(x, y) {
CRectangle::length = length;
CRectangle::high = high;
}
void CPoint::printPoint() {
cout <<"("<<CPoint::x<<","<<y<<")";
}
void CRectangle::printRectangle() {
cout <<"The Rectangle's Center is: ";
CPoint::printPoint();
cout <<endl<<"Length = "<<CRectangle::length<<" High = "<<CRectangle::high<<endl;
}
void CPoint::setX(int x) {
CPoint::x = x;
}
void CPoint::setY(int y) {
CPoint::y = y;
}
int CPoint::getX() {
return CPoint::x;
}
int CPoint::getY() {
return CPoint::y;
}
void CRectangle::setLength(int length) {
CRectangle::length = length;
}
void CRectangle::setHigh(int high) {
CRectangle::high = high;
}
int CRectangle::getLength() {
return CRectangle::length;
}
int CRectangle::getHigh() {
return CRectangle::high;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -