Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Nazar on 04.12.2016.
- //
- /*
- #include <iostream>
- #include <cstdio>
- #include <vector>
- using namespace std;
- class Items
- {
- public:
- int id;
- char Name[20];
- int Weight;
- int Price;
- };
- class Users
- {
- public:
- int id;
- char Login[20];
- char Password[20];
- int Status;
- };
- void OutputItems(vector<Items> items);
- void OutputUsers(vector<Users> users);
- void AddNewItem(vector<Items> items, Items item1, FILE *dataF);
- //int CheckIfUserExists(vector<Users> users, FILE *logPass);
- int main()
- {
- // DO THIS AT THE START OF THE PROGRAM
- // DO THIS AT THE START OF THE PROGRAM
- // DO THIS AT THE START OF THE PROGRAM
- vector<Items> items;
- vector<Users> users;
- Items item1;
- Users user1;
- // open datafile
- FILE *dataF = NULL;
- dataF = fopen("datafile.txt" , "r+");
- // open logins and passwords file
- FILE *logPass = NULL;
- logPass = fopen("logPass.txt", "r+");
- // read from files
- if (dataF != NULL)
- {
- while (!feof(dataF))
- {
- fscanf(dataF, "%i%s%i%i", &item1.id, &item1.Name , &item1.Weight , &item1.Price);
- items.push_back(item1);
- }
- }
- else
- {
- cout << "Cannot open file datafile.txt" << endl;
- }
- if (logPass != NULL)
- {
- while (!feof(logPass))
- {
- fscanf(logPass, "%i%s%s%i", &user1.id, &user1.Login, &user1.Password, &user1.Status);
- users.push_back(user1);
- }
- }
- else
- {
- cout << "Cannot open file datafile.txt" << endl;
- }
- // END START OF PROGRAM
- // END START OF PROGRAM
- // END START OF PROGRAM
- //output id and name
- OutputItems(items);
- OutputUsers(users);
- AddNewItem(items, item1, dataF);
- fclose(dataF);
- fclose(logPass);
- OutputItems(items);
- OutputUsers(users);
- AddNewItem(items, item1, dataF);
- fclose(dataF);
- fclose(logPass);
- system("pause");
- return 0;
- }
- void OutputItems(vector<Items> items)
- {
- cout << "Items: \n";
- for (int i = 0; i < items.size(); ++i)
- {
- cout << items[i].id << " " << items[i].Name << " "
- << items[i].Weight << " " << items[i].Price << endl;
- }
- }
- void OutputUsers(vector<Users> users)
- {
- cout << "Users: \n";
- for (int i = 0; i < users.size(); ++i)
- {
- cout << users[i].id << " " << users[i].Login << " "
- << users[i].Password << " " << users[i].Status << endl;
- }
- }
- void AddNewItem(vector<Items> items, Items item1, FILE *dataF)
- {
- cout << "enter id" << endl;
- cin >> item1.id;
- cout << "enter name" << endl;
- cin >> item1.Name;
- cout << "enter Weight" << endl;
- cin >> item1.Weight;
- cout << "enter Price" << endl;
- cin >> item1.Price;
- items.push_back(item1);
- fprintf(dataF, "\n%i %s %i %i", item1.id, item1.Name, item1.Weight, item1.Price);
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement