Вы находитесь на странице: 1из 9

#include<iostream>

#include<cstring>
#include<string>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include <algorithm>
#include<locale>
#include<ctime>
#include<Windows.h>
#include<string.h>
#include<stdlib.h>
#pragma warning (disable: 4996)

using namespace std;


class rectangle {
protected:
int x1, y1, x2, y2; //координаты прямокутника
int color;//колір
public:
//конструктор
rectangle(int x1, int y1, int x2, int y2, int color)
{
this->x1 = x1;
this->y1 = y1;
this->x2 = x2;
this->y2 = y2;
this->color = color;
}

virtual void choosecolor(int x) {


char s[10], st[20] = "color ";
itoa(x, s, 10);
strcat(st, s);
system(st);
//cout << "Выберети цвет" << endl;
};
rectangle() {
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
color = 0;
};
//конструктор копирования
rectangle(rectangle& r)
{
x1 = r.x1;
y1 = r.y1;
x2 = r.x2;
y2 = r.y2;
color = r.color;
}
//операция введения в поток
ostream& operator<<(ostream& os)
{
os << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << color << endl;
return os;
}

//операция вывода из потока


istream& operator>>(istream& is)
{
is >> x1 >> y1 >> x2 >> y2 >> color;
return is;
}
//операция ++ збільшення
rectangle& operator++() {
x2++;
y2++;
return *this;
}
//операция -- зменшення
rectangle& operator --() {
x2--;
y2--;
return *this;
}

// Перезарузка оператора присвоения "=" переміщення.


rectangle& operator = (rectangle& obj)
{
x1 = obj.x1;
y1 = obj.y1;
x2 = obj.x2;
y2 = obj.y2;
color = obj.color;
return *this;
}
// Перезагрузка бинарного оператора умножения "*"
rectangle operator * (rectangle obj)
{
rectangle tmp;
tmp.x1 = x1 * obj.x1;
tmp.y1 = y1 * obj.y1;
tmp.x2 = x2 * obj.x2;
tmp.y2 = y2 * obj.y2;
return tmp;
}
};

//Класс меню
class Menu {
protected:
int count; //количество команд
int active; //номер активной команды
char** command; //название команды
public:
//конструктор
Menu(int count, int active, char** command)
{
this->count = count;
this->active = active;
this->command = new char* [count];
for (int i = 0; i < count; i++)
{
this->command[i] = new char[20];
strcpy_s(this->command[i], 20, command[i]);
}
}
Menu() {
count = 0;
active = 0;
command = NULL;
};
//конструктор копирования
Menu(Menu& m)
{
count = m.count;
active = m.active;

command = new char* [m.count];


for (int i = 0; i < count; i++)
{
command[i] = new char[20];
strcpy_s(command[i], 20, m.command[i]);
}
}
//деструктор
~Menu()
{
for (int i = 0; i < count; i++)
delete[]command[i];
}
//операция введения с потока
friend istream& operator>>(istream& is, Menu& m)
{
for (int i = 0; i < m.count; i++) is >> m.command[i];
return is;
}
//операция вывода из потока
friend ostream& operator<<(ostream& os, Menu& m)
{
for (int i = 0; i < m.count; i++) os << m.command[i] << endl;
return os;
}
};
//Класс окна
class Window : public rectangle, public Menu
{

protected:
char* title; //Заголовок
public:
//конструктор
Window(char* title, rectangle r, Menu m) : rectangle(r), Menu(m)
{
this->title = new char[100];
strcpy_s(this->title, 100, title);
}
//конструктор копирования
Window(const Window& w)
{
//rectangle
x1 = w.x1;
y1 = w.y1;
x2 = w.x2;
y2 = w.y2;
color = w.color;
//Menu
count = w.count;
active = w.active;
command = new char* [w.count];
for (int i = 0; i < count; i++)
{
command[i] = new char[20];
strcpy_s(command[i], 20, w.command[i]);
}
//Window
title = w.title;
}
//деструктор
~Window()
{
delete[] title;
}

Window() :rectangle(), Menu()


{
title = NULL;
}
//операция введения из потока
friend istream& operator>>(istream& is, Window& w)
{
is >> w.x1 >> w.y1 >> w.x2 >> w.y2;
for (int i = 0; i < w.count; i++) is >> w.command[i];
is >> w.title;
return is;
}
//операция вывода из потка
friend ostream& operator<<(ostream& os, Window& w)
{
os << w.title << ' ';
os << w;
os << w;
return os;
}
void set() { cin.ignore(); };
char* getname() { return title; };
Window set(ifstream& f) {
char str[100] = "";
char* ptr;
f.getline(title, 50);
ptr = strtok(str, "\t"); if (ptr) strcpy(title, ptr);

ptr = strtok(str, NULL); if (ptr) choosecolor(atoi(ptr));

return Window();
}
void print(ofstream& f)
{
f << title << '\n';
}
void print() {
//printf("\t%-25s%-11s% 8s", title);
Window();
}
};

class Queue {
protected:
queue<Window> q;
public:
void Print();
void Load();
void Save();
void Add();
void Edit();
void Del();
void Find();
};

void Queue::Print()
{
//queue <osoba>::iterator it;
int i = 0;
cout << "# Окно\n";
cout <<
"-------------------------------------------------------------------\n";
//it=os.begin();
int n = q.size();
queue <Window> t = q;

while (!t.empty())
{
cout << ++i;
t.front().print();
t.pop();
}
}

void Queue::Load()
{
char sn[5] = "";
int n = 0;
Window dd;

ifstream fi("text.txt", ios::in);


fi.getline(sn, 5);
n = atoi(sn);
for (int i = 0; i < n; i++)
{
dd.set(fi);
q.push(dd);
}
}

void Queue::Save()
{
ofstream f("text.txt", ios::out); //ff.close();
f << q.size() << '\n';

queue<Window> t = q;
while (!t.empty())
{
t.front().print(f);

t.pop();
}
f.close();
}

void Queue::Add()//vector <osoba> &os)


{
Window dd;
dd.set();
q.push(dd);
}

void Queue::Edit()//
{
int i = 0, n;
Print();
cout << "Введите номер редактируемоо элемента > ";
cin >> n;
if (n < 1 || n > q.size())
{
fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
}
n--;
queue<Window> f, f2;
Window dd;
while (i < n)
{
f.push(q.front());
q.pop();
i++;
//f.back().print();
}

dd = q.front();
q.pop();
dd.set();

while (!q.empty())
{
f2.push(q.front());
q.pop();
}

while (!f.empty())
{
q.push(f.front());
f.pop();
}
q.push(dd);
while (!f2.empty())
{
q.push(f2.front());
f2.pop();
}
}

void Queue::Del()//vector <osoba> &os)


{
int i = 0, n;
Print();
cout << "Введите номер удаляемоо элемента > ";
cin >> n;
if (n < 1 || n > q.size())
{
fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
}
n--;
queue<Window> f, f2;
while (i < n)
{
f.push(q.front());
q.pop();
i++;
//f.back().print();
}

q.pop();

while (!q.empty())
{
f2.push(q.front());
q.pop();
}

while (!f.empty())
{
q.push(f.front());
f.pop();
}

while (!f2.empty())
{
q.push(f2.front());
f2.pop();
}
}
void Queue::Find()
{
int i = 0;
char str[50];
Print();
cout << "Введите Фамилию> ";
cin >> str;
queue<Window> f = q;

while (!f.empty())
{
if (strstr(f.front().getname(), str))
{
f.front().print(); i++;
}
f.pop();

if (i == 0) cout << "Нет записей удовлетворяющих условие!" << endl;


}
}
int men(void) {
int c = 0;
struct tm* t;
time_t ltime;
time(&ltime);
t = localtime(&ltime);
cout << '\n' << t->tm_mday << '/' << t->tm_mon + 1 << '/' << 1990 + t-
>tm_year << endl;

while ((c < '0' || c >9) && c != 21)


{
printf("\n>>>>>Menu<<<<<\n");
printf("----------------\n");
printf("[0] - Exit\n[1] - Add\n[2] - Save\n[3] - Load\n[4] - Print\n[5]
- Find\n[6] - Del\n[7] - Edit\n");
printf("----------------\n");
printf("---->");
c = getch();
printf("%c\n", c);
}
return c;
}

void main()
{
Queue os;
int k;
setlocale(LC_ALL, "Russian");
/* char command[][6] = { "Add", "Save", "Load", "Print", "Find",
"Del","Edit" };
while ((k = men()) != 0 && k != 20)
switch (k)
{
case'1': os.Add(); break;
case'2': os.Save(); break;
case'3': os.Load(); break;
case'4': os.Print(); break;
case'5': os.Find(); break;
case'6': os.Del(); break;
case'7': os.Edit(); break;
}*/
while (true) {
cout << "[1] - Add\n[2] - Save\n[3] - Load\n[4] - Print\n[5] - Find\
n[6] - Del\n[7] - Edit\n[0] - Exit\n";
cin >> k;
switch (k)
{
case 1:
os.Add(); break;
break;
case 2:
os.Save(); break;
break;
case 3:
os.Load(); break;
case 4:
os.Print(); break;
break;
case 5:
os.Find(); break;
break;
case 6:
os.Del(); break;
case 7:
os.Edit(); break;
default:
cout << "Command not found!" << endl;
break;
}
}
/*rectangle f(1, 1, 80, 25, 2);
cout << "Склад объекта rectangle\n" << f;

Menu m(7, 0, command);


cout << "Склад объекта Menu\n" << m;

Window w("MyWindow", f, m);

cout << w << endl;*/

system("pause");
}

Вам также может понравиться