Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- #include<fstream>
- #include<cmath>
- #include<cstdbool>
- #include<string>
- #include<conio.h>
- #include<vector>
- #include<string>
- #include<algorithm>
- #include<cstdio>
- #include<limits>
- #include<cctype>
- using namespace std;
- void book_issue_menu();
- void user_issue_menu();
- class book
- {
- int ID_book;
- string title, author;
- public:
- void add_book();
- void search_book();
- void show_books();
- book();
- ~book();
- };
- book::book()
- {}
- book::~book()
- {}
- void book::add_book() {
- cout << "Creating new book: " << endl;
- cout << "ID: ";
- while (!(cin >> ID_book))
- {
- cout << "ID has to be a number.\nID:";
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- fflush;
- cin.get();
- cout << "Title: " << "\t";
- getline(cin, title);
- cout << endl << "Author: ";
- while (getline(cin, author), find_if(author.begin(), author.end(), isalpha) == author.end())
- {
- cout << "You have to enter letters.\nAuthor: ";
- }
- fstream file("books.txt", ios::app);
- if (file.good() == true)
- {
- file << ID_book << endl;
- file << title << endl;
- file << author << endl;
- file.close();
- }
- cout << endl;
- }
- void book::search_book() {
- string title_1;
- string line;
- bool check = true;
- cout << "\nEnter title of book to search: ";
- cin.get();
- getline(cin, title_1);
- fstream file("books.txt");
- if (file.good() == true)
- {
- while (getline(file, line))
- {
- title = line;
- if ((title == title_1))
- {
- cout << "Book in stock.\n";
- check = false;
- break;
- }
- }
- if (check == true)
- cout << "Book not in stock.\n";
- }
- else
- {
- cout << "Cannot open the file.\n";
- }
- }
- void book::show_books() {
- string helper, line;
- int i = 0, line_counter = 0;
- cout << "BOOK LIST" << endl;
- fstream file("books.txt", ios::in);
- if (file.good() == true)
- {
- while (getline(file, helper))
- {
- if (i == 0) cout << "ID:";
- else if (i == 1) cout << "Title:";
- else if (i == 2)
- {
- cout << "Author:";
- i = -1;
- }
- i++;
- cout << helper << endl;
- line_counter++;
- }
- file.close();
- }
- cout << "Number of books: " << line_counter / 3 << endl << endl;
- }
- class user
- {
- int ID_user;
- string name;
- public:
- void add_user();
- void search_user();
- void show_users();
- user();
- ~user();
- };
- user::user()
- {
- }
- user::~user()
- {
- }
- void user::add_user() {
- cout << "Creating new user: " << endl;
- cout << "ID: ";
- while (!(cin >> ID_user))
- {
- cout << "ID has to be a number.\nID:";
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- fflush;
- cin.get();
- cout << endl << "Name: ";
- while (getline(cin, name), find_if(name.begin(), name.end(), isalpha) == name.end())
- {
- cout << "You have to enter letters.\Name: ";
- }
- fstream file("users.txt", ios::app);
- if (file.good() == true)
- {
- file << ID_user << endl;
- file << name << endl;
- file.close();
- }
- cout << endl;
- }
- void user::search_user() {
- string name_1;
- string line;
- bool check = true;
- cout << "\nEnter name of user to search: ";
- cin.get();
- getline(cin, name_1);
- fstream file("books.txt");
- if (file.good() == true)
- {
- while (getline(file, line))
- {
- name = line;
- if ((name == name_1))
- {
- cout << "User in base.\n";
- check = false;
- break;
- }
- }
- if (check == true)
- cout << "User not in base.\n";
- }
- }
- void user::show_users() {
- string helper;
- int i = 0;
- cout << "USER LIST" << endl;
- fstream file("books.txt", ios::in);
- if (file.good() == true)
- {
- while (getline(file, helper))
- {
- if (i == 0) cout << "ID:";
- else if (i == 1)
- {
- cout << "Name:";
- i = -1;
- }
- i++;
- cout << helper << endl;
- file.close();
- }
- }
- cout << endl;
- }
- int main()
- {
- char choice;
- choice = 0;
- while (choice < '1' || choice > '3')
- {
- cout << "---=== Library ==---" << endl;
- cout << "What do you want to do?"
- << endl << "1. Book Menu"
- << endl << "2. User Menu"
- << endl << "3. Exit." << endl
- << "Enter your choice: " << "\t";
- cin >> choice;
- switch (choice) {
- case '1':
- system("cls");
- book_issue_menu();
- break;
- case '2':
- system("cls");
- user_issue_menu();
- break;
- case '3':
- system("cls");
- break;
- }
- }
- return 0;
- }
- void book_issue_menu() {
- book b1;
- int choice;
- choice = 0;
- while (choice != 4)
- {
- cout << "---=== BOOK MENU ==---" << endl;
- cout << "What do you want to do?"
- << endl << "1. Add new book."
- << endl << "2. Search book."
- << endl << "3. Display all books."
- << endl << "4. Exit to main menu." << endl
- << "Enter your choice: " << "\t";
- cin >> choice;
- switch (choice) {
- case 1:
- system("cls");
- b1.add_book();
- break;
- case 2:
- system("cls");
- b1.search_book();
- break;
- case 3:
- system("cls");
- b1.show_books();
- break;
- case 4:
- system("cls");
- return;
- }
- }
- }
- void user_issue_menu() {
- user u1;
- int choice;
- choice = 0;
- while (choice != 4)
- {
- cout << "---=== BOOK MENU ==---" << endl;
- cout << "What do you want to do?"
- << endl << "1. Add new user."
- << endl << "2. Search user."
- << endl << "3. Display all users."
- << endl << "4. Exit to main menu." << endl
- << "Enter your choice: " << "\t";
- cin >> choice;
- switch (choice) {
- case 1:
- system("cls");
- u1.add_user();
- break;
- case 2:
- system("cls");
- u1.search_user();
- break;
- case 3:
- system("cls");
- u1.show_users();
- break;
- case 4:
- system("cls");
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement