Advertisement
Garey

Read/Write/Search

Dec 13th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. struct Vlogove{
  9.     string ime;
  10.     string familiq;
  11.     string egn;
  12.  
  13.     double vlog_v_leva;
  14.     double vlog_v_evro;
  15. };
  16.  
  17. void vuvejdane_na_vlogove(Vlogove [], int &);
  18. void tursene_po_ime_i_familiq(Vlogove[], int &);
  19.  
  20. int main() {
  21.  
  22.     int n;
  23.  
  24.     Vlogove vlog[25];
  25.  
  26.     vuvejdane_na_vlogove(vlog, n);
  27.  
  28.     tursene_po_ime_i_familiq(vlog, n);
  29.  
  30.     return 0;
  31. }
  32.  
  33. void vuvejdane_na_vlogove(Vlogove vlog[], int &n) {
  34.    
  35.     fstream file;
  36.    
  37.     file.open("vlogove.dat", ios::binary | ios::out);
  38.  
  39.     cout << "Vuvedi broi na vlogovete: ";
  40.     cin >> n;
  41.  
  42.     for (int i = 0; i < n; i++) {
  43.         cout << "Vuvedi ime: ";
  44.         cin >> vlog[i].ime;
  45.  
  46.         cout << "Vuvedi familiq: ";
  47.         cin >> vlog[i].familiq;
  48.  
  49.         cout << "Vuvedi egn: ";
  50.         cin >> vlog[i].egn;
  51.  
  52.         cout << "Vuvedi vlog v leva: ";
  53.         cin >> vlog[i].vlog_v_leva;
  54.  
  55.         cout << "Vuvedi vlog v evro: ";
  56.         cin >> vlog[i].vlog_v_evro;
  57.     }
  58.  
  59.     file.write( (char *) (&vlog), n * sizeof(vlog) );
  60.  
  61.     file.close();
  62. }
  63.  
  64. void tursene_po_ime_i_familiq(Vlogove vlog[], int &n) {
  65.     fstream file;
  66.  
  67.     string ime;
  68.     string familiq;
  69.  
  70.     file.open("vlogove.dat", ios::binary | ios::out);
  71.  
  72.     file.read( (char *) (&vlog), n * sizeof(vlog) );
  73.  
  74.  
  75.     cout << "Vuvedi ime po koeto da tursish: ";
  76.     cin >> ime;
  77.  
  78.     cout << "Vuvedi familiq za imeto: ";
  79.     cin >> familiq;
  80.  
  81.     for (int i = 0; i < n; i++) {
  82.         if (strcmp( ime.c_str(), vlog[i].ime.c_str() ) == 0 && strcmp( familiq.c_str(), vlog[i].familiq.c_str() ) == 0 ) {
  83.             cout << "Ime: " << vlog[i].ime << endl;
  84.             cout << "Familiq: " << vlog[i].familiq << endl;
  85.             cout << "EGN: " << vlog[i].egn << endl;
  86.             cout << "Vlog v leva: " << vlog[i].vlog_v_leva << endl;
  87.             cout << "Vlog v evro: " << vlog[i].vlog_v_evro << endl;
  88.         }
  89.     }
  90.  
  91.     file.close();
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement