SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. struct Spm {
  10.     char NameLast[20];
  11.     int Num;
  12.     int try_1;
  13.     int try_2;
  14.     int try_3;
  15.     Spm* Next;
  16. };
  17. class List
  18. {
  19.     Spm* Head;
  20. public:
  21.     List() :Head(NULL) {};
  22.     //(Head = NULL)
  23.     ~List();
  24.     void ReadFromFile();
  25.     void Add();
  26.     void Show();
  27.     void LoadToFile();
  28. };
  29. List::~List()
  30. {
  31.     while (Head != NULL)
  32.     {
  33.         Spm* temp = Head->Next;
  34.         delete Head;
  35.         Head = temp;
  36.     };
  37. }
  38.  
  39. void List::ReadFromFile()
  40. {
  41.     ifstream fin("sportsmen.txt");
  42.     Spm* temp;
  43.     if (fin.is_open()) {
  44.         cout << "File is open" << endl;
  45.         while (!fin.eof())
  46.         {
  47.             temp = new Spm;
  48.             fin >> temp->NameLast >> temp->Num >> temp->try_1 >> temp->try_2 >> temp->try_3;
  49.             temp->Next = Head;
  50.             Head = temp;
  51.         }
  52.         cout << "Data is recevied" << endl;
  53.         fin.close();
  54.     }
  55.     else cout << "File is not found";
  56. }
  57.  
  58. void List::Show() {
  59.     Spm* temp = Head;
  60.     system("cls");
  61.     cout << setw(20) << "NameLast" << setw(20) << "Number" << setw(20) << "Try 1" << setw(20) << "Try 2" << setw(20) << "Try 3" << endl;
  62.     cout << "_______________________________________________________________________________________________" << endl << endl;
  63.     while (temp != NULL)
  64.     {
  65.         cout << setw(20) << temp->NameLast;
  66.         cout << setw(20) << temp->Num;
  67.         cout << setw(20) << temp->try_1;
  68.         cout << setw(20) << temp->try_2;
  69.         cout << setw(20) << temp->try_3 << endl;
  70.         temp = temp->Next;
  71.     }
  72.     cout << "_______________________________________________________________________________________________" << endl << endl;
  73.  
  74. }
  75. void List::Add()
  76. {
  77.     Spm sp;
  78.     Spm* temp = new Spm;
  79.     temp->Next = Head;
  80.     system("cls");
  81.     cin.ignore();
  82.     cout << "NameLast: "; cin.getline(sp.NameLast, 20);
  83.     cout << "Number: "; cin >> sp.Num;
  84.     cin.ignore();
  85.     cout << "Try 1: "; cin >> sp.try_1;
  86.     cin.ignore();
  87.     cout << "Try 2: "; cin >> sp.try_2;
  88.     cin.ignore();
  89.     cout << "Try 3: "; cin >> sp.try_3;
  90.     cin.ignore();
  91.  
  92.     strcpy(temp->NameLast, sp.NameLast);
  93.     temp->Num, sp.Num;
  94.     temp->try_1, sp.try_1;
  95.     temp->try_2, sp.try_2;
  96.     temp->try_3, sp.try_3;
  97.     Head = temp;
  98. }
  99. void List::LoadToFile() {
  100.     char file_name[30];
  101.     system("cls");
  102.     cout << "Input file name:   ";
  103.     cin >> file_name;
  104.     ofstream fout(file_name);
  105.     {
  106.         Spm* temp = Head;
  107.         while (temp != NULL)
  108.         {
  109.             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;
  110.             temp = temp->Next;
  111.         }
  112.         cout << "File is completed" << endl;
  113.         system("pause");
  114.         fout.close();
  115.     }
  116. }
  117.  
  118. int main() {
  119.     cout.setf(ios::left);
  120.     bool flag = true;
  121.     int choice;
  122.     Spm spm;
  123.     List spisok;
  124.     while (flag)
  125.     {
  126.         system("cls");
  127.         cout << "               MENU" << endl;
  128.         cout << "_______________________________________________________" << endl;
  129.         cout << "1: Read from the file" << endl;
  130.         cout << "2: Show list" << endl;
  131.         cout << "3: Add student" << endl;
  132.         cout << "4: Save to the file" << endl;
  133.         cout << "5: Delete the record" << endl;
  134.         cout << "6: Search" << endl;
  135.         cout << "7: Sort" << endl;
  136.         cout << "8: Exit" << endl;
  137.         cout << "_______________________________________________________" << endl << endl;
  138.         cout << "Make your choice (1-8): ";
  139.         cin >> choice;
  140.         switch (choice)
  141.         {
  142.         case 1: spisok.ReadFromFile();
  143.             system("PAUSE");
  144.             break;
  145.         case 2: spisok.Show();
  146.             system("PAUSE");
  147.             break;
  148.             case 3: spisok.Add();
  149.                 break;
  150.             case 4: spisok.LoadToFile();
  151.                 break;
  152.         case 8: flag = false;
  153.             break;
  154.         default: {cout << "You are  wrong.  " << endl; system("pause"); }
  155.  
  156.         }
  157.     }
  158.     system("PAUSE");
  159.     return 0;
  160. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top