Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication5.cpp : Defines the entry point for the console application.
- //
- #include <iostream>
- #include<fstream>
- #include<string>
- using namespace std;
- struct korabi
- {
- string marshrut;
- string ime;
- int ndata;
- int kdata;
- string kapitan;
- string konteiner;
- string sum;
- };
- void input(korabi[], int &n);
- void output(korabi[], int &n);
- void prodljitelnost(korabi k[], int &n);
- int main()
- {
- int n;
- int ch;
- korabi k[20];
- do {
- cout << "\n 1.Input information about shiping transports and show it to display:";
- cout << "\n 2. Search by a name:";
- cout << "\n 3. Which is biggest shipping transport:";
- cout << "\n 4.Exit.";
- cout << "\n Your choice is:";
- cin >> ch;
- switch (ch)
- {
- case 1:
- input(k, n);
- break;
- case 2:
- output(k, n);
- break;
- case 3:
- prodljitelnost(k, n);
- break;
- }
- } while (ch!=4);
- return 0;
- }
- void input(korabi k[], int &n)
- {
- fstream fp;
- fp.open("prevozi.dat", ios::binary | ios::out);
- cout << "\n How much ships:";
- cin >> n;
- int i;
- for (i = 0; i < n; i++)
- {
- cin.ignore();
- cout << "\n What is the route of the ship:";
- getline(cin, k[i].marshrut);
- cout << "\n What is the name of the ship:";
- cin >> k[i].ime;
- cout << "\n What is the first date:";
- cin >> k[i].ndata;
- cout << "\n What is the end date:";
- cin >> k[i].kdata;
- cout << "\n What is the name of the captain:";
- cin >> k[i].kapitan;
- cout << "\n What is the count of the trailers:";
- cin >> k[i].konteiner;
- cout << "\n What is the all incoming funds:";
- cin >> k[i].sum;
- }
- for (i = 0; i < n; i++) {
- 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;
- }
- fp.write((char*)(&k), n * sizeof(k));
- fp.close();
- }
- void output(korabi k[], int &n)
- {
- fstream fp;
- fp.open("prevozi.dat", ios::binary | ios::in);
- fp.read((char*)(&k), n * sizeof(k));
- bool choice = true;
- char ch;
- while (choice)
- {
- string name;
- cout << "\n Enter name to search:";
- cin >> name;
- for (int i = 0; i < n; i++) {
- if(strcmp(k[i].ime.c_str(), name.c_str())==0)
- 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;
- }
- cout << "\n Do you want a new research:";
- cin >> ch;
- if (ch == 'n')
- choice = false;
- }fp.close();
- }
- void prodljitelnost(korabi k[], int &n) {
- fstream fp;
- fp.open("prevozi.dat", ios::binary | ios::out);
- fp.read((char*)(&k), n * sizeof(k));
- korabi max = k[0];
- for (int i = 0; i < n; i++) {
- int diffDate_k, diffDate_max;
- if (k[i].ndata > k[i].kdata)
- diffDate_k = k[i].ndata - k[i].kdata;
- else
- diffDate_k = k[i].kdata - k[i].ndata;
- if (max.ndata > max.kdata)
- diffDate_max = max.ndata - max.kdata;
- else
- diffDate_max = max.kdata - max.ndata;
- if (diffDate_k > diffDate_max) {
- max = k[i];
- }
- }
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement