C++ Адаптируйте код под VisualStudio 2010 (код представлен с адаптацией под 2017)
[email protected] в категроии Информатика, вопрос открыт 26.05.2018 в 20:33
#include <iostream>#include <string>#include <fstream>#include <vector>#include <cstdlib>#include <algorithm> using namespace std; struct Student{ string surname; string name; string patron; int birth; int study; string group; string department; void load(fstream &fin) { fin >> surname >> name >> patron >> birth >> study >> group >> department; } void input() { cout << "Input data for new student" << endl; cout << "Surname: "; cin >> surname; cout << "Name: "; cin >> name; cout << "Patronymic: "; cin >> patron; cout << "Birth year: "; cin >> birth; cout << "Study year: "; cin >> study; cout << "Group: "; cin >> group; cout << "Department: "; cin >> department; } void print() { cout << surname << " " << name << " " << patron << " " << birth << " " << study << " " << group << " " << department << endl; } void save(fstream &fout) { fout << surname << " " << name << " " << patron << " " << birth << " " << study << " " << group << " " << department << endl; }}; vector<Student> stud; void exit(){ cout << "Bye." << endl;} void print(){ cout << endl; int n = stud.size(); for (int i = 0; i<n; i++) { cout << i + 1 << " "; stud[i].print(); }} void load(){ stud.clear(); fstream fin("C:\\Users\\lordi\\Desktop\\data.txt", fstream::in); if (!fin) cout << "Can't open file" << endl; else cout << "Complite!" << endl; int n; fin >> n; Student s; for (int i = 0; i<n; i++) { s.load(fin); stud.push_back(s); } fin.close();} void save(){ fstream fout("C:\\Users\\lordi\\Desktop\\data.txt", fstream::out); fout << stud.size() << endl; for (auto &s : stud) s.save(fout) fout.close();} void add(){ Student s; s.input(); stud.push_back(s);} void edit(){ print(); int i; cout << "input # to edit: "; cin >> i; stud[i - 1].input();} void sort(){ int n; cout << "Sort by: 1-Surname, 2-Name, 3-Patronymic, 4-Birth year, 5-Study year, 6-Group, 7-Department" << endl; cout << "You choise: "; cin >> n; if (n == 1) sort(stud.begin(), stud.end(), [](const Student& s1, const Student& s2) { return s1.surname < s2.surname; }); if (n == 2) sort(stud.begin(), stud.end(), [](const Student& s1, const Student& s2) { return s1.name < s2.name; }); if (n == 3) sort(stud.begin(), stud.end(), [](const Student& s1, const Student& s2) { return s1.patron < s2.patron; }); if (n == 4) sort(stud.begin(), stud.end(), [](const Student& s1, const Student& s2) { return s1.birth < s2.birth; }); if (n == 5) sort(stud.begin(), stud.end(), [](const Student& s1, const Student& s2) { return s1.study < s2.study; }); if (n == 6) sort(stud.begin(), stud.end(), [](const Student& s1, const Student& s2) { return s1.group< s2.group; }); if (n == 7) sort(stud.begin(), stud.end(), [](const Student& s1, const Student& s2) { return s1.department< s2.department; }); print();} void search(){ int n; cout << "Search by: 1-Surname, 2-Name, 3-Patronymic, 4-Birth year, 5-Study year, 6-Group, 7-Department" << endl; cout << "You choise: "; cin >> n; string str; cout << "Find what: "; cin >> str; cout << endl; for (auto& s : stud) { if (n == 1 && s.surname.find(str) != string::npos) s.print(); if (n == 2 && s.name.find(str) != string::npos) s.print(); if (n == 3 && s.patron.find(str) != string::npos) s.print(); if (n == 4 && s.birth == stoi(str)) s.print(); if (n == 5 && s.study == stoi(str)) s.print(); if (n == 6 && s.group.find(str) != string::npos) s.print(); if (n == 7 && s.department.find(str) != string::npos) s.print(); } cout << endl;} int menu(){ cout << "0-Exit " << "1-Load " << "2-Print " << "3-Add " << "4-Edit " << "5-Search " << "6-Sort " << "7-Save" << endl; int choise = 0; cout << "> "; cin >> choise; return choise;} void(*func[])() = { exit, load, print, add, edit, search, sort, save }; int main(){ int choise; do { choise = menu(); func[choise](); cout << endl; } while (choise != 0);}
0 ответов
Зарегистрируйтесь или авторизируйтесь на сайте чтобы оставить ответ на вопрос.