Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab_1.cpp
- #include "stdafx.h"
- #include <locale>
- #include <windows.h>
- #include <iostream>
- #include "MyDateS.h"
- #include "MyDate.h"
- using namespace std;
- /*Структура Дата.Структура должна включать следующие поля : день, месяц, год, список событий на эту дату.
- Простейшие функции : увеличение / уменьшение на 1 день,
- вычисление количества дней до заданной даты,
- вывод текущей даты,
- просмотр списка событий,
- увеличение и очистка списка событий.*/
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int option = 0;
- Datefunc::DateStruct *ds;
- // Выделяем динамически память под структуру
- // и присваиваем адрес структуры в указатель
- try
- {
- ds = new Datefunc::DateStruct;
- }
- catch (...)
- {
- cout << "Ошибка: Память не выделена!";
- exit(0);
- };
- // Создаем объект класса
- Date* d;
- // Выделяем динамически память под объект
- d = new Date;
- while (1)
- {
- cout << "1.Ввод даты" << endl;
- cout << "2.Добавление события" << endl;
- cout << "3.Вывод событий для даты" << endl;
- cout << "4.Очистка списка событий" << endl;
- cout << "5.Уменьшение заданной даты на 1 день" << endl;
- cout << "6.Увеличение заданной даты на 1 день" << endl;
- cout << "7.Выход" << endl;
- cin >> option;
- // Работа с классом
- switch (option)
- {
- case 1:
- {
- int day, m, y;
- cout << "Ввод даты" << endl;
- cout << "Введите число: " << endl;
- cin >> day;
- d->SetDay(day);
- cout << "Введите месяц: " << endl;
- cin >> m;
- d->SetMonth(m);
- cout << "Введите год: " << endl;
- cin >> y;
- d->SetYear(y);
- break;
- }
- case 2:
- {
- int day, m, y;
- string events;
- cout << "К какой дате добавить событие: " << endl;
- cout << "Введите число: " << endl;
- cin >> day;
- cout << "Введите месяц: " << endl;
- cin >> m;
- cout << "Введите год: " << endl;
- cin >> y;
- cout << "Введите событие: " << endl;
- cin.ignore();
- getline(cin, events);
- d->AddEvent(day, m, y, events);
- break;
- }
- case 3:
- {
- int day, m, y;
- cout << "К какой дате вывести события: " << endl;
- cout << "Введите число: " << endl;
- cin >> day;
- cout << "Введите месяц: " << endl;
- cin >> m;
- cout << "Введите год: " << endl;
- cin >> y;
- d->Print(day, m, y);
- break;
- }
- case 4:
- {
- int day, m, y;
- cout << "Для какой даты очистить события: " << endl;
- cout << "Введите число: " << endl;
- cin >> day;
- cout << "Введите месяц: " << endl;
- cin >> m;
- cout << "Введите год: " << endl;
- cin >> y;
- d->Clear(day, m, y);
- break;
- }
- case 5:
- {
- int day, m, y;
- cout << "-1 день: " << endl;
- cout << "Введите число: " << endl;
- cin >> day;
- cout << "Введите месяц: " << endl;
- cin >> m;
- cout << "Введите год: " << endl;
- cin >> y;
- d->Minus(day, m, y);
- break;
- }
- case 6:
- {
- int day, m, y;
- cout << "+1 день: " << endl;
- cout << "Введите число: " << endl;
- cin >> day;
- cout << "Введите месяц: " << endl;
- cin >> m;
- cout << "Введите год: " << endl;
- cin >> y;
- d->Plus(day, m, y);
- break;
- }
- case 7:
- {
- exit(0);
- }
- default:
- cout << "Введите число от 1 до 7" << endl;
- }
- /* Работа со структурой
- Создаем объект класса Datefunc*/
- Datefunc* datefunc;
- // Выделяем динамически память под объект
- datefunc = new Datefunc;
- datefunc->SetDay(ds, d->Day);
- datefunc->SetMonth(ds, d->Month);
- datefunc->SetYear(ds, d->Year);
- datefunc->SetEvent(ds, d->Event);
- }
- return 0;
- }
- //MyDateS.h
- #pragma once
- #include "string"
- using namespace std;
- class Datefunc
- {
- public:
- struct DateStruct
- {
- int Day[100]; //день
- int Month[100]; //месяц
- int Year[100]; //год
- string Event[100]; // массив 100 элементов - события
- };
- public:
- void SetDay(struct DateStruct* S, int Day[]);
- void SetMonth(struct DateStruct* S, int Month[]);
- void SetYear(struct DateStruct* S, int Year[]);
- void SetEvent(struct DateStruct* S, string *Event);
- int countDate = 0; // счетчик количества дней
- };
- //MyDateS.cpp
- #include "stdafx.h"
- #include "MyDateS.h"
- //---------------------------------------------------
- void Datefunc::SetDay(struct DateStruct* S, int Day[])
- {
- for (int i = 0; i < countDate; i++)
- S->Day[i] = Day[i];
- }
- void Datefunc::SetMonth(struct DateStruct* S, int Month[])
- {
- for (int i = 0; i < countDate; i++)
- S->Month[i] = Month[i];
- }
- void Datefunc::SetYear(struct DateStruct* S, int Year[])
- {
- for (int i = 0; i < countDate; i++)
- S->Year[i] = Year[i];
- }
- void Datefunc::SetEvent(struct DateStruct* S, string *Event)
- {
- for (int i = 0; i<100; i++)
- S->Event[i] = Event[i];
- }
- //MyDate.h
- #pragma once
- #include "string"
- using namespace std;
- class Date
- {
- public:
- int Day[100]; //день
- int Month[100]; //месяц
- int Year[100]; //год
- string Date_s[100];
- string Event[100]; // массив 100 элементов - события
- int countEvent = 0; // счетчик количества событий
- int countDate = 0; // счетчик количества дней
- public:
- void SetDay(int Day);
- void SetMonth(int Month);
- void SetYear(int Year);
- void Plus(int, int, int);// увеличение на 1 день
- void Minus(int, int, int);// уменьшение на 1 день
- void Calculating(int,int,int);// вычисление количества дней до заданной даты
- void Print(int, int, int);// Вывод текущей даты, просмотр списка событий
- void Clear(int, int, int);// Очистка списка событий по дате
- void AddEvent(int, int, int, string); // Добавление события к дате
- };
- //MyDate.cpp
- #include "stdafx.h"
- #include <iostream>
- #include "MyDate.h"
- //---------------------------------------------------
- void Date::SetDay(int _Day)
- {
- Day[countDate] = _Day;
- }
- void Date::SetMonth(int _Month)
- {
- Month[countDate] = _Month;
- }
- void Date::SetYear(int _Year)
- {
- Year[countDate] = _Year;
- countDate++;
- }
- void Date::Plus(int d, int m, int y)
- {
- for (int i = 0; i < countDate; i++)
- if (Day[i] == d && Month[i] == m && Year[i] == y)
- Day[i] += 1;
- }
- void Date::Minus(int d, int m, int y)
- {
- for (int i = 0; i < countDate; i++)
- if (Day[i] == d && Month[i] == m && Year[i] == y)
- Day[i] -= 1;
- }
- void Date::Calculating(int d, int m, int y)
- {
- }
- void Date::Print(int d, int m, int y)
- {
- cout << "Список событий для " << d << "." << m << "." << y << endl;
- for (int i = 0; i < countDate; i++)
- if (Day[i] == d && Month[i] == m && Year[i] == y)
- {
- for (int j = 0; j < countEvent; j++)
- cout << "Событие [" << j << "] -> " << Event[j] << endl;
- return;
- }
- cout << "Список пуст" << endl;
- }
- void Date::Clear(int d, int m, int y)
- {
- for (int i = 0; i < countDate; i++)
- if (Day[i] == d && Month[i] == m && Year[i] == y)
- for (int j = 0; j < countEvent; j++)
- {
- Event[j] = "";
- countEvent--;
- }
- }
- void Date::AddEvent(int d, int m, int y, string ev)
- {
- for (int i = 0; i < countDate; i++)
- if (Day[i] == d && Month[i] == m && Year[i] == y)
- {
- cout << "Добавлено" << endl;
- Event[countEvent] = ev;
- countEvent++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment