Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <stdlib.h>
- #include <iomanip>
- using namespace std;
- struct Spm {
- char NameLast[20];
- int Num;
- int try_1;
- int try_2;
- int try_3;
- Spm* Next;
- };
- class List
- {
- Spm* Head;
- public:
- List() :Head(NULL) {};
- //(Head = NULL)
- ~List();
- void ReadFromFile();
- void Add();
- void Show();
- void LoadToFile();
- };
- List::~List()
- {
- while (Head != NULL)
- {
- Spm* temp = Head->Next;
- delete Head;
- Head = temp;
- };
- }
- void List::ReadFromFile()
- {
- ifstream fin("sportsmen.txt");
- Spm* temp;
- if (fin.is_open()) {
- cout << "File is open" << endl;
- while (!fin.eof())
- {
- temp = new Spm;
- fin >> temp->NameLast >> temp->Num >> temp->try_1 >> temp->try_2 >> temp->try_3;
- temp->Next = Head;
- Head = temp;
- }
- cout << "Data is recevied" << endl;
- fin.close();
- }
- else cout << "File is not found";
- }
- void List::Show() {
- Spm* temp = Head;
- system("cls");
- cout << setw(20) << "NameLast" << setw(20) << "Number" << setw(20) << "Try 1" << setw(20) << "Try 2" << setw(20) << "Try 3" << endl;
- cout << "_______________________________________________________________________________________________" << endl << endl;
- while (temp != NULL)
- {
- cout << setw(20) << temp->NameLast;
- cout << setw(20) << temp->Num;
- cout << setw(20) << temp->try_1;
- cout << setw(20) << temp->try_2;
- cout << setw(20) << temp->try_3 << endl;
- temp = temp->Next;
- }
- cout << "_______________________________________________________________________________________________" << endl << endl;
- }
- void List::Add()
- {
- Spm sp;
- Spm* temp = new Spm;
- temp->Next = Head;
- system("cls");
- cin.ignore();
- cout << "NameLast: "; cin.getline(sp.NameLast, 20);
- cout << "Number: "; cin >> sp.Num;
- cin.ignore();
- cout << "Try 1: "; cin >> sp.try_1;
- cin.ignore();
- cout << "Try 2: "; cin >> sp.try_2;
- cin.ignore();
- cout << "Try 3: "; cin >> sp.try_3;
- cin.ignore();
- strcpy(temp->NameLast, sp.NameLast);
- temp->Num, sp.Num;
- temp->try_1, sp.try_1;
- temp->try_2, sp.try_2;
- temp->try_3, sp.try_3;
- Head = temp;
- }
- void List::LoadToFile() {
- char file_name[30];
- system("cls");
- cout << "Input file name: ";
- cin >> file_name;
- ofstream fout(file_name);
- {
- Spm* temp = Head;
- while (temp != NULL)
- {
- fout << setw(20) << temp->NameLast << setw(20) << temp->Num << setw(10) << temp->try_1 << setw(10) << temp->try_2 << setw(10) << temp->try_3 << endl;
- temp = temp->Next;
- }
- cout << "File is completed" << endl;
- system("pause");
- fout.close();
- }
- }
- int main() {
- cout.setf(ios::left);
- bool flag = true;
- int choice;
- Spm spm;
- List spisok;
- while (flag)
- {
- system("cls");
- cout << " MENU" << endl;
- cout << "_______________________________________________________" << endl;
- cout << "1: Read from the file" << endl;
- cout << "2: Show list" << endl;
- cout << "3: Add student" << endl;
- cout << "4: Save to the file" << endl;
- cout << "5: Delete the record" << endl;
- cout << "6: Search" << endl;
- cout << "7: Sort" << endl;
- cout << "8: Exit" << endl;
- cout << "_______________________________________________________" << endl << endl;
- cout << "Make your choice (1-8): ";
- cin >> choice;
- switch (choice)
- {
- case 1: spisok.ReadFromFile();
- system("PAUSE");
- break;
- case 2: spisok.Show();
- system("PAUSE");
- break;
- case 3: spisok.Add();
- break;
- case 4: spisok.LoadToFile();
- break;
- case 8: flag = false;
- break;
- default: {cout << "You are wrong. " << endl; system("pause"); }
- }
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement