Skip to content

Commit 057d7d2

Browse files
finished the project,only minor improvements left
1 parent bd4163c commit 057d7d2

29 files changed

+166
-68
lines changed

Diff for: Book.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ void Book::setId(const size_t _id)
5353

5454
void Book::printBriefly() const
5555
{
56-
std::cout << "Title: " << this->title << std::endl;
56+
std::cout << "Title: " << this->title << std::endl;
5757
std::cout << "Author: " << this->author << std::endl;
58-
std::cout << "Genre: " << this->genre << std::endl;
59-
std::cout << "ID: " << this->id << std::endl;
58+
std::cout << "Genre: " << this->genre << std::endl;
59+
std::cout << "ID: " << this->id << std::endl;
6060
}
6161

6262
void Book::printDetailed() const
6363
{
64-
std::cout << "Title: " << this->title << std::endl;
65-
std::cout << "Author: " << this->author << std::endl;
66-
std::cout << "Genre: " << this->genre << std::endl;
64+
std::cout << "Title: " << this->title << std::endl;
65+
std::cout << "Author: " << this->author << std::endl;
66+
std::cout << "Genre: " << this->genre << std::endl;
6767
std::cout << "Summary: " << this->summary << std::endl;
68-
std::cout << "Tags: "; this->tags.print(); std::cout << std::endl;
69-
std::cout << "Year: " << this->year << std::endl;
70-
std::cout << "Rating: " << this->rating << std::endl;
71-
std::cout << "ID: " << this->id << std::endl;
68+
std::cout << "Tags: "; this->tags.print(); std::cout << std::endl;
69+
std::cout << "Year: " << this->year << std::endl;
70+
std::cout << "Rating: " << this->rating << std::endl;
71+
std::cout << "ID: " << this->id << std::endl;
7272
}
7373

7474
void Book::loadBook(std::istream& in)
@@ -125,4 +125,4 @@ const size_t& Book::getYear() const
125125
const double& Book::getRating() const
126126
{
127127
return this->rating;
128-
}
128+
}

Diff for: Book.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ class Book
1313
void setTags(const Vector<String>&);
1414
void setRating(const double);
1515
void setId(const size_t);
16+
1617
void printBriefly() const;
1718
void printDetailed() const;
19+
1820
void loadBook(std::istream&);
1921
void saveBook(std::ostream&) const;
22+
2023
size_t getID() const;
2124
const String& getTitle() const;
2225
const String& getAuthor() const;
@@ -32,4 +35,4 @@ class Book
3235
size_t year;
3336
double rating;
3437
size_t id;
35-
};
38+
};

Diff for: BookStore.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ void BookStore::allBooksBrieflyInfo() const
2323
for (size_t i = 0; i < size; ++i)
2424
{
2525
books[i].printBriefly();
26-
std::cout << std::endl;
26+
if(i != size - 1)
27+
std::cout << std::endl;
2728
}
2829
}
2930

@@ -415,3 +416,9 @@ void BookStore::saveBooks(std::ofstream& out)
415416
books[i].saveBook(out);
416417
}
417418
}
419+
420+
void BookStore::clear()
421+
{
422+
BookStore clean;
423+
*this = clean;
424+
}

Diff for: BookStore.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class BookStore
1313
void sortBooksDescending(const String&);
1414
void addBook();
1515
void removeBook(const String&);
16+
void loadBooks(std::ifstream&,size_t);
17+
void saveBooks(std::ofstream&);
1618
size_t getSize() const;
17-
void loadBooks(std::ifstream& in,size_t);
18-
void saveBooks(std::ofstream& out);
19+
void clear();
1920
private:
2021
Vector<Book> books;
2122
size_t total;

Diff for: CommandMenu.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ void CommandMenu::startLibrary()
6060
}
6161
case 1:
6262
{
63+
if (parameters.getSize() >= 1)
64+
{
65+
std::cout << "Invalid parameters count!\n";
66+
break;
67+
}
68+
library.close();
6369
break;
6470
}
6571
case 2:
@@ -74,6 +80,12 @@ void CommandMenu::startLibrary()
7480
}
7581
case 3:
7682
{
83+
if (parameters.getSize() >= 2 || parameters.getSize() <= 0)
84+
{
85+
std::cout << "Invalid parameters count!\n";
86+
break;
87+
}
88+
library.saveAs(parameters[0]);
7789
break;
7890
}
7991
case 4:
@@ -307,5 +319,4 @@ void CommandMenu::checkSecondCommand(String& command)
307319
{
308320
if (command != "info" && command != "find" && command != "sort" && command != "add" && command != "remove" && command != "all" && command != "as")
309321
this->theCommand.popBack();
310-
}
311-
322+
}

Diff for: CommandMenu.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ class CommandMenu
1818
Vector<String> theCommand;
1919
Vector<String> parameters;
2020
String command;
21-
};
22-
21+
};

Diff for: Database2.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
1
2+
admin
3+
i<3c++
4+
1
5+
1
6+
2
7+
MyFirstBook
8+
iAmTheAuthor
9+
sci-fi
10+
A cool book about space
11+
4
12+
space
13+
war
14+
planets
15+
stars
16+
2021
17+
100
18+
1
19+
MySecondBook
20+
iAmTheAuthor
21+
adventure
22+
A cool book about dinosaurs
23+
4
24+
dino
25+
BC
26+
animals
27+
adventure
28+
2021
29+
100
30+
2

Diff for: Debug/Book.obj

687 Bytes
Binary file not shown.

Diff for: Debug/BookStore.obj

8.23 KB
Binary file not shown.

Diff for: Debug/CommandMenu.obj

402 Bytes
Binary file not shown.

Diff for: Debug/Library.log

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
 BookStore.cpp
2-
D:\VisualStudio2019\ООП-Л\Course Project\Library\Library\BookStore.cpp(395,20): warning C4018: '<': signed/unsigned mismatch
3-
Library.cpp
4-
Generating Code...
1+
 Book.cpp
52
Library.vcxproj -> D:\VisualStudio2019\ООП-Л\Course Project\Library\Debug\Library.exe

Diff for: Debug/Library.obj

4.37 KB
Binary file not shown.

Diff for: Debug/Library.tlog/CL.command.1.tlog

0 Bytes
Binary file not shown.

Diff for: Debug/Library.tlog/CL.read.1.tlog

-400 Bytes
Binary file not shown.

Diff for: Debug/Library.tlog/CL.write.1.tlog

3 KB
Binary file not shown.

Diff for: Debug/Library.tlog/link.read.1.tlog

232 Bytes
Binary file not shown.

Diff for: Debug/Project.obj

0 Bytes
Binary file not shown.

Diff for: Debug/User.obj

0 Bytes
Binary file not shown.

Diff for: Debug/UserStore.obj

-164 KB
Binary file not shown.

Diff for: Debug/vc142.idb

0 Bytes
Binary file not shown.

Diff for: Debug/vc142.pdb

0 Bytes
Binary file not shown.

Diff for: Library.cpp

+61-16
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ void Library::open(const String& filename)
2626
std::ifstream in(filename.getText());
2727
in.seekg(std::ios::beg);
2828
users.loadUsers(in);
29+
if (users.getSize() == 0)
30+
return;
2931
size_t skip = users.getSize() * 4 + 1;
30-
in.seekg(std::ios::beg);
32+
in.seekg(0,std::ios::beg);
3133
books.loadBooks(in,skip);
3234
std::cout << "Database successfully loaded!\n";
3335
this->FileName = filename;
@@ -54,6 +56,53 @@ void Library::save()
5456
this->isChanged = false;
5557
}
5658

59+
void Library::saveAs(const String& filename)
60+
{
61+
if (!isOpened)
62+
{
63+
std::cout << "Open a file before executing any other commands!\n";
64+
return;
65+
}
66+
size_t size = filename.getSize();
67+
if (filename[size - 4] != '.' || filename[size - 3] != 't' || filename[size - 2] != 'x' || filename[size - 1] != 't')
68+
{
69+
std::cout << "File name must end with .txt !\n";
70+
return;
71+
}
72+
this->FileName = filename;
73+
this->save();
74+
}
75+
76+
void Library::close()
77+
{
78+
if (!isOpened)
79+
{
80+
std::cout << "Open a file before executing any other commands!\n";
81+
return;
82+
}
83+
if (isChanged)
84+
{
85+
std::cout << "There are unsaved changes! Are you sure you want to exit?\n0 - Save&Close | 1 - Close : ";
86+
bool choice = 0;
87+
std::cin >> choice;
88+
if (choice)
89+
{
90+
std::cin.ignore();
91+
std::cout << "Successfully closed " << this->FileName << "!\n";
92+
this->clear();
93+
return;
94+
}
95+
std::cin.ignore();
96+
this->save();
97+
std::cout << "Successfully closed " << this->FileName << "!\n";
98+
this->clear();
99+
return;
100+
}
101+
std::cout << "Successfully closed " << this->FileName << "!\n";
102+
this->clear();
103+
this->isOpened = 0;
104+
}
105+
57106
void Library::logIn()
58107
{
59108
if (!isOpened)
@@ -133,24 +182,12 @@ void Library::logOut()
133182

134183
void Library::exit()
135184
{
136-
if (isChanged)
185+
if (users.activeUserIndex() == -1)
137186
{
138-
std::cout << "There are unsaved changes! Are you sure you want to exit?\n0 - Save&Exit | 1 - Exit : ";
139-
bool choice = 0;
140-
std::cin >> choice;
141-
if (choice)
142-
{
143-
std::cin.ignore();
144-
std::cout << "Good bye!\n";
145-
return;
146-
}
147-
std::cin.ignore();
148-
this->save();
149187
std::cout << "Good bye!\n";
150188
return;
151-
}
152-
std::cout << "Good bye!\n";
153-
return;
189+
}
190+
std::cout << "Good bye " << users[users.activeUserIndex()].getName() << "!\n";
154191
}
155192

156193
void Library::help() const
@@ -360,3 +397,11 @@ User& Library::activeUser()
360397
{
361398
return users[users.activeUserIndex()];
362399
}
400+
401+
void Library::clear()
402+
{
403+
this->users.clear();
404+
this->books.clear();
405+
this->isOpened = false;
406+
this->FileName = "";
407+
}

Diff for: Library.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Library
2222
void booksRemove(const String&);
2323
void usersAdd(const String&, const String&);
2424
void usersRemove(String&);
25-
25+
void clear();
2626
User& activeUser();
2727
private:
2828
UserStore users;
@@ -31,5 +31,4 @@ class Library
3131
bool isSaved;
3232
bool isChanged;
3333
String FileName;
34-
};
35-
34+
};

Diff for: Project.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ int main()
1111

1212
CommandMenu menu;
1313
menu.startLibrary();
14+
1415
return 0;
1516
}

Diff for: User.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ User& User::operator=(const User& other)
9191
this->isLoggedIn = other.isLoggedIn;
9292
}
9393
return *this;
94-
}
94+
}

Diff for: User.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ class User
55
public:
66
User();
77
User(String&, String&);
8+
89
String getName() const;
9-
void setName(const String&);
1010
String getPassword() const;
11-
void setPassword(const String&);
1211
bool getAdmin() const;
1312
bool getLoggedIn() const;
13+
14+
void setPassword(const String&);
15+
void setName(const String&);
1416
void setLoggedIn(const bool);
1517
void setAdmin(const bool);
18+
1619
void loadUser(std::ifstream&);
1720
void saveUser(std::ostream&) const;
21+
1822
bool operator==(const User&);
19-
User& operator=(const User& other);
23+
User& operator=(const User&);
2024
private:
2125
String name;
2226
String password;

0 commit comments

Comments
 (0)