Professional Documents
Culture Documents
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
struct Content {
string id;
};
struct Book {
string id;
string author;
string title;
string ageRange;
vector<string> illustrations;
vector<string> keywords;
};
struct TreeNode {
Book book;
vector<Content> contents;
};
string readLine() {
string line;
getline(cin, line);
return line;
}
if (!found) {
cout << "No books matching the pattern found." << endl;
}
}
if (!found) {
cout << "No books matching the keyword found." << endl;
}
}
if (bookIt != tree.end()) {
cout << "Book information edited successfully!" << endl;
} else {
cout << "Book not found with the provided ID." << endl;
}
}
string keyword;
while (ss >> keyword) {
book.keywords.push_back(keyword);
}
TreeNode node;
node.book = book;
tree[bookId] = node;
bookId[3]++;
}
inputFile.close();
}
int main() {
Tree tree;
loadDataFromFile(tree);
TreeNode computerBookNode;
computerBookNode.book.id = "B002";
computerBookNode.book.author = "Matthew Justice";
computerBookNode.book.title = "How Computers Really Work: A Hands-On Guide to
the Inner Workings of the Machine";
computerBookNode.book.ageRange = "14 and up";
computerBookNode.book.illustrations = {"Cover2.jpg", "Inside3.jpg",
"Inside4.jpg"};
computerBookNode.book.keywords = {
"Computer", "Architecture", "Digital Logic", "Processor", "Computer
Science",
"Technology", "Hardware", "Programming", "Circuitry", "Electronics"
};
tree["B002"] = computerBookNode;
TreeNode kissQuotientBookNode;
kissQuotientBookNode.book.id = "B003";
kissQuotientBookNode.book.author = "Helen Hoang";
kissQuotientBookNode.book.title = "The Kiss Quotient";
kissQuotientBookNode.book.ageRange = "Adult";
kissQuotientBookNode.book.keywords = {
"Romance", "Contemporary", "Love Story", "Relationships", "Autism
Spectrum",
"Diversity", "Vietnamese-American", "Adult Fiction", "Emotional",
"Heartwarming"
};
tree["B003"] = kissQuotientBookNode;
TreeNode treasureIslandBookNode;
treasureIslandBookNode.book.id = "B004";
treasureIslandBookNode.book.author = "Robert Louis Stevenson";
treasureIslandBookNode.book.title = "Treasure Island";
treasureIslandBookNode.book.ageRange = "12 and up";
treasureIslandBookNode.book.keywords = {
"Adventure", "Pirates", "Treasure Hunt", "Classic Literature", "Action",
"Coming of Age", "Robert Louis Stevenson", "High Seas", "Island", "Buried
Treasure"
};
tree["B004"] = treasureIslandBookNode;
TreeNode duneBookNode;
duneBookNode.book.id = "B005";
duneBookNode.book.author = "Frank Herbert";
duneBookNode.book.title = "Dune";
duneBookNode.book.ageRange = "14 and up";
duneBookNode.book.keywords = {
"Science Fiction", "Space Opera", "Fantasy", "Dystopian", "Politics",
"Religion", "Epic", "Societal Conflict", "Frank Herbert", "Desert Planet"
};
tree["B005"] = duneBookNode;
TreeNode worldWarZBookNode;
worldWarZBookNode.book.id = "B006";
worldWarZBookNode.book.author = "Max Brooks";
worldWarZBookNode.book.title = "World War Z";
worldWarZBookNode.book.ageRange = "Adult";
worldWarZBookNode.book.keywords = {
"Zombies", "Apocalypse", "Horror", "Survival", "Pandemic", "Global",
"Oral History", "Max Brooks", "Post-Apocalyptic", "Worldwide Conflict"
};
tree["B006"] = worldWarZBookNode;
TreeNode spyBookNode;
spyBookNode.book.id = "B007";
spyBookNode.book.author = "John le Carré";
spyBookNode.book.title = "The Spy Who Came In From the Cold";
spyBookNode.book.ageRange = "Adult";
spyBookNode.book.keywords = {
"Espionage", "Cold War", "Spy", "Thriller", "Intelligence", "John le
Carré",
"Undercover", "Political Intrigue", "Mystery", "Suspense"
};
tree["B007"] = spyBookNode;
while (true) {
cout << "1. Search books by pattern" << endl;
cout << "2. Search books by keyword" << endl;
cout << "3. Edit book information" << endl;
cout << "4. Exit" << endl;
cout << "Enter your choice: ";
int choice;
cin >> choice;
cin.ignore();
switch (choice) {
case 1:
cout << "Enter the pattern: ";
searchBooksByPattern(readLine(), tree);
break;
case 2:
cout << "Enter the keyword: ";
searchBooksByKeyword(readLine(), tree);
break;
case 3:
editBookInfo("Salah", "BABY", tree);
editBookInfo("Ayoub", "BENYICHE", tree);
editBookInfo("Abderrahim", "ELHADI", tree);
break;
case 4:
cout << "Exiting the program..." << endl;
return 0;
default:
cout << "Invalid choice! Please try again." << endl;
}
return 0;
}