⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1-1.cpp

📁 c++二、通过将其元素插入到双向链表中的方法对数组A进行排序。算法对链表的当前操作位置进行维护
💻 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 + -