Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. //
  2. // Created by Nazar on 04.12.2016.
  3. //
  4. /*
  5. #include <iostream>
  6. #include <cstdio>
  7. #include <vector>
  8.  
  9. using namespace std;
  10.  
  11.  
  12.  
  13. class Items
  14. {
  15. public:
  16.     int id;
  17.     char Name[20];
  18.     int Weight;
  19.     int Price;
  20. };
  21.  
  22. class Users
  23. {
  24. public:
  25.     int id;
  26.     char Login[20];
  27.     char Password[20];
  28.     int Status;
  29. };
  30.  
  31. void OutputItems(vector<Items> items);
  32. void OutputUsers(vector<Users> users);
  33. void AddNewItem(vector<Items> items, Items item1, FILE *dataF);
  34. //int CheckIfUserExists(vector<Users> users, FILE *logPass);
  35.  
  36. int main()
  37. {
  38.     // DO THIS AT THE START OF THE PROGRAM
  39.     // DO THIS AT THE START OF THE PROGRAM
  40.     // DO THIS AT THE START OF THE PROGRAM
  41.     vector<Items> items;
  42.     vector<Users> users;
  43.     Items item1;
  44.     Users user1;
  45.     // open datafile
  46.     FILE *dataF = NULL;
  47.     dataF = fopen("datafile.txt" , "r+");
  48.     // open logins and passwords file
  49.     FILE *logPass = NULL;
  50.     logPass = fopen("logPass.txt", "r+");
  51.     // read from files
  52.     if (dataF != NULL)
  53.     {
  54.         while (!feof(dataF))
  55.         {
  56.             fscanf(dataF, "%i%s%i%i", &item1.id, &item1.Name , &item1.Weight , &item1.Price);
  57.             items.push_back(item1);
  58.         }
  59.     }
  60.     else
  61.     {
  62.         cout << "Cannot open file datafile.txt" << endl;
  63.     }
  64.     if (logPass != NULL)
  65.     {
  66.         while (!feof(logPass))
  67.         {
  68.             fscanf(logPass, "%i%s%s%i", &user1.id, &user1.Login, &user1.Password, &user1.Status);
  69.             users.push_back(user1);
  70.         }
  71.     }
  72.     else
  73.     {
  74.         cout << "Cannot open file datafile.txt" << endl;
  75.     }
  76.     // END START OF PROGRAM
  77.     // END START OF PROGRAM
  78.     // END START OF PROGRAM
  79.  
  80.     //output id and name
  81.     OutputItems(items);
  82.     OutputUsers(users);
  83.  
  84.     AddNewItem(items, item1, dataF);
  85.  
  86.     fclose(dataF);
  87.     fclose(logPass);
  88.     OutputItems(items);
  89.     OutputUsers(users);
  90.  
  91.     AddNewItem(items, item1, dataF);
  92.  
  93.     fclose(dataF);
  94.     fclose(logPass);
  95.     system("pause");
  96.     return 0;
  97. }
  98.  
  99. void OutputItems(vector<Items> items)
  100. {
  101.     cout << "Items: \n";
  102.     for (int i = 0; i < items.size(); ++i)
  103.     {
  104.         cout << items[i].id << " " << items[i].Name << " "
  105.              << items[i].Weight << " " << items[i].Price << endl;
  106.     }
  107. }
  108.  
  109. void OutputUsers(vector<Users> users)
  110. {
  111.     cout << "Users: \n";
  112.     for (int i = 0; i < users.size(); ++i)
  113.     {
  114.         cout << users[i].id << " " << users[i].Login << " "
  115.              << users[i].Password << " " << users[i].Status << endl;
  116.     }
  117. }
  118.  
  119. void AddNewItem(vector<Items> items, Items item1, FILE *dataF)
  120. {
  121.     cout << "enter id" << endl;
  122.     cin >> item1.id;
  123.     cout << "enter name" << endl;
  124.     cin >> item1.Name;
  125.     cout << "enter Weight" << endl;
  126.     cin >> item1.Weight;
  127.     cout << "enter Price" << endl;
  128.     cin >> item1.Price;
  129.     items.push_back(item1);
  130.     fprintf(dataF, "\n%i %s %i %i", item1.id, item1.Name, item1.Weight, item1.Price);
  131. }
  132. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement