-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
80 lines (59 loc) · 3.53 KB
/
main.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
#include <iostream>
#include "bookcase.h"
#include <ctime>
using namespace std;
int main(int argc, char* argv[])
{
cout << " --- THE PROGRAM STARTED --- " << endl ;
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
cout << " A. Nα δημιουργεί μια βιβλιοθήκη." << endl;
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
int NMAX = stoi(argv[1]), L = stoi(argv[2]), K1 = stoi(argv[3]), K2 = stoi(argv[4]);
cout << "NMAX = " << NMAX << " L = " << L << " K1 = " << K1 << " K2 = " << K2 << endl;
Bookcase bookCase(NMAX);
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
cout << " Β. Να δημιουργεί " << L << " βιβλία." << endl;
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
Book *book[L];
for(int i = 0; i < L; i++)
{
book[i] = new Book("title" + to_string(i), "nameSurenameOfAuthor" + to_string(i), i);
}
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
cout << " Γ. Να πραγματοποιεί " << K1 << " τυχαίες τοποθετήσεις βιβλίων στη βιβλιοθήκη." << endl;
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
int numberOfBooksToPlace = L;
if(L > K1)
{
numberOfBooksToPlace = K1;
}
else if(L < K1)
{
cout << "ERROR : You want to place " << K1 << " books, but you have " << L << " books. So " << L << " books will be placed." << endl;
}
srand((unsigned) time(0));
for(int i = 0; i < numberOfBooksToPlace; i++)
{
int randomShelf = rand() % (5) + 1;
bookCase.place_book(randomShelf, *book[i]);
}
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
cout << " Δ. Να πραγματοποιεί " << K2 << " τυχαίες αϕαιρέσεις βιβλίων στη βιβλιοθήκη." << endl;
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
for(int i = 0; i < K2; i++)
{
int randomShelf = rand() % (5) + 1;
bookCase.take_book(randomShelf);
}
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
cout << " Ε. Να κάνει εκτύπωση στην βιβλιοθήκη" << endl;
cout << endl << "-----------------------------------------------------------------------------------------------------------------------------" << endl << endl ;
bookCase.print();
// Deleting Books
for(int i = 0; i < L; i++)
{
delete book[i];
}
cout << " --- THE PROGRAM ENDED --- " << endl << endl ;
return 0;
}