-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
135 lines (114 loc) · 3.01 KB
/
Copy pathmain.cpp
File metadata and controls
135 lines (114 loc) · 3.01 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
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
/**
* @file main.cpp
* @author Sam Emison + Cole Belew
* @date 2024-11-07
* @brief Main
* .
* The main for the program. Calls functions and provides the interactable part of the program
*/
#include <iostream>
#include "Library.h"
using namespace std;
int main() {
Library lib;
//Variables
int choice;
string title, author, isbn;
int pages, year;
double price;
do { //Menu for commands
cout << "\nLibrary System Menu: " << endl;
cout << "1. Add Book" << endl;
cout << "2. Display All Books" << endl;
cout << "3. Find Book Via Author" << endl;
cout << "4. Find Book Via Title" << endl;
cout << "5. Delete Book" << endl;
cout << "6. Read Books from a File" << endl;
cout << "7. Write Books to File" << endl;
cout << "8. Exit" << endl;
cin >> choice;
cin.ignore();
switch (choice) { //Start of options
case 1: //Adds a book
cout << "Enter Book Title: ";
getline(cin, title);
cout << " " << endl;
cout << "Enter Author: ";
getline(cin, author);
cout << " " << endl;
cout << "Enter ISBN: ";
getline(cin, isbn);
cout << " " << endl;
cout << "Enter Number of Pages: ";
cin >> pages;
cout << " " << endl;
cout << "Enter Price: ";
cin >> price;
cout << " " << endl;
cout << "Enter Year of Publication: ";
cin >> year;
cout << " " << endl;
lib.insert_sorted(title, author, isbn, pages, price, year);
cout << "Book added successfully!" << endl;
break;
case 2: //Display books
cout << "\nAll Books in the Library..." << endl;
lib.print();
break;
case 3: //Find book via author
cout << "Enter Author's Name: ";
getline(cin, author);
lib.find_author(author);
break;
case 4: //Find book via title
cout << "Enter Book Title: ";
getline(cin, title);
lib.find_album(title);
break;
case 5: //Delete Book
cout << "Enter Author's Name: ";
getline(cin, author);
cout << "Enter Book Title: ";
getline(cin, title);
if (lib.deleteBook(author, title)) {
cout << "Book Deleted Successfully!" << endl;
}
else{
cout << "Book Not Found" << endl;
}
break;
case 6: //Read from a file
{
string filename;
cout << "Enter the filename to read from: ";
cin >> filename;
if (lib.read_from_file(filename)) {
cout << "Book Read from File Successfully!" << endl;
}
else {
cout << "Error Reading File" << endl;
}
}
break;
case 7: //Write to a file
{
string filename;
cout << "Enter the filename to write to: ";
cin >> filename;
if (lib.write_to_file(filename)) {
cout << "Books Written to File Successfully!" << endl;
}
else {
cout << "Error Writing to File" << endl;
}
}
break;
case 8: //Exit code
cout << "Exiting the Program... Goodbye!" << endl;
break;
default:
cout << "Invalid Choice... Try Again." << endl;
}
} while(choice != 8);
return 0;
}