-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.c
142 lines (135 loc) · 4.58 KB
/
Main.c
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
#include "Library.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "General.h"
#define LIBRARY_TEXT "libraryText.txt"
#define LIBRARY_BIN "libraryBin.bin"
void headMessage();
void PrintMenu();
void loadFile(const char* textFile, const char* binFile, Library* library);
//program starts here
int main()
{
Library* library = initLibrary();
headMessage();
loadFile(LIBRARY_TEXT, LIBRARY_BIN, library);
int choice;
do {
PrintMenu();
scanf_s("%d", &choice);
getchar();
switch (choice) {
case 1:
addNewBook(library->bookManager);
break;
case 2:
addNewMember(library->memberManager);
break;
case 3:
addNewLoan(library->bookManager, library->loanManager, library->memberManager);
break;
case 4:
removeBook(library->bookManager, library->loanManager);
break;
case 5:
removeMember(library->memberManager);
break;
case 6:
returnBook(library->bookManager, library->loanManager, library->memberManager);
break;
case 7:
sortBooks(library->bookManager);
break;
case 8:
searchBook(library->bookManager);
break;
case 9:
printf("\n========================================== books available ======================================\n\n");
printBookArr(library->bookManager->bookPtrArr, library->bookManager->count);
break;
case 10:
printf("\n=========================================== Members list ========================================\n\n");
printMemberArr(library->memberManager->memberArr, library->memberManager->count);
break;
case 11:
printf("\n========================================== active loan list =====================================\n\n");
printLoanList(library->loanManager);
break;
case 12:
printPopularBooks(library->bookManager);
break;
case 13:
printBooksOfAuthor(library->bookManager);
break;
case 14:
printf("closing program!\n");
break;
default:
handleError("Not valid Choice!");
break;
}
refreshLibraryLoans(library->loanManager);
printf("\n");
} while (choice != 14);
writeLibraryToTextFile(LIBRARY_TEXT, library);
writeLibraryToBinFile(LIBRARY_BIN, library);
}
void headMessage()
{
printf("###########################################################################\n");
printf("############ ############\n");
printf("############ Library management System V1.0 ############\n");
printf("############ ############\n");
printf("############ Developed by: ############\n");
printf("############ Nereya Mantzur & Simon Farber ############\n");
printf("############ ############\n");
printf("###########################################################################\n\n");
printf("Press any key to continue...\n");
_getch();
system("cls");
}
void PrintMenu()
{
printf("=========================================== Main menu ===========================================\n\n");
printf("[1] - Add New Book\n"); //DONE
printf("[2] - Add New Member\n"); //DONE
printf("[3] - Add New Loan\n"); //DONE
printf("[4] - Remove Book\n"); //DONE
printf("[5] - Remove Member\n"); //DONE
printf("[6] - Return a Book\n"); //DONE
printf("[7] - Sort books\n"); //DONE
printf("[8] - Search a Book\n"); //DONE
printf("[9] - Print All Available Books\n"); //DONE
printf("[10] - Print All Members\n"); //DONE
printf("[11] - Print All Loaned Books\n"); //DONE
printf("[12] - Print Popular Books\n"); //DONE
printf("[13] - Print books of a specific author\n"); //DONE
printf("[14] - Exit Program\n");
printf("Please enter your choice: ");
}
void loadFile(const char* textFile, const char* binFile, Library* library)
{
int choice;
do
{
printf("=========================================== Load menu ===========================================\n\n");
printf("[1] - Load system from a file\n");
printf("[2] - Exit\n");
printf("Please enter your choice: ");
scanf_s("%d", &choice);
getchar();
printf("\n=================================================================================================\n\n");
switch (choice)
{
case 1:
loadLibraryFromFile(textFile, binFile, library);
break;
case 2:
return;
default:
handleError("Not valid choice! Try again!\n\n");
break;
}
} while (1 && choice == 2);
}