-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.cpp
178 lines (148 loc) · 4.53 KB
/
Project.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include<iostream>
#include<fstream>
using namespace std;
fstream books_file("books.txt");
fstream user_file("user.txt");
bool search(string s){
string x;
while ( getline (user_file,x)){
if (x.find(s, 0) != string::npos)
return true;
return false;
}
class User{
private:
string password;
string first_name;
string last_name;
string birth_date;
public:
string user_name;
void setFirstName(string f){
first_name=f;
}
void setLastName(string l){
last_name=l;
}
void setBithDate(string b){
birth_date=b;;
}
void setPassword(string p){
password=p;
}
string getPassword(){
return password;
}
bool sign_in(){
string d=user_name +" "+ password;
if(search(d))
return true;
return false;
}
void sign_up(){
if(search(user_name))
cout<<"this user name already exist";
else{
ofstream file("user.txt",ios_base::app);
file<<first_name<<" "<<last_name<<" "<<birth_date<<" "<<user_name<<" "<<password<<"\n";
file.close();
}
}
};
class Books{
public:
string title;
string shelf_number;
string author;
string publlsher;
string subjects;
int edithion;
int publlshed_year;
int isbn;
int length;
};
int main(){
string enter;
string Password;
string firstName;
string lastName;
string birthDate;
User user;
Books books;
string mytext;
bool c=false;
cin>>enter;
if(enter=="sign_in"){
cin>>user.user_name>>Password;
user.setPassword(Password);
Password=user.getPassword();
}
if(enter=="sign_up"){
cin>>firstName>>lastName>>birthDate>>user.user_name>>Password;
user.setFirstName(firstName);
user.setLastName(lastName);
user.setBithDate(birthDate);
user.setPassword(Password);
user.sign_up();
}
string info;
cin>>books.title>>books.shelf_number>>books.author>>books.publlsher>>
books.subjects>>books.edithion>>books.publlshed_year>>books.isbn>>books.length;
string book;
int c=0;
//barrow
while ( getline (user_file,book)){
if (book.find(user.user_name, 0) != string::npos)
c++;
}
if(c<2){
cin>>books.title>>books.shelf_number>>books.author>>books.publlsher>>
books.subjects>>books.edithion>>books.publlshed_year>>books.isbn>>books.length;
ofstream newFile("new.txt");
string myline= books.title + " " + books.shelf_number+ " " +books.author+ " " +books.publlsher+ " " +
books.subjects+ " " +books.edithion+ " " +books.publlshed_year+ " " +books.isbn+ " " +books.length + " free" +"NULL";
int lineNumber;
while ( getline (user_file,book)){
if (book.find(myline, 0) != string::npos)
lineNumber;
}
int line=0;
while( getline(books_file,book) ){
if(line != lineNumber)
newFile<< book << "\n";
else
newFile<<books.title + " " + books.shelf_number+ " " +books.author+ " " +books.publlsher+ " " +books.subjects+
" " +books.edithion+ " " +books.publlshed_year+ " " +books.isbn+ " " +books.length + " not_free" +user.user_name;
line++;
}
newFile.close()
remove("books.txt")
rename("newFile.txt","book.txt");
}
if(c==2){
"you have to give back at least one book!!"
}
//give back
cin>>books.title>>books.shelf_number>>books.author>>books.publlsher>>
books.subjects>>books.edithion>>books.publlshed_year>>books.isbn>>books.length;
ofstream newFile("new.txt");
string myline= books.title + " " + books.shelf_number+ " " +books.author+ " " +books.publlsher+ " " +
books.subjects+ " " +books.edithion+ " " +books.publlshed_year+ " " +books.isbn+ " " +books.length + " not_free" +user.user_name;
int lineNumber;
while ( getline (user_file,book)){
if (book.find(myline, 0) != string::npos)
lineNumber;
}
int line=0;
while( getline(books_file,book) ){
if(line != lineNumber)
newFile<< book << "\n";
else
newFile<<books.title + " " + books.shelf_number+ " " +books.author+ " " +books.publlsher+ " " +books.subjects+
" " +books.edithion+ " " +books.publlshed_year+ " " +books.isbn+ " " +books.length + "free" + "NULL";
line++;
}
newFile.close()
remove("books.txt")
rename("newFile.txt","book.txt");
}