Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- using namespace std;
- class card {
- private:
- string ID;
- string name;
- string lastname;
- string age;
- string university;
- public:
- card(string _ID, string _name, string _lastname, string _age, string _university) {
- ID = _ID;
- name = _name;
- lastname = _lastname;
- age = _age;
- university = _university;
- }
- #pragma region getters
- string getID() {
- return ID;
- }
- string getName() {
- return name;
- }
- string getLastname() {
- return lastname;
- }
- string getAge() {
- return age;
- }
- string getUniversity() {
- return university;
- }
- #pragma endregion
- };
- void menu(vector<card> sl);
- void studentsBrowser(vector<card> sl);
- void lookForStudentWithID(vector<card> sl);
- vector<card> getAllUsersFromDB();
- void addDeclaredUsersToDB(vector<card> instance);
- void addUsersToDB(vector<card>ls);
- int main() {
- //card stud1("01001089009", "Tornike", "Qurdadze", "19", "Tbilisi State University");
- //card stud2("65012305914", "Gio", "Bitsadze", "20", "Tbilisi State University");
- //card stud3("93851399302", "Mate", "Gvaramadze", "21", "Tbilisi Free University");
- vector<card> sl = getAllUsersFromDB();
- //sl.push_back(stud1);
- //sl.push_back(stud2);
- //sl.push_back(stud3);
- //addDeclaredUsersToDB(sl);
- menu(sl);
- cin.get();
- cin.get();
- }
- void menu(vector<card> sl) {
- system("cls");
- cout << "1) Check all students" << endl;
- cout << "2) Find student with specific ID" << endl;
- cout << "3) Add a new user" << endl;
- cout << "4) Exit" << endl;
- int switcher = 0;
- cin >> switcher;
- switch (switcher)
- {
- case 1:
- studentsBrowser(sl);
- break;
- case 2:
- lookForStudentWithID(sl);
- break;
- case 3:
- addUsersToDB(sl);
- break;
- case 4:
- exit(1);
- break;
- default:
- exit(1);
- break;
- }
- }
- void studentsBrowser(vector<card> sl) {
- system("cls");
- for (auto item : sl)
- {
- cout << "ID: " << item.getID() << endl;
- cout << "Name: " << item.getName() << endl;
- cout << "Lastname: " << item.getLastname() << endl;
- cout << "Age: " << item.getAge() << endl;
- cout << "University: " << item.getUniversity() << endl;
- cout << endl;
- cout << "****************************************";
- cout << endl;
- }
- }
- void lookForStudentWithID(vector<card> sl)
- {
- system("cls");
- cout << "Enter the ID of student you are looking for : ";
- string _ID;
- cin >> _ID;
- for (auto item : sl)
- {
- if (item.getID() == _ID)
- {
- cout << "ID: " << item.getID() << endl;
- cout << "Name: " << item.getName() << endl;
- cout << "Lastname: " << item.getLastname() << endl;
- cout << "Age: " << item.getAge() << endl;
- cout << "University: " << item.getUniversity() << endl;
- cout << endl;
- cout << endl;
- }
- }
- }
- vector<card> getAllUsersFromDB()
- {
- vector<card> sl;
- string ID;
- string name;
- string lastname;
- string age;
- string university;
- ifstream db;
- db.open("AdditionalUsers.dat");
- string line;
- int amountOfUsers = 0;
- int lineNumber = 0;
- while (getline(db, line)) {
- if (lineNumber == 0) {
- ID = line;
- }
- else if (lineNumber == 1) {
- name = line;
- }
- else if (lineNumber == 2) {
- lastname = line;
- }
- else if (lineNumber == 3) {
- age = line;
- }
- else if (lineNumber == 4) {
- university = line;
- lineNumber = -1;
- card student(ID, name, lastname, age, university);
- sl.push_back(student);
- }
- lineNumber++;
- }
- db.close();
- return sl;
- }
- void addDeclaredUsersToDB(vector<card> instance) {
- ofstream dbFile;
- string ID;
- string name;
- string lastname;
- string age;
- string university;
- dbFile.open("AdditionalUsers.dat", ios::app);
- for (auto item : instance)
- {
- ID = item.getID();
- name = item.getName();
- lastname = item.getLastname();
- age = item.getAge();
- university = item.getUniversity();
- dbFile << ID << endl << name << endl << lastname << endl << age << endl << university;
- }
- }
- void addUsersToDB(vector<card> ls)
- {
- system("cls");
- #pragma region declarations
- string ID;
- string name;
- string lastname;
- string age;
- string university;
- cout << "Enter ID: ";
- cin >> ID;
- cout << endl << "Enter name: ";
- cin >> name;
- cout << endl << "Enter lastname: ";
- cin >> lastname;
- cout << endl << "Enter age: ";
- cin >> age;
- cout << endl << "Enter university: ";
- cin >> university;
- cout << endl;
- #pragma endregion
- ofstream dbFile;
- dbFile.open("AdditionalUsers.dat", ios::app);
- dbFile << ID << endl << name << endl << lastname << endl << age << endl << university;
- cout << "User Successfully added to database." << endl;
- dbFile.close();
- ls = getAllUsersFromDB();
- menu(ls);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement