-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserClass.cpp
More file actions
69 lines (66 loc) · 1.99 KB
/
Copy pathUserClass.cpp
File metadata and controls
69 lines (66 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "classes.h"
//User Functions' Implementations
string User::getName() const {
return this->name;
}
string User::getUID() const {
return this->UID;
}
void User::editProfile() {
cout << "Edit Name (Current: " << name << "): ";
if (cin.peek() == '\n') cin.ignore();//AWESOME :)
getline(cin,name);
cout << "Edit Age (Current: " << age << "): ";
while(true){
cin >> age;
if (cin.fail()) {
cin.clear(); //***BEST APPROACH FOR ERROR HANDLING TILL DATE----YAY
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "\nInvalid input. Please enter a valid age:\n";
}else break;
}
}
int User::getAge() const {
return this->age;
}
// 2nd const is necessary for calling it on a const Book1, else it will give error
// it ensures "this" is not modified inside
bool User::operator<(const User& other) const {
return this->UID < other.UID;
}
// void User::saveUser(ofstream &out) {
// out << UID << " " << name << " " << age << endl;
// }
// void User::loadUser(ifstream &in) {
// in >> UID >> name >> age;
// }
// void User::borrowBook(Book& book){
// cout<<"Borrow Request for "<<book.title<<" denied.\n"
// "User trying to borrow (maybe some issue) CHECK.\n";
// }
// void User::returnBook(Book& book){
// cout<<"Return Request for "<<book.title<<" denied.\n"
// "User trying to return (maybe some issue) CHECK.\n";
// }
// void User::reserveBook(Book& book){
// cout<<"Reserve Request for "<<book.title<<" denied.\n"
// "User trying to reserve (maybe some issue) CHECK.\n";
// }
User::User(string UID,string name,int age){
this->UID = UID;
this->name = name;
this->age = age;
this->account = new Account(this);
// cout<<"Constructor of user class\n";
}
User::User(const User& user){
this->UID = user.UID;
this->name = user.name;
this->age = user.age;
this->account = new Account(&(user));
}
User::~User(){
// cout<<"Destructor of user class called\n";
delete account;
account = nullptr;
}