Book Management system

Source: Internet
Author: User
* * The copyright and version of the Declaration section: *copyright (c) 2013, Yantai University Computer College students *all rights reserved. * File Name: * Author: Shang * Date of Completion: May 23, 2014 * Version number: v0.1 * Description of task and solution: * Input Description: * Description: * Program Input: * Program output: * Problem Analysis: * Algorithm design: * My program: * * * #include &L
t;iostream> #include <cstdlib>//exit (0) #include <string> using namespace std;  void menu ();   Main interface void Bookmenu ();   Lookup interface void Findbook ();   Find book void showbook (int);  Display book information int number=0;  Number of books class book {public:void Addbook ();  Increase the book void Querybyid (int id);   Finds a book void Querybyname (string name) by number;    Find the book void Querybyauthor (string author) by name;   Finds a book void Querybypublisher (string publisher) based on the author;  Find book void Queryaall according to publishing house ();
    Display information for all books int get_id () {return id;
    String Get_name () {return name;
    String Get_author () {return author;
    String Get_publisher () {return publisher;
    Double Get_price () {return price; } private:int Id
    String name;
    string author;
    string publisher;
Double Price;
};
Book b[100];
    void menu () {cout<< "------------------------" <<endl;
    cout<< "-----Book Management System-----" <<endl;
    cout<< "------------------------" <<endl<<endl;
    cout<< "------------------------" <<endl;
    cout<< "----1 Add book----" <<endl;
    cout<< "----2 Find books----" <<endl;
    cout<< "----3 Show all----" <<endl;
    cout<< "----0 exit system----" <<endl;
cout<< "Please enter your choice:";
    } void Showbook (int n) {cout<< "-------------------------------------------------------" <<endl;
    cout<< "book number book name author publishing house price" <<endl;
    cout<<b[n].get_id () << "" <<b[n].get_name ();
    cout<< "" <<b[n].get_author () << "" <<b[n].get_publisher ();
    cout<< "" <<b[n].get_price () <<endl; cout<< "-------------------------------------------------------" <<endl;
    } void Bookmenu () {cout<< "-----------------------" <<endl;
    cout<< "---1 according to book Number---" <<endl;
    cout<< "---2 according to book name---" <<endl;
    cout<< "---3 according to book author---" <<endl;
    cout<< "---4 according to publishing house-----" <<endl;
    cout<< "---5 Return to main Menu-----" <<endl;
cout<< "-----------------------" <<endl;
    } void Findbook () {int id,c;
    String Name,publisher,author;
    cin>>c;
        Switch (c) {case 1:cout<< "Please enter Number:";
        cin>>id;
        B[number].querybyid (ID);
    Break
        Case 2:cout<< "Please enter the title:";
        cin>>name;
        B[number].querybyname (name);
    Break
        Case 3:cout<< "Please input author:";
        cin>>author;
        B[number].querybyauthor (author);
    Break
        Case 4:cout<< "Please input publishing house:";
        cin>>publisher; B[nuMber].querybypublisher (publisher);
    Break
    Case 5://bookmenu ();//This line should not break;
    } void Book::addbook () {cout<< "book Number:";
    cin>>b[number].id;
    cout<< "book Name:";
    cin>>b[number].name;
    cout<< "Author:";
    cin>>b[number].author;
    cout<< "Publishing house:";
    cin>>b[number].publisher;
    cout<< "Price:";
    cin>>b[number].price;
    cout<< "book Add Success" <<endl;
    Showbook (number);
    Number+=1;
    char s;
    cout<< "continue to add books: Yes (y) No (n)";
    cin>>s;
    if (s== ' y ') {book::addbook ();
            } void Book::querybyid (int id) {for (int i=0; i<number; i++) {if (b[i].get_id () ==id) {
        Showbook (i);
        else {cout<< "not the book you're looking for" <<endl;
    } bookmenu ();
Findbook ();
    } void Book::querybyname (string name) {for (int i=0; i<number; i++) {if (B[i].get_name () ==name)    {Showbook (i);
        else {cout<< "not the book you're looking for" <<endl;
    } bookmenu ();
Findbook (); 
        } void Book::querybyauthor (string author) {for (int i=0; i<number; i++) {if (B[i].get_author () ==author)
        {Showbook (i);
        else {cout<< "not the book you're looking for" <<endl;
    } bookmenu ();
Findbook (); } void Book::querybypublisher (string publisher) {for (int i=0; i<number; i++) {if (B[i].get_publisher ()
        ==publisher) {showbook (i);
        else {cout<< "not the book you're looking for" <<endl;
    } bookmenu ();
Findbook ();
    } void Book::queryaall () {for (int i=0; i<number; i++) {showbook (i);
    } bookmenu ();
Findbook ();
    int main () {int C;
        while (7) {menu ();
        cin>>c; if (c==1) {B[number].addbook ();
            else if (c==2) {bookmenu ();
        Findbook ();
        else if (c==3) {b[number].queryaall ();
        else if (c==0) {exit (0);
        } else {menu ();
} return 0; }


Results show:

Experience: Finally made out, is to use a little long time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.