0 / 0 / 0
Регистрация: 10.12.2019
Сообщений: 27
|
|
1 | |
Програма связанная с бд22.05.2021, 16:16. Показов 230. Ответов 0
Метки нет (Все метки)
У меня есть программа, в ней заложен текстовик, с которого она считывает либо вводит данные, должно получится что-то вроде базы данных.
Мне нужно переработать єту программу, что-бы не было заметно, что она взята с нее, тему можно выбрать любую, начиная от автосалона либо что-то в єтом роде, заканчивая библиотекой, чисто любую на свой вкус. Кликните здесь для просмотра всего текста
Текст програми
#include <iostream> #include <sstream> #include <fstream> #include <cstdio> #include <cstring> #include <vector> #include <limits> #include <algorithm> #include <ctime> using namespace std; string mainData; string temp; string data; int sfN = 0, sfDa = 0, sfS = 0, sfDi = 0, svN = 0, svV = 0, svD = 0; class Movies { private: struct Film { string name; string studio; string genre; string date; string director; string cast; string content; string rating; string have; string FIO; string deadline; Film(string name, string studio, string genre, string date, string director, string cast, string content, string rating, string have, string FIO, string deadline) { this -> name = name; this -> studio = studio; this -> genre = genre; this -> date = date; this -> director = director; this -> cast = cast; this -> content = content; this -> rating = rating; this -> have = have; this -> FIO = FIO; this -> deadline = deadline; } }; vector<Film>films; static string cO(string buffer, char sep, int index)//poluchenie texta v zavisimosti ot indexa { string result; int currentIndex = 1; for(auto it : buffer) { if(it != sep) { result = result + it; } else if(it == sep && currentIndex == index) { return result; } else { result = ""; currentIndex++; } } return result; } void write()//perezapis' dannih v fail { ofstream out; out.open("test/q.txt"); if (out.is_open()) { for(int i = 0; i < films.size(); ++i) { out << films[i].name << ";\n"; out << films[i].studio << ";\n"; out << films[i].genre << ";\n"; out << films[i].date << ";\n"; out << films[i].director << ";\n"; out << films[i].cast << ";\n"; out << films[i].content << ";\n"; out << films[i].rating << ";\n"; out << films[i].have << ";\n"; out << films[i].FIO << ";\n"; out << films[i].deadline << ";" << "/\n"; } } out.close(); } void ListMovieMenu() { int choice = 0; if(!films.empty()) { printf("1) Add new movie\ \n2) Edit movie\ \n3) Delete movie\ \n4) Sort movies\ \n5) Back\ \n6) Exit\n"); }else { printf("1) Add new movie\ \n2) Back\ \n3) Exit\n"); } cin >> choice; choiceListMovieMenu(choice); } void choiceMainMenu(int choice) { switch(choice) { case 1: listOfMovie(); ListMovieMenu(); break; case 2: listVisitors(); break; case 3: giveMovie(); break; case 4: getMovie(); break; case 5: exit(1); } } void listVisitors()//spisok posetiteley { system("cls"); int ink = 1; int choice = 0; cout << "==============================" << endl; for(int i = 0; i < films.size(); ++i) { if(films[i].have == "false") { printf("%d)\n",ink); cout << "Visitor's name: " << films[i].FIO << endl; cout << "Film name: " << films[i].name << endl; cout << "Deadline: " << films[i].deadline << endl; cout << "==============================" << endl; ink++; } } printf("1)Sort\ \n2)Back\ \n3)Exit\n"); cin >> choice;//vibor v nemu if(choice == 1)sortVisitorsMode(); if(choice == 2)menu(); if(choice == 3)exit(1); } void sortVisitorsMode()//sort. posetiteley { system("cls"); int choice = 0; string mode; printf("1) Sort by Visitor's name:\ \n2) Sort by Movie name:\ \n3) Sort by Deadline:\ \n4) Back\ \n5) Exit\n"); printf("Choose sorting type\n"); cin >> choice; //vibor tipa sort. sortVisitors(choice); } void sortVisitors(int choice)//sort. posetiteley cherez l9mbdu { switch(choice) { case 1: if(svV == 0 ){ sort(films.begin(), films.end(), [](Film &first, Film &second){return first.FIO < second.FIO;}); svV = 1; } else {sort(films.begin(), films.end(), [](Film &first, Film &second){return first.FIO > second.FIO;}); svV = 0;} break; case 2: if(svN == 0 ){ sort(films.begin(), films.end(), [](Film &first, Film &second){return first.name < second.name;}); svN = 1; } else {sort(films.begin(), films.end(), [](Film &first, Film &second){return first.name > second.name;}); svN = 0;} break; case 3: if(svD == 0 ){ sort(films.begin(), films.end(), [](Film &first, Film &second){return first.deadline < second.deadline;}); svD = 1; } else {sort(films.begin(), films.end(), [](Film &first, Film &second){return first.deadline > second.deadline;}); svD = 0;} break; listVisitors(); case 5: exit(1); } listVisitors(); } void giveMovie()//vidacha fil'ma { string name_; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); printf("Enter movie name:\n"); getline(cin, name_, '\n'); auto it = find(&films.begin() -> name, &films.end() -> name, name_); if(*it == name_ && films[vInd(films, name_)].have == "true") { printf("Enter your Name:\n"); getline(cin, films[vInd(films, name_)].FIO, '\n'); films[vInd(films, name_)].have = "false"; cout << films[vInd(films, name_)].FIO << endl; time_t now = time(0);//use unix dl9 deadline now = now + 86400 * 7;// tm *ltm = localtime(&now);// films[vInd(films, name_)].deadline = to_string(ltm->tm_mday) + "." + to_string(ltm->tm_mon + 1) + "." + to_string(ltm->tm_year + 1900); } write(); menu(); } void getMovie()//poluchenie fil'ma { string name_; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); printf("Enter movie name\n"); getline(cin, name_, '\n'); auto it = find(&films.begin() -> name, &films.end() -> name, name_); if(*it == name_ && films[vInd(films, name_)].have == "false") { films[vInd(films, name_)].have = "true"; films[vInd(films, name_)].FIO = "-"; films[vInd(films, name_)].deadline = "0.0.0000"; } write(); menu(); } void choiceListMovieMenu(int choice) { if(!films.empty()) { switch(choice) { case 1: addNewMovie(); break; case 2: editMovie(); break; case 3: delMovie(); break; case 4: choiceSortMode(); break; case 5: menu(); break; case 6: exit(1); break; } }else { switch(choice) { case 1: addNewMovie(); break; case 2: menu(); break; case 3: exit(1); break; } } } void choiceSortMode() { system("cls"); int choice = 0; string mode; printf("1) Sort by name\ \n2) Sort by date\ \n3) Sort by studio\ \n4) Sort by director\ \n5) Back\ \n6) Exit\n"); printf("Choose sorting type:\n"); cin >> choice; sortMovie(choice); } void addNewMovie() //dobavlenie fil'ma v vector { system("cls"); cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); string nameL; printf("Enter the name of the movie:\n"); getline(cin , nameL); string studioL; printf("\nEnter the name of the studio:\n"); getline(cin, studioL); string genreL; printf("\nEnter the genre of the movie:\n"); getline(cin, genreL); string dateL; printf("\nEnter the date of the movie:\n"); getline(cin, dateL); string directorL; printf("\nEnter the director of the movie:\n"); getline(cin, directorL); string castL; printf("\nEnter the cast of the movie:\n"); getline(cin, castL); string contenL; printf("\nEnter the conten of the movie:\n"); getline(cin, contenL); string ratingL; printf("\nEnter the rating of the movie:\n"); getline(cin, ratingL); films.emplace_back(Film(nameL, studioL, genreL, dateL, directorL, castL, contenL, ratingL, "true", "-", "0.0.0000")); write(); listOfMovie(); ListMovieMenu(); } void editMovie() //izmenenie fil'ma { int numb = 0; string edit; system("cls"); listOfMovie(); printf("Enter the number of the movie:\n"); cin >> numb; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); printf("Edit name:\n"); getline(cin, edit, '\n'); if(edit != "") films[numb - 1].name = edit; printf("Edit studio:\n"); getline(cin, edit, '\n'); if(edit != "") films[numb - 1].studio = edit; printf("Edit genre:\n"); getline(cin, edit, '\n'); if(edit != "") films[numb - 1].genre = edit; printf("Edit date:\n"); getline(cin, edit, '\n'); if(edit != "") films[numb - 1].date = edit; printf("Edit director:\n"); getline(cin, edit, '\n'); if(edit != "") films[numb - 1].director = edit; printf("Edit cast:\n"); getline(cin, edit, '\n'); if(edit != "") films[numb - 1].cast = edit; printf("Edit conten:\n"); getline(cin, edit, '\n'); if(edit != "") films[numb - 1].content = edit; printf("Edit rating:\n"); getline(cin, edit, '\n'); if(edit != "") films[numb - 1].rating = edit; write(); listOfMovie(); ListMovieMenu(); } void delMovie()//udalenie fil'ma { system("cls"); int number = 0; printf("Enter the number of the movie.\nIf you want to delete all movies enter '0'\n"); cin >> number; if(number == 0) { films.clear(); } else if(number > 0 ) { films.erase(films.begin() - 1 + number); } else { printf("Enter correct number\n"); } write(); listOfMovie(); ListMovieMenu(); } void sortMovie(int choice)//sort. fil'mov cherez l9mbda { system("cls"); switch(choice) { case 1 : if(sfN == 0 ){ sort(films.begin(), films.end(), [](Film &first, Film &second){return first.name < second.name;}); sfN = 1; } else {sort(films.begin(), films.end(), [](Film &first, Film &second){return first.name > second.name;}); sfN = 0;} break; case 2: if(sfDa == 0 ){ sort(films.begin(), films.end(), [](Film &first, Film &second){return first.date < second.date;}); sfDa = 1; } else {sort(films.begin(), films.end(), [](Film &first, Film &second){return first.date > second.date;}); sfDa = 0;} break; case 3: if(sfS == 0 ){ sort(films.begin(), films.end(), [](Film &first, Film &second){return first.studio < second.studio;}); sfS = 1;} else { sort(films.begin(), films.end(), [](Film &first, Film &second){return first.studio > second.studio;}); sfS = 0;} break; case 4: if(sfDi == 0 ){ sort(films.begin(), films.end(), [](Film &first, Film &second){return first.director < second.director;}); sfDi = 1;} else { sort(films.begin(), films.end(), [](Film &first, Film &second){return first.director > second.director;}); sfDi = 0;} break; } listOfMovie(); ListMovieMenu(); } void listOfMovie()//vivod fil'mov { system("cls"); cout << "==============================" << endl; for(int i = 0; i < films.size(); ++i) { printf("%d)\n",i + 1); cout << "Name: " << films[i].name << endl; cout << "Studio: " << films[i].studio << endl; cout << "Genre: " << films[i].genre << endl; cout << "Date: " << films[i].date << endl; cout << "Director: " << films[i].director << endl; cout << "Cast: " << films[i].cast << endl; cout << "Content: " << films[i].content << endl; cout << "Rating: " << films[i].rating << endl; cout << "Have: " << films[i].have << endl; if(films[i].have == "false") { cout << "Visitor's name: " << films[i].FIO << endl; cout << "Deadline: " << films[i].deadline << endl; } cout << "==============================" << endl; } } static int vInd(vector<Film>& films, string obj)//poluchenie indexa v zavisimosti ot ob'ekta { int i = 0; for(auto it : films) { if(it.name == obj) break; i++; } return i; } public: void fill() //schitivanie dannih s faila i dobavlenie ih v vector { ifstream in("test/q.txt"); while(getline(in, temp)) {mainData = mainData + temp;} in.close(); istringstream iss(mainData); while(getline(iss, data, '/')) { films.emplace_back(Film(cO(data, ';', 1), cO(data, ';', 2), cO(data, ';', 3), cO(data, ';', 4), cO(data, ';', 5), cO(data, ';', 6), cO(data, ';', 7), cO(data, ';', 8), cO(data, ';', 9), cO(data, ';', 10), cO(data, ';', 11))); } } void menu() { system("cls"); int choice = 0; printf("(1)List of Movie\ \n(2)List of Visitors\ \n(3)Give Movie\ \n(4)Get Movie\ \n(5)Exit\n"); cin >> choice; system("cls"); choiceMainMenu(choice); } }; int main() { setlocale(0, ""); Movies q; q.fill(); q.menu(); system("pause"); }
0
|
22.05.2021, 16:16 | |
Ответы с готовыми решениями:
0
консольная програма, но ка сделать чтоб програма выполнялась, а консоль не открывалась?? Ошибка связанная с MV C++ Связанная таблица связанная таблица |
22.05.2021, 16:16 | |
22.05.2021, 16:16 | |
Помогаю со студенческими работами здесь
1
прога на С++,связанная с файлами Задача связанная с IP камерой Ошибка связанная с кодировками Ошибка, связанная с памятью Ошибка связанная с string Ошибка связанная с гетч Искать еще темы с ответами Или воспользуйтесь поиском по форуму: |