Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

В2_6

.cpp
Скачиваний:
7
Добавлен:
01.02.2019
Размер:
4.95 Кб
Скачать
#include <iostream>
#include <vector>

using namespace std;

class B1 {
	int x, y;
public:
	B1(int a, int b) {
		x = a;
		y = b;
		cout << "B1" << endl;
	}
	void Show_B1() {
		cout << "x: " << x << " | y: " << y << endl; 
	}
};

class B2 {
	int x, y;
public:
	B2(int a, int b) {
		x = a;
		y = b;
		cout << "B2" << endl;
	}
	void Show_B2() {
		cout << "x: " << x << " | y: " << y << endl; 
	}
};

class D1: protected B1, public B2  {
	int x, y;
public:
	D1(int a, int b): B1(a, b), B2(a, b) {
		x = a;
		y = b;
		cout << "D1" << endl;
	}
	void Show_D1() {
		cout << "x: " << x << " | y: " << y << endl; 
	}
};

class B3 {
	int x, y;
public:
	B3(int a, int b) {
		x = a;
		y = b;
		cout << "B3" << endl;
	}
	void Show_B3() {
		cout << "x: " << x << " | y: " << y << endl; 
	}
};

class D2: public D1, protected B3 {
	int x, y;
public:
	D2(int a, int b): D1(a, b), B3(a, b) {
		x = a; 
		y = b;
		cout << "D2" << endl;
	}
	void Show_D2() {
		cout << "x: " << x << " | y: " << y << endl; 
	}
};

class D3: public D2 {
	int x, y;
public:
	D3(int a, int b): D2 (a, b) {
		x = a;
		y = b;
		cout << "D3" << endl;
	}
	void Show_D3() {
		cout << "x: " << x << " | y: " << y << endl; 
	}
};

class graph_object {
public:
	double x, y, size;
	graph_object (double a, double b, double _size) {
		x = a;
		y = b;
		size = _size;
	}
	virtual void show_coord () {
		cout << "x: " << x << " | y: " << y << endl;
	}
	virtual void show_size () {
		cout << "size: " << size << endl;
	}
};

class point: public graph_object {
public:
	point(double a, double b): graph_object(a, b, false) {}
	virtual void show_coord () {
		cout << "Координаты точки" << endl;
		cout << "x: " << x << endl;
		cout << "y: " << y << endl;
	}
	virtual void show_size () {
		cout << "Точка не имеет размера" << endl;
	}
};

class line: public graph_object {
	double x2, y2;
public:
	line(double _x, double _y, double _x2, double _y2): graph_object(_x, _y, sqrt(pow(_x2 - _x, 2) + pow(_y2 - _y, 2))) {
		x2 = _x2;
		y2 = _y2;
	}
	virtual void show_coord () {
		cout << "Координаты линии" << endl;
		cout << "(x1, y1): (" << x << ", " << y << ')' << endl;
		cout << "(x2, y2): (" << x2 << ", " << y2 << ')' << endl;
	}
	virtual void show_size () {
		cout << "Длина линии: " << size << endl;
	}
};

class circle: public graph_object {
public:
	circle(double _x, double _y, double _radius): graph_object(_x, _y, _radius) {}
	virtual void show_coord () {
		cout << "Центр круга: " << x << ", " << y << endl;
	}
	virtual void show_size () {
		cout << "Радиус: " << size << endl;
		cout << "Длина окружности: " << (2 * 3.14 * size) << endl;
		cout << "Площадь круга: " << (3.14 * pow(size, 2)) << endl;
	}
};

int main() {
	setlocale(0, "");
	// Задание 1
	D3 d(2,2);
	d.Show_D3();
	d.Show_D2();
	d.Show_B2();
	system ("pause");
	system ("cls");
	// Задание 2
	vector<graph_object *> arr; 
	short id;
	double x1, y1, x2, y2, radius;
	point * Point;
	line * Line;
	circle * Circle;
	while (true) {
		cout << "1) Добавить круг" << endl;
		cout << "2) Добавить точку" << endl;
		cout << "3) Добавить линию" << endl;
		cout << "4) Вывести список элементов" << endl;
		cout << "0) Выход" << endl;
		cout << " Выберите пункт меню: ";
		cin >> id;
		cout << endl;
		switch(id) {
		case 1: 
			cout << "Введите координаты центра круга" << endl;
			cout << "x: ";
			cin >> x1;
			cout << "y: ";
			cin >> y1;
			cout << "Введите радиус круга: ";
			cin >> radius;
			cout << endl;
			Circle = new circle (x1, y1, radius);
			arr.insert(arr.end(), (graph_object *) Circle);
			break;
		case 2: 
			cout << "Введите координаты точки" << endl;
			cout << "x: ";
			cin >> x1;
			cout << "y: ";
			cin >> y1;
			Point = new point (x1, y1);
			cout << endl;
			arr.insert(arr.end(), (graph_object *) Point);
			break;
		case 3: 
			cout << "Введите координаты начала линии" << endl;
			cout << "x1: ";
			cin >> x1;
			cout << "y1: ";
			cin >> y1;
			cout << "Введите координаты конца линии" << endl;
			cout << "x2: ";
			cin >> x2;
			cout << "y2: ";
			cin >> y2;
			cout << endl;
			Line = new line (x1, y1, x2, y2);
			arr.insert(arr.end(), (graph_object *) Line);
			break;
		case 4:
			for (unsigned short i = 0; i < arr.size(); i++) {
				arr[i]->show_coord();
				arr[i]->show_size();
				cout << endl;
			}
			break;
		case 0:
			return false;
		default:
			cout << "Неверный пункт меню" << endl;
		}
	}
	system ("pause");
	return 0;
}
Соседние файлы в предмете Программирование на C++