Advertisement
Garey

Untitled

Dec 17th, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. // ConsoleApplication5.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include <iostream>
  5. #include<fstream>
  6. #include<string>
  7.  
  8. using namespace std;
  9.  
  10. struct korabi
  11. {
  12.     string marshrut;
  13.     string ime;
  14.     int ndata;
  15.     int kdata;
  16.     string kapitan;
  17.     string konteiner;
  18.     string sum;
  19.  
  20. };
  21.  
  22.  
  23. void input(korabi[], int &n);
  24. void output(korabi[], int &n);
  25. void prodljitelnost(korabi k[], int &n);
  26. int main()
  27. {
  28.     int n;
  29.     int ch;
  30.     korabi k[20];
  31.     do {
  32.         cout << "\n 1.Input information about shiping transports and show it to display:";
  33.         cout << "\n 2. Search by a name:";
  34.         cout << "\n 3. Which is biggest shipping transport:";
  35.         cout << "\n 4.Exit.";
  36.         cout << "\n Your choice is:";
  37.         cin >> ch;
  38.         switch (ch)
  39.         {
  40.         case 1:
  41.             input(k, n);
  42.  
  43.             break;
  44.         case 2:
  45.             output(k, n);
  46.             break;
  47.         case 3:
  48.             prodljitelnost(k, n);
  49.             break;
  50.         }
  51.     } while (ch!=4);
  52.  
  53.     return 0;
  54.  
  55. }
  56.  
  57.  
  58. void input(korabi k[], int &n)
  59. {
  60.     fstream fp;
  61.     fp.open("prevozi.dat", ios::binary | ios::out);
  62.  
  63.     cout << "\n How much ships:";
  64.     cin >> n;
  65.     int i;
  66.     for (i = 0; i < n; i++)
  67.     {
  68.         cin.ignore();
  69.         cout << "\n What is the route of the ship:";
  70.         getline(cin, k[i].marshrut);
  71.         cout << "\n What is the name of the ship:";
  72.         cin >> k[i].ime;
  73.         cout << "\n What is the first date:";
  74.         cin >> k[i].ndata;
  75.         cout << "\n What is the end date:";
  76.         cin >> k[i].kdata;
  77.         cout << "\n What is the name of the captain:";
  78.         cin >> k[i].kapitan;
  79.         cout << "\n What is the count of the trailers:";
  80.         cin >> k[i].konteiner;
  81.         cout << "\n What is the all incoming funds:";
  82.         cin >> k[i].sum;
  83.     }
  84.     for (i = 0; i < n; i++) {
  85.         cout << "\nName: " << k[i].ime << "|" << "\nFirst date:" << k[i].ndata << "|" << "\nEnd date:" << k[i].kdata << "|" << "\nName of captain:" << k[i].kapitan << "|" << "\nCount of the trailers:" << k[i].konteiner << "|" << "\nAll funds:" << k[i].sum << endl;
  86.     }
  87.     fp.write((char*)(&k), n * sizeof(k));
  88.     fp.close();
  89. }
  90. void output(korabi k[], int &n)
  91. {
  92.     fstream fp;
  93.     fp.open("prevozi.dat", ios::binary | ios::in);
  94.     fp.read((char*)(&k), n * sizeof(k));
  95.  
  96.     bool choice = true;
  97.     char ch;
  98.     while (choice)
  99.     {
  100.         string name;
  101.         cout << "\n Enter name to search:";
  102.         cin >> name;
  103.  
  104.         for (int i = 0; i < n; i++) {
  105.             if(strcmp(k[i].ime.c_str(), name.c_str())==0)
  106.                 cout << "\nName: " << k[i].ime << "|" << "\nFirst date:" << k[i].ndata << "|" << "\nEnd date:" << k[i].kdata << "|" << "\nName of captain:" << k[i].kapitan << "|" << "\nCount of the trailers:" << k[i].konteiner << "|" << "\nAll funds:" << k[i].sum << endl;
  107.         }
  108.         cout << "\n Do you want a new research:";
  109.         cin >> ch;
  110.         if (ch == 'n')
  111.             choice = false;
  112.     }fp.close();
  113. }
  114. void prodljitelnost(korabi k[], int &n) {
  115.     fstream fp;
  116.     fp.open("prevozi.dat", ios::binary | ios::out);
  117.     fp.read((char*)(&k), n * sizeof(k));
  118.  
  119.     korabi max = k[0];
  120.    
  121.     for (int i = 0; i < n; i++) {
  122.         int diffDate_k, diffDate_max;
  123.    
  124.         if (k[i].ndata > k[i].kdata)
  125.             diffDate_k = k[i].ndata - k[i].kdata;
  126.         else
  127.             diffDate_k = k[i].kdata - k[i].ndata;
  128.  
  129.         if (max.ndata > max.kdata)
  130.             diffDate_max = max.ndata - max.kdata;
  131.         else
  132.             diffDate_max = max.kdata - max.ndata;
  133.        
  134.         if (diffDate_k > diffDate_max) {
  135.             max = k[i];
  136.         }
  137.     }
  138.  
  139.     cout << "\nName: " << max.ime << "|" << "\nFirst date:" << max.ndata << "|" << "\nEnd date:" << max.kdata << "|" << "\nName of captain:" << max.kapitan << "|" << "\nCount of the trailers:" << max.konteiner << "|" << "\nAll funds:" << max.sum << endl;
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement