From 3a06cc6c63fbf6041ed84eac9ee1e68a4f5fe6da Mon Sep 17 00:00:00 2001 From: Yoshi31 <62884580+Yoshi31@users.noreply.github.com> Date: Tue, 30 Jun 2020 17:34:01 +0300 Subject: [PATCH 1/3] Add files via upload --- Film.cpp | 18 ++++---- Film.h | 6 +-- Function.cpp | 115 +++++++++++++++++++++++++++++++--------------- Kinoteatr_cpp.cpp | 2 +- 4 files changed, 91 insertions(+), 50 deletions(-) diff --git a/Film.cpp b/Film.cpp index 6f8350d..d51cd27 100644 --- a/Film.cpp +++ b/Film.cpp @@ -9,7 +9,7 @@ Film::Film() { price = 0; } -void Film::SetFilm(string name_value, string genre_value, float ratting_value, int price_value) { +void Film::SetFilm(string name_value, string genre_value, double ratting_value, int price_value) { name = name_value; genre = genre_value; ratting = ratting_value; @@ -23,7 +23,7 @@ string Film:: GetGenre() { return genre; } -float Film::GetRatting() { +double Film::GetRatting() { return ratting; } @@ -33,27 +33,27 @@ int Film::GetPrice() { void Film:: ScanFilm() { setlocale(LC_CTYPE, "Russian"); - cout << "НОВЫЙ ФИЛЬМ" << endl << "Введите данных о фильме" << endl; - cout << "Название:" << endl; + cout << " " << endl << " " << endl; + cout << ":" << endl; cin >> name; - cout << "Жанр:" << endl; + cout << ":" << endl; cin >> genre; - cout << "Рэйтинг:" << endl; + cout << ":" << endl; cin >> ratting; - cout << "Цену за билет:" << endl; + cout << " :" << endl; cin >> price; }; void Film::Print() { setlocale(LC_CTYPE, "Russian"); - cout << "Название: " << name << "\t Жанр: " << genre << "\t Рэйтинг: " << ratting << "\t Цена: " << price << endl; + cout << ": " << name << "\t : " << genre << "\t : " << ratting << "\t : " << price << endl; } void Film::Putinfile(string filename) { ofstream file; file.open(filename, ios_base::app); if (!file) { - cout << "Ошибка работы с файлом" << endl; + cout << " " << endl; return; } file << name << " "; diff --git a/Film.h b/Film.h index 1fa5d95..5d8533a 100644 --- a/Film.h +++ b/Film.h @@ -7,14 +7,14 @@ class Film private: string name; string genre; - float ratting; + double ratting; int price; public: Film(); - void SetFilm(string name_value, string genre_value, float ratting_value, int price_value); + void SetFilm(string name_value, string genre_value, double ratting_value, int price_value); string GetName(); string GetGenre(); - float GetRatting(); + double GetRatting(); int GetPrice(); void ScanFilm(); void Print(); diff --git a/Function.cpp b/Function.cpp index f99a04c..a9bdf0a 100644 --- a/Function.cpp +++ b/Function.cpp @@ -12,39 +12,39 @@ void addfilm(string filename) { film = new Film; film->ScanFilm(); int c; - cout << "Вы дейстительно хотите добавить этот фильм?" << endl; + cout << " ?" << endl; film->Print(); - cout << "1)Да" << endl << "2)Нет" << endl; + cout << "1)" << endl << "2)" << endl; cin >> c; switch (c) { case 1: film->Putinfile(filename); - cout << "Фильм успешно добавлен в базу данных кинотеатра" << endl; + cout << " " << endl; break; case 2: - cout << "Фильм не будет добавлен в базу данных кинотеатра"; + cout << " "; exit(0); default: - cout << "Ошибка" << endl; + cout << "" << endl; } delete film; } -void deletefilm(string filename) { - cout << "Введите название фильма для удаления" << endl; +/*void deletefilm(string filename) { + cout << " " << endl; string deletename; string archiv; cin >> deletename; fstream file; int n, s = 0; - Film *film; + Film* film; film = new Film; file.open(filename); if (!file) { - cout << "Ошибка работы с файлом" << endl; + cout << " " << endl; return; } file.seekg(0, ios_base::end); @@ -58,7 +58,7 @@ void deletefilm(string filename) { //file >> name_value >> genre_value >> ratting_value >> price_value; //film->SetFilm(name_value, genre_value, ratting_value, price_value); s = file.tellg(); - if (deletename != film->GetName()) + if (deletename != film->GetName()) { string rattingstr = to_string(film->GetRatting()); string pricestr = to_string(film->GetPrice()); @@ -67,20 +67,61 @@ void deletefilm(string filename) { } delete film; - } while (s < n - 4); + } while (s < n - 3); file.close(); file.open(filename); if (!file) { - cout << "Ошибка работы с файлом" << endl; + cout << " " << endl; return; } file << archiv; file.close(); - cout << "Фильм был успешно удален!" << endl; + cout << " !" << endl; +}*/ + +void deletefilm(string filename) { + cout << " " << endl; + string deletename; + cin >> deletename; + fstream file; + int n, s = 0; + const int maxsize = 20; + Film *masfilm = new Film[maxsize]; + file.open(filename); + if (!file) { + cout << " " << endl; + return; + } + file.seekg(0, ios_base::end); + n = file.tellg(); + file.seekg(0); + int i = 0; + while (s < (n - 3)) { + file >> masfilm[i]; + i++; + s = file.tellg(); + } + file.close(); + file.open(filename); + file.ios_base::trunc; + if (!file) { + cout << " " << endl; + return; + } + //file.ios_base::trunc; + for (int j = 0; j < maxsize-1; j++) { + if ((masfilm[j].GetName() != deletename) && (masfilm[j].GetName() != "Null")) { + file << masfilm[j]; + masfilm[j].Print(); + } + } + delete[]masfilm; + file.close(); + cout << " !" << endl; } void searchfilm(string filename) { - cout << "Поиск фильмов по:" << endl << "1)Названию" << endl << "2)Жанру" << endl; + cout << " :" << endl << "1)" << endl << "2)" << endl; int c; cin >> c; switch (c) @@ -92,14 +133,14 @@ void searchfilm(string filename) { searchfilm_genre(filename); break; default: - cout << "Ошибка" << endl; + cout << "" << endl; } } void searchfilm_name(string filename) { string check; - cout << "Введите название фильма для поиска" << endl; + cout << " " << endl; cin >> check; ifstream file; int n, s = 0; @@ -108,13 +149,13 @@ void searchfilm_name(string filename) { film = new Film; file.open(filename); if (!file) { - cout << "Ошибка работы с файлом" << endl; + cout << " " << endl; return; } file.seekg(0, ios_base::end); n = file.tellg(); file.seekg(0); - cout << "Список фильмов по вашему запросу:" << endl; + cout << " :" << endl; do { file >> *film; @@ -134,7 +175,7 @@ void searchfilm_name(string filename) { void searchfilm_genre(string filename) { string check; - cout << "Введите жанр фильма для поиска" << endl; + cout << " " << endl; cin >> check; ifstream file; int n, s = 0; @@ -143,13 +184,13 @@ void searchfilm_genre(string filename) { film = new Film; file.open(filename); if (!file) { - cout << "Ошибка работы с файлом" << endl; + cout << " " << endl; return; } file.seekg(0, ios_base::end); n = file.tellg(); file.seekg(0); - cout << "Список фильмов по вашему запросу:" << endl; + cout << " :" << endl; do { file >> *film; @@ -174,7 +215,7 @@ void listfilm(string filename) { film = new Film; file.open(filename); if (!file) { - cout << "Ошибка работы с файлом" << endl; + cout << " " << endl; return; } @@ -197,7 +238,7 @@ void listfilm(string filename) { void changefilm(string filename) { string changename; string archive; - cout << "Введите название фильма который хотите изменить: "; + cout << " : "; cin >> changename; fstream file; int n, s = 0; @@ -206,7 +247,7 @@ void changefilm(string filename) { film = new Film; file.open(filename); if (!file) { - cout << "Ошибка работы с файлом" << endl; + cout << " " << endl; return; } file.seekg(0, ios_base::end); @@ -217,8 +258,8 @@ void changefilm(string filename) { s = file.tellg(); if (changename == film->GetName()) { film->Print(); - cout << "Что вы хотите изменить?"<> c; string newname; @@ -230,33 +271,33 @@ void changefilm(string filename) { switch (c) { case 1: - cout<<"Введите новое название: "; + cout<<" : "; cin >> newname; archive += newname + " " + film->GetGenre() + " " + rattingstr + " " + pricestr + "\n"; - cout << "Название фильма успешно изменено!"<> newgenre; archive += film->GetName() + " " + newgenre + " " + rattingstr + " " + pricestr + "\n"; - cout << "Жанр фильма успешно изменен!" << endl; + cout << " !" << endl; break; case 3: - cout << "Введите новый рейтинг: "; + cout << " : "; cin >> newratting; rattingstr = to_string(newratting); archive += film->GetName() + " " + film->GetGenre() + " " + rattingstr + " " + pricestr + "\n"; - cout << "Рейтинг фильма успешно изменен!" << endl; + cout << " !" << endl; break; case 4: - cout << "Введите новую стоимость: "; + cout << " : "; cin >> newprice; pricestr = to_string(newprice); archive += film->GetName() + " " + film->GetGenre() + " " + rattingstr + " " + pricestr + "\n"; - cout << "Стоимость фильма успешно изменена!" << endl; + cout << " !" << endl; break; default: - cout << "Ошибка" << endl; + cout << "" << endl; } } @@ -270,7 +311,7 @@ void changefilm(string filename) { file.close(); file.open(filename); if (!file) { - cout << "Ошибка работы с файлом" << endl; + cout << " " << endl; return; } file << archive; @@ -294,7 +335,7 @@ int menu_select() do { cout << "---------------------------------------------------------------------------------------------------------------" << endl; - cout << "1 - Добавить фильм" << endl << "2 - Список фильмов" << endl << "3 - Поиск фильма" << endl << "4 - Удалить фильм" << endl << "5 - Изменить фильм" << endl << "6 - выход" << endl << "Ваш выбор: "; + cout << "1 - " << endl << "2 - " << endl << "3 - " << endl << "4 - " << endl << "5 - " << endl << "6 - " << endl << " : "; cin >> s; c = atoi(s); cout << "---------------------------------------------------------------------------------------------------------------" << endl; diff --git a/Kinoteatr_cpp.cpp b/Kinoteatr_cpp.cpp index 1020d8d..93887c0 100644 --- a/Kinoteatr_cpp.cpp +++ b/Kinoteatr_cpp.cpp @@ -4,10 +4,10 @@ #include "Film.h" #include "Function.h" using namespace std; -bool work=true; int main(int argc, char* argv[]) { + bool work = true; setlocale(LC_CTYPE, "Russian"); if (argc != 2) { From 5a3c6174cc3f6710df87cd5c201c19d5d47c36d4 Mon Sep 17 00:00:00 2001 From: Yoshi31 <62884580+Yoshi31@users.noreply.github.com> Date: Tue, 30 Jun 2020 17:35:41 +0300 Subject: [PATCH 2/3] Update Function.cpp --- Function.cpp | 74 ++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/Function.cpp b/Function.cpp index a9bdf0a..2895121 100644 --- a/Function.cpp +++ b/Function.cpp @@ -12,21 +12,21 @@ void addfilm(string filename) { film = new Film; film->ScanFilm(); int c; - cout << " ?" << endl; + cout << "Вы дейстительно хотите добавить этот фильм?" << endl; film->Print(); - cout << "1)" << endl << "2)" << endl; + cout << "1)Да" << endl << "2)Нет" << endl; cin >> c; switch (c) { case 1: film->Putinfile(filename); - cout << " " << endl; + cout << "Фильм успешно добавлен в базу данных кинотеатра" << endl; break; case 2: - cout << " "; + cout << "Фильм не будет добавлен в базу данных кинотеатра"; exit(0); default: - cout << "" << endl; + cout << "Ошибка" << endl; } delete film; @@ -34,7 +34,7 @@ void addfilm(string filename) { } /*void deletefilm(string filename) { - cout << " " << endl; + cout << "Введите название фильма для удаления" << endl; string deletename; string archiv; cin >> deletename; @@ -44,7 +44,7 @@ void addfilm(string filename) { film = new Film; file.open(filename); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } file.seekg(0, ios_base::end); @@ -71,16 +71,16 @@ void addfilm(string filename) { file.close(); file.open(filename); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } file << archiv; file.close(); - cout << " !" << endl; + cout << "Фильм был успешно удален!" << endl; }*/ void deletefilm(string filename) { - cout << " " << endl; + cout << "Введите название фильма для удаления" << endl; string deletename; cin >> deletename; fstream file; @@ -89,7 +89,7 @@ void deletefilm(string filename) { Film *masfilm = new Film[maxsize]; file.open(filename); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } file.seekg(0, ios_base::end); @@ -105,7 +105,7 @@ void deletefilm(string filename) { file.open(filename); file.ios_base::trunc; if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } //file.ios_base::trunc; @@ -117,11 +117,11 @@ void deletefilm(string filename) { } delete[]masfilm; file.close(); - cout << " !" << endl; + cout << "Фильм был успешно удален!" << endl; } void searchfilm(string filename) { - cout << " :" << endl << "1)" << endl << "2)" << endl; + cout << "Поиск фильмов по:" << endl << "1)Названию" << endl << "2)Жанру" << endl; int c; cin >> c; switch (c) @@ -133,14 +133,14 @@ void searchfilm(string filename) { searchfilm_genre(filename); break; default: - cout << "" << endl; + cout << "Ошибка" << endl; } } void searchfilm_name(string filename) { string check; - cout << " " << endl; + cout << "Введите название фильма для поиска" << endl; cin >> check; ifstream file; int n, s = 0; @@ -149,13 +149,13 @@ void searchfilm_name(string filename) { film = new Film; file.open(filename); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } file.seekg(0, ios_base::end); n = file.tellg(); file.seekg(0); - cout << " :" << endl; + cout << "Список фильмов по вашему запросу:" << endl; do { file >> *film; @@ -175,7 +175,7 @@ void searchfilm_name(string filename) { void searchfilm_genre(string filename) { string check; - cout << " " << endl; + cout << "Введите жанр фильма для поиска" << endl; cin >> check; ifstream file; int n, s = 0; @@ -184,13 +184,13 @@ void searchfilm_genre(string filename) { film = new Film; file.open(filename); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } file.seekg(0, ios_base::end); n = file.tellg(); file.seekg(0); - cout << " :" << endl; + cout << "Список фильмов по вашему запросу:" << endl; do { file >> *film; @@ -215,7 +215,7 @@ void listfilm(string filename) { film = new Film; file.open(filename); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } @@ -238,7 +238,7 @@ void listfilm(string filename) { void changefilm(string filename) { string changename; string archive; - cout << " : "; + cout << "Введите название фильма который хотите изменить: "; cin >> changename; fstream file; int n, s = 0; @@ -247,7 +247,7 @@ void changefilm(string filename) { film = new Film; file.open(filename); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } file.seekg(0, ios_base::end); @@ -258,8 +258,8 @@ void changefilm(string filename) { s = file.tellg(); if (changename == film->GetName()) { film->Print(); - cout << " ?"<> c; string newname; @@ -271,33 +271,33 @@ void changefilm(string filename) { switch (c) { case 1: - cout<<" : "; + cout<<"Введите новое название: "; cin >> newname; archive += newname + " " + film->GetGenre() + " " + rattingstr + " " + pricestr + "\n"; - cout << " !"<> newgenre; archive += film->GetName() + " " + newgenre + " " + rattingstr + " " + pricestr + "\n"; - cout << " !" << endl; + cout << "Жанр фильма успешно изменен!" << endl; break; case 3: - cout << " : "; + cout << "Введите новый рейтинг: "; cin >> newratting; rattingstr = to_string(newratting); archive += film->GetName() + " " + film->GetGenre() + " " + rattingstr + " " + pricestr + "\n"; - cout << " !" << endl; + cout << "Рейтинг фильма успешно изменен!" << endl; break; case 4: - cout << " : "; + cout << "Введите новую стоимость: "; cin >> newprice; pricestr = to_string(newprice); archive += film->GetName() + " " + film->GetGenre() + " " + rattingstr + " " + pricestr + "\n"; - cout << " !" << endl; + cout << "Стоимость фильма успешно изменена!" << endl; break; default: - cout << "" << endl; + cout << "Ошибка" << endl; } } @@ -311,7 +311,7 @@ void changefilm(string filename) { file.close(); file.open(filename); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } file << archive; @@ -335,7 +335,7 @@ int menu_select() do { cout << "---------------------------------------------------------------------------------------------------------------" << endl; - cout << "1 - " << endl << "2 - " << endl << "3 - " << endl << "4 - " << endl << "5 - " << endl << "6 - " << endl << " : "; + cout << "1 - Добавить фильм" << endl << "2 - Список фильмов" << endl << "3 - Поиск фильма" << endl << "4 - Удалить фильм" << endl << "5 - Изменить фильм" << endl << "6 - выход" << endl << "Ваш выбор: "; cin >> s; c = atoi(s); cout << "---------------------------------------------------------------------------------------------------------------" << endl; From c03cfee6076b96d58ea67f701647a4f04b8fbc67 Mon Sep 17 00:00:00 2001 From: Yoshi31 <62884580+Yoshi31@users.noreply.github.com> Date: Tue, 30 Jun 2020 17:36:29 +0300 Subject: [PATCH 3/3] Update Film.cpp --- Film.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Film.cpp b/Film.cpp index d51cd27..58db14a 100644 --- a/Film.cpp +++ b/Film.cpp @@ -33,27 +33,27 @@ int Film::GetPrice() { void Film:: ScanFilm() { setlocale(LC_CTYPE, "Russian"); - cout << " " << endl << " " << endl; - cout << ":" << endl; + cout << "НОВЫЙ ФИЛЬМ" << endl << "Введите данных о фильме" << endl; + cout << "Название:" << endl; cin >> name; - cout << ":" << endl; + cout << "Жанр:" << endl; cin >> genre; - cout << ":" << endl; + cout << "Рэйтинг:" << endl; cin >> ratting; - cout << " :" << endl; + cout << "Цену за билет:" << endl; cin >> price; }; void Film::Print() { setlocale(LC_CTYPE, "Russian"); - cout << ": " << name << "\t : " << genre << "\t : " << ratting << "\t : " << price << endl; + cout << "Название: " << name << "\t Жанр: " << genre << "\t Рэйтинг: " << ratting << "\t Цена: " << price << endl; } void Film::Putinfile(string filename) { ofstream file; file.open(filename, ios_base::app); if (!file) { - cout << " " << endl; + cout << "Ошибка работы с файлом" << endl; return; } file << name << " ";