Source Code
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Book {
string title;
string author;
string ISBN;
int stock;
};
vector<Book> inventory;
// Function to handle user login
bool login() {
string username, password;
cout << "Enter username: ";
cin >> username;
cout << "Enter password: ";
cin >> password;
// Verify username and password against a database or file
// Return true if login is successful, false otherwise
if(username=="admin" && password=="password")
return true;
else
return false;
}
// Function to add a new book to the inventory
void add_book() {
Book new_book;
cout << "Enter book title: ";
cin >> new_book.title;
cout << "Enter book author: ";
cin >> new_book.author;
cout << "Enter book ISBN: ";
cin >> new_book.ISBN;
cout << "Enter stock: ";
cin >> new_book.stock;
inventory.push_back(new_book);
cout << "Book added to inventory." << endl;
}
// Function to view the current inventory of books
void view_inventory() {
cout << "Inventory:" << endl;
cout << "Title \t\t Author \t\t ISBN \t\t Stock" << endl;
for (int i = 0; i < inventory.size(); i++) {
cout << inventory[i].title << "\t\t" << inventory[i].author << "\t\t" << inventory[i].ISBN << "\t\t" << inventory[i].stock << endl;
}
}
// Function to search for a specific book in the inventory
void search_book() {
string search_term;
bool book_found = false;
cout << "Enter search term (title, author, ISBN): ";
cin >> search_term;
for (int i = 0;
Code Explanation
A book shop management system in C++ could involve the following basic functions:
- login(): This function would handle user authentication and ensure that only authorized users are able to access the system.
- add_book(): This function would allow the user to add new books to the inventory.
- view_inventory(): This function would allow the user to view the current inventory of books.
- search_book(): This function would allow the user to search for a specific book by title, author, or ISBN.
- update_book(): This function would allow the user to update the details of a specific book in the inventory.
- delete_book(): This function would allow the user to delete a specific book from the inventory.
- sell_book(): This function would allow the user to sell a specific book and update the inventory accordingly.
- view_sales(): This function would allow the user to view the sales history.
- main(): This function would handle the overall flow of the program and call the appropriate functions based on user input.
It’s important to consider the security and the error handling of the system.
Leave a Reply