Books and users' borrow and return modules

Source: Internet
Author: User
Books and users' borrow and return modules

/*
Name: Tang xiangheng
Copyright: Tang xiangheng
Author: Tang xiangheng
Date: 09-11-08
Description:
*/
# Include <iostream>
Using namespace STD;
# Define max 20 // defines the size of array elements
# Define loan_yes 1 // indicates that the book has been lent out
# Define loan_no 0 // indicates that the book has not been lent out
# Define unlend 00 // The user borrowed the book
# Define lend 11 // The user has not borrowed a book
******************** **********
Struct user
{
Char uname [21]; // User Name
Char unuber [9]; // credential number
Char classno [35]; // class
Int stuno; // number
Int SOS; // borrow sign
};
User ones [Max] =
{"Liu Lilin", "0001", "embedded 3081", 1, unlend}, {"clock-style regular", "0002", "embedded 3082", 2, unlend },
{"Tang Qiliang", "0003", "iiit3083", 3, unlend}, {"Wang Qigang", "0004", "numerical control 3088", 4, unlend },
{"Tang Culture", "0005", "biochemical pharmaceutical 3087", 5, unlend}, {"Wang Xiaobo", "0006", "Art Design 3086", 6, unlend },
{"Deng Wen", "0007", "Ai 3088", 10, unlend}, {"Tang Political Commissar", "0008", "Military Command 8088", 69, unlend },
{"Zhang Hao", "0009", "biochemical research 3308", 40, unlend}, {"Li Kaifu", "0010", "software design 3086", 88, unlend }};

********************** **********
Struct book
{
Char ID [9]; // The ISBN number of the book
Char name [35]; // Title
Char author [11]; // prepared
Char publisher [31]; // Press
Float price; // price
Int flag; // outbound flag
User ones;
};
Book [Max] =
{"Isbn001", "Linux programming", "Kai-Fu Li", "Xiamen University Press", 64.00, loan_no },
{"Isbn002", "C ++ Program Design", "Tan haoqiang", "Tsinghua University Press", 36.00, loan_no },
{"Isbn003", "PIC microcontroller practical C", "Sun Anqing", "China Power Press", 39.80, loan_no },
{"Isbn004", "Java programming", "Tang xiangheng", "Software Institute Press", 55.00, loan_no },
{"Isbn005", "C ++ practical tutorial", "Zheng AQI", "Electronic Industry Press", 48.00, loan_no },
{"Isbn006", "C language programming", "C. Thomas", "Electronic Industry Press", 68.00, loan_no },
{"Isbn007", "Computer System Design", "Wang weiming", "People's post Publishing House", 88.00, loan_no },
{"Isbn008", "Data Structure", "Yan Weimin", "Tsinghua University Press", 28.00, loan_no },
{"Isbn009", "Database Design", "Chen Xiaobo", "China Power Press", 55.00, loan_no },
{"Isbn010", "computer algorithm", "Liu Xiaoping", "Peking University Press", 77, loan_no }};
 
Int main ()
{
Void functionmenu (); // menu display function
Void listbook (); // display the list of books
Void lendbook (); // borrow Function
Void returnbook (); // return Function
Void showlended (); // display borrowed books
Void playuser (); // displays the user's borrowing Information

Char choice;
While (choice! = 6) // continuously display the menu
{
Functionmenu ();
Cin> choice;
Switch (choice)
{
Case '1': // display all books
Listbook (); break;
Case '2': // borrow books
Lendbook (); break;
Case '3': // return a book
Returnbook (); break;
Case '4': showlended (); break;
// Display the user's borrowing Information
Case '5': playuser (); break;
Case '6': // exit
Return 0;
Default: // do not perform any operation
Break;
}
}
System ("pause ");
Return 0;
}
// **************************** Display all information ******** ***************************
Void listbook ()
{
Char * Title = "borrow ";
// Display the number of digits occupied by N in the header. s indicates the character type, and F indicates the floating point type.
Printf ("% 8 S % 16 S % 11 S % 14 S % 10 S % 10 s/n", "ISBN", "title", "author ", "Press", "price", "external lending ");
For (INT I = 0; I <Max; I ++)
{
If (Book [I]. Price = 0) break; // if the price is 0, all books are displayed.
If (Book [I]. Flag = loan_yes) // define a macro as a Chinese character
{
Title = "borrow ";
} Else
{
Title = "in Database ";
}
// Display all information about the book
Printf ("% 9 S % 16 S % 11 S % 16 S % 8.2f % 8 S/N ",
Book [I]. ID, Book [I]. Name, Book [I]. Author, Book [I]. Publisher, Book [I]. Price, title );
}
}
********* ***************************
Void lendbook ()
{
Char bookid [11]; // used to receive the book number to be borrowed
Char usernuber [11]; // used to receive the account ID to be lent to the user
Int I, J;

Cout <"Enter the book number you want to borrow :";
Cin> bookid;
For (I = 0; I <Max; I ++) // find a book
{
If (strcmp (Book [I]. ID, bookid) = 0) // find the book
{
If (Book [I]. Flag = loan_yes) // if the book has been lent
{
Cout <"the book you want to borrow has been borrowed by someone else! "<Endl;
} Else // perform the borrow operation
{
Cout <"Enter your debit card number :";
Cin> usernuber;
For (j = 0; j <Max; j ++) // scans users.
{
If (strcmp (ones [J]. unuber, usernuber) = 0) // This user information is available
{
Ones [J]. SOS = lend; // mark that the user has borrowed a book
Book [I]. Flag = loan_yes; // The tag book has been lent out.
// Display the borrowed books
Cout <ones [J]. uname <"hello, sir! The books you borrowed are: "<book [I]. Name <Endl;
Cout <"book details:" <Endl;
Cout <"" <" ISBN" <"" <"" title "<" <"author" <"" <"<"
"Press" <"<" price "<" borrower "<Endl;
Printf ("% 9 S % 16 S % 11 S % 16 S % 8.2f % 8 S/N ",
Book [I]. ID, Book [I]. name, Book [I]. author, Book [I]. publisher, Book [I]. price, ones [J]. uname );
Cout <"the book has been borrowed successfully. Please return the book on time! "<Endl;
}
}

}
Break;
}
}
If (I = max) // you have found all of them. If you do not have this book, make a prompt.
{
Cout <"the book you are looking for cannot be found! "<Endl;
}
}
************* *************************
Void returnbook ()
{
Char bookid [11]; // used to receive the number of books to be returned
Int I;
Cout <"Enter the book number for returning the book :";
Cin> bookid;
For (I = 0; I <Max; I ++) // find a book
{
If (strcmp (Book [I]. ID, bookid) = 0) // find the book
{
If (Book [I]. Flag = loan_yes & ones [I]. SOS = lend) // For example, it indicates lending
{
Book [I]. Flag = loan_no; // mark the Outstanding Books
Ones [I]. SOS = unlend; // mark the user's book return
Cout <"your other books are:" <Endl;
Cout <"" <" ISBN" <"" <"" title "<" <"author" <"" <"<"
"Press" <"<" price "<" borrower "<Endl;
Printf ("% 9 S % 16 S % 11 S % 16 S % 8.2f % 8 S/N ",
Book [I]. ID, Book [I]. name, Book [I]. author, Book [I]. publisher, Book [I]. price, ones [I]. uname );
Cout <"return the book successfully. Thank you for using it! Welcome to the next visit! "<Endl;
} Else // if the book is not borrowed, an error is returned.
{
Cout <"Operation error. This book is in the library! Enter again! "<Endl;
}
}
}
}
********* **********************
Void showlended ()
{
Cout <"Welcome to query! "<Endl;
Char M [11];
Cout <"Enter the ISBN number of the book to be queried :";
Cin> m;
For (INT I = 0; I <Max; I ++) // scans the library
{
If (strcmp (Book [I]. ID, m) = 0) // find the book
{
If (Book [I]. Flag = loan_yes) // and lent
{
Cout <"the information about the books you want to query and the borrower is as follows" <Endl;
Cout <"" <" ISBN" <"" <"" title "<" <"price" <"" <"
"Borrower" <"" <"debit card number" <"" <"class" <Endl;
// Display borrowed books
Printf ("% 9 S % 16 S % 8.2f % 11 S % 10 S % 14 S/N ",
Book [I]. ID, Book [I]. name, Book [I]. price, ones [I]. uname, ones [I]. unuber, ones [I]. classno );
} Else
{
Cout <"This book has not been lent out! "<Endl;
}
}
}
}
************ *************************
Void functionmenu ()
{
Cout <"1. query all books" <Endl;
Cout <"2. Borrow Books" <Endl;
Cout <"3. Returning books" <Endl;
Cout <"4. querying detailed borrow information" <Endl;
Cout <"5. Display User Information and borrow information" <Endl;
Cout <"6. Quit" <Endl;
Cout <"select function No :";
}
******* *******************
Void playuser ()
{
Int I;
Char * change = "borrowed books"; // prepare for subsequent conversions
Printf ("% 8 S % 10 S % 16 S % 10 S % 12 S/N", "name", "card number", "class", "No ", "borrow books ");
For (I = 0; I <Max; I ++) // Scan
{
If (ones [I]. stuno = 0) break; // if the number is 0, it is like the end. This is to prevent unnecessary display
If (ones [I]. SOS = lend) // borrow a book
{
Change = "borrowed books ";
} Else
{
Change = "books not borrowed ";
}
Printf ("% 8 S % 10 S % 16 S % 10i % 12 S/N", ones [I]. uname, ones [I]. unuber, ones [I]. classno, ones [I]. stuno, change );
}

}

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.