Design and Realization of Book Information Management System

Design and Realization of Book Information Management System

(1) Experimental content:

Design and implement a library information management system. Design the menu and interactive logic of the system according to the experimental requirements, and code to realize the functions of adding, deleting, modifying and checking. The system includes at least the following functions:

  1. According to the specified number of books, enter the book information one by one;
  2. Display the relevant information of all books in the book table one by one;
  3. Insert the new book into the specified position in the book table according to the specified position and information of the new book to be stored in the library;
  4. Delete the book from the book table according to the location of the designated old book to be released;
  5. Can count the number of books in the table;
  6. Realize the deduplication of books in the book information table;
  7. Realize the query of favorite books, search in half according to the title, require the use of non-recursive algorithm, and successfully return the book number and price of this book;
  8. The book information table is modified in batches according to the specified conditions;
  9. Use quick sort to sort in descending order of book price;
  10. Realize the search for the most expensive books;

(2) Experiment tips:

Definition of book information:

typedef struct {

    char no[8]; //8-digit book number

    char name[20]; //book title

    int price; //price

}Book;

Definition of sequence table:

typedef  struct {

  Book *elem; //Point to the base address of the data element

  int length; //The current length of the linear table                                                           

 }SqList;

Linked list definition:

typedef struct LNode{

     Book data; //data field

     struct LNode *next; //pointer field

}LNode,*LinkList;  

  1. Creation and output of book information table based on sequential storage/chain storage structure

Define a sequential table containing book information (Ben, Title, Price). Read in the corresponding book data to complete the creation of the book information table, then count the number of books in the book table, and output the information of each book line by line.

enter

Input n+1 lines, the first n lines are the information of n books (book number, title, price), each book information occupies one line, the book number , title, and price are separated by spaces, and there is no space after the price. The last line n+1 is the input end flag: 0 0 0 (three 0s separated by spaces ). Among them, the book number and book name are of string type, and the price is of floating point number type.

output

A total of n+1 lines, the first line is the number of books in the created book table, and the last n lines are the information of n books (book number,

Book title, price), each book information occupies one line, and the book number, title, and price are separated by spaces. where the price output retains two

decimal places.

Input sample:

9787302257646 Fundamentals of programming 25.00

9787302164340 Fundamentals of Programming (2nd Edition) 20.00

9787302219972 Single-chip microcomputer technology and application 32.00

9787302203513 Principle and application technology of single chip microcomputer 26.00

9787810827430 Industrial Computer Control Technology - Principle and Application 29.00

9787811234923 Assembly Language Programming Tutorial 32.00

0 0 0

  1. Modification of book information table based on sequential storage/chain storage structure

Read in the book information table, then calculate the average price of all books, increase the price of all books lower than the average price by 20%, increase the price of all books higher than or equal to the average price by 10%, and finally output the books with modified prices line by line information.

enter

Input n+1 lines, the first n lines are the information of n books (book number, title, price), each book information occupies one line, the book number , title, and price are separated by spaces, and there is no space after the price. The last line n+1 is the input end flag: 0 0 0 (three 0s separated by spaces ). Among them, the book number and book name are of string type, and the price is of floating point number type.

output

A total of n+1 lines, the first line is the average price of all books before modification, the last n lines are the information (book number, title, price) of n books after the price modification, each book information occupies one line, book number, book title , prices are separated by spaces. The price output retains two decimal places.

Input sample:

9787302257646 Fundamentals of programming 25.00

9787302164340 Fundamentals of Programming (2nd Edition) 20.00

9787302219972 Data Mining and Machine Learning 32.00

9787302203513 Pattern Recognition and Intelligent Computing 26.00

9787810827430 Industrial Computer Control Technology - Principle and Application 29.00

9787811234923 Operating System Tutorial 32.00

0 0 0

Sample output:

9787302257646 Fundamentals of programming 30.00

9787302164340 Fundamentals of Programming (2nd Edition) 24.00

9787302219972 Data Mining and Machine Learning 35.20

9787302203513 Pattern Recognition and Intelligent Computing 28.60

9787810827430 Industrial Computer Control Technology - Principle and Application 31.90

9787811234923 Operating System Tutorial 35.20

  1. Most Expensive Book Search Based on Book Information Table of Sequential Storage/Chained Storage Structure

Read in the corresponding book information table, then find the book with the highest price, and output the information of the corresponding book.

output

A total of m+1 lines, of which, the first line is the number of the most expensive books (there may be multiple books with the highest price), and the last m lines are the information of the most expensive books, each book information occupies one line, ISBN, book title , prices are separated by spaces. The price output retains two decimal places.

Sample output:

2

9787302219972 Data Mining and Machine Learning 35.20

9787811234923 Operating System Tutorial 35.20

  1. Searching for Favorite Books in Book Information Table Based on Sequential Storage/Chained Storage Structure

Read in the corresponding book information table, and then output the information of the corresponding book according to the name of the specified favorite book.

enter

Enter 1 line, which is the name of the favorite book to be searched each time.

output

If the search is successful, output k+1 lines. For each search, the first line is the number of favorite books. There may be multiple books with the same title. The last K lines are the information of favorite books (book number, title, price) ), each book information occupies one line, and the book number, title, and price are separated by spaces, and the price output retains two decimal places. If the search fails: only output the following prompt: Sorry, there is no favorite for you!

output sample

2

9787302257646 Fundamentals of programming 30.00

9787302164340 Fundamentals of Programming (2nd Edition) 24.00

  1. Storage of new books based on book information table of sequential storage/chain storage structure

Read in the location and information of the specified new book to be stored, insert the new book into the specified location in the book table, and finally output the information of all books after the new book is stored.

enter

A total of n+1 lines, first enter the first line, the content is only an integer, representing the location number of the new book to be stored, and then enter n lines, the content is the information of the new book, the book number, title, and price are separated by spaces .

output

If the insertion is successful, output the information (book number, title, and price) of all books after the new book is put into storage, with a total of n+1 lines, each line is the information of a book, and the book number, title, and price are separated by spaces. The price output retains two decimal places.

If the insertion fails, only the following prompt will be output: Sorry, the storage location is illegal!

Input sample:

2

9787302265436 Introduction to Computer Experiment Guide 18.00

Sample output:

9787302257646 Fundamentals of programming 30.00

9787302265436 Introduction to Computer Experiment Guide 18.00

9787302164340 Fundamentals of Programming (2nd Edition) 24.00

9787302219972 Data Mining and Machine Learning 35.20

9787302203513 Pattern Recognition and Intelligent Computing 28.60

9787810827430 Industrial Computer Control Technology - Principle and Application 31.90

9787811234923 Operating System Tutorial 35.20

  1. Outbound used books based on book information table based on sequential storage/chain storage structure

Read in the ISBN of the specified old book to be released from the library, delete the book from the book table, and finally output the information of all books after the old book is released from the library.

enter

Enter the ISBN of the used book to be released;

output

If the deletion is successful, output the information (book number, title, price) of all books after the old book is out of the library. Each line is the information of a book, and the book number, title, and price are separated by spaces. The price output retains two decimal places.

If the deletion fails, only the following prompt will be output: Failed to leave the library, the book was not found!

  1. Book Deduplication Based on Book Information Table Based on Sequential Storage/Chained Storage Structure

The book number (ISBN) of any book published by the publishing house is unique, that is, books with duplicate book numbers are not allowed in the book table. Read in the corresponding book information table (add records with duplicate book numbers in advance), and then deduplicate books, that is, delete books with duplicate book numbers (only the first book is left), and finally output the information of all books after deduplication.

output

A total of m+1 lines are output (m<=n), among which, the first line is the number of books after deduplication, and the last m lines are the information of books after deduplication (book number, title, price), and the information of each book accounts for One line, book number, book title, and price are separated by spaces, and the price output retains two decimal places.

the code

typedef struct {     string no; //8-digit book number     string name; //book title     double price; //price }Book; //definition of sequence table: typedef struct LNode {     Book data; //data field     struct LNode* next; //pointer field }LNode; typedef struct {     LNode* first; //point to the base address of the data element     int length; //current length of the linear list    }SqList; //definition of the linked list














 

Library() {
        sq.length = 0;LNode* first = new LNode; sq.first = first;
        Book book;  first->next = NULL; LNode* r =first; LNode* ln = new LNode;
        while (1) {
            ln = new LNode;
            cin >> ln->data.no >> ln->data.name >> ln->data.price;
            
            if (ln->data.no == "0" && ln->data.name == "0"&&ln->data.price==0 ) {
                break;
            }
            else {
                r->next = ln; r = ln;
                sq.length++;
            }
        }
        r->next = NULL;
    }
 

The implementation code is as follows

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
#define ok 1
#define error 0
#define maxsize 100
#define overflow -2
typedef struct
{  string ID;  string name;  float price; }book;//Structure typedef struct {  book* elem;  int length; }sqlist; int initlist(sqlist &l)//Initialization of sequence table {  l.elem = new book[maxsize];//Assign address to sequence table space  if (!l.elem)exit(overflow);  l.length = 0;  return ok; } void menu()//menu function {


















 cout << "**************1. Input book information************" << endl;
 cout << "******** *****2. Query book information (all)*******" << endl;
 cout << "**************3. Sort by price*** *********" << endl;
 cout << "**************4. Query book information by title****" << endl;
 cout < < "**************5.Delete book information according to book title*****" << endl;
 cout << "************ 6. Find duplicate book information according to the ID ***" << endl;
 cout << "************7. Insert books according to the specific position entered******" < < endl;
 cout << "************8. Get the sequence table length *****************" << endl;
 cout << "* ***********9. Modify prices in batches****************" << endl;
 cout << "******** *****10.Terminate program *******************" << endl;
}
int input(sqlist &l)//Input book information
{  cout << "Please enter the number of books:" < < endl;  int n;  cin >> n;



 for (int i = l.length; i < l.length+n; i++)//It is convenient for subsequent input of book information
 {   cout << "Please enter the first "<<i+1<<" book information" << endl ;   cout << "The book number is:" << endl;   cin >> l.elem[i].ID;   cout << "The book name is:" << endl;   cin >> l.elem[i].name;   cout << "The price is:" << endl;   cin >> l.elem[i].price;  }  l.length = l.length + n;  return ok; } int Length(sqlist &l){     cout<<" Sequence table length "<<l.length<<endl;     return 0;//Return the length of the sequence table } //Batch operation (change price) void Adjust(sqlist &l) {  double sum = 0;//Summation  for (int i = 0; i < l. length-1; ++i) {      sum += l.elem[i].price;//sum of prices  }







 














 double ave = sum / (l.length-1);//求平均
 //调整
 for (int i = 0; i < l.length ; i++) {      if (l.elem[i].price < ave) {          l.elem[i].price += 0.2 * l.elem[i].price;      }      else {              l.elem[i].price += 0.1 *l.elem[i].price;          }  }  for(int i=0;i<l.length;i++){      cout<<"变化后:"<<l.elem[i].ID<<"   "<< l.elem[i].name <<"     "<< l.elem[i].price << endl;  } } void insertNum(sqlist &l,int location){     if(location<1||location>l.length) throw"位置错误,不在顺表范围之内";     else{                     for (int j = l.length; j >= location; --j) { //Traverse and adjust element position; 










 

 




                l.elem[j]=l.elem[j-1];
        }
             cout << "Book number is:" << endl;
             cin >> l.elem[location-1].ID;
            cout << "Book name : " << endl;
            cin >> l.elem[location-1].name;
            cout << "The price is: " << endl;
            cin >> l.elem[location-1].price;
            l.length++;
        
    }
}
 
int sort(sqlist& l)//Sort books by price (using bubble sort)
{  for (int i = 0; i < l.length - 1; i++)  {   for (int n = 0; n < l. length - 1 - i; n++)   {    if (l. elem[n]. price > l. elem[n + 1].price)    {     book tmp;     tmp = l.elem[n];








    l.elem[n] = l.elem[n + 1];
    l.elem[n + 1] = tmp;
   }
  }
 }
 cout << "The sorted book information is:" << endl;
 for (int i = 0; i <l.length; i++)
  cout << l.elem[i].ID <<" "<< l.elem[i].name <<" "<< l.elem[i].price < < endl;
 cout<<"The most expensive book"<<l.elem[l.length-1].ID<<" "<< l.elem[l.length-1].name <<" "<< l.elem[l.length-1].price << endl;
 return ok;
}
void output(sqlist &l)//output book information function
{  cout << "book information is:" << endl;  for (int i = 0; i <l.length; i++)   cout << l.elem[i].ID<< " "<< l.elem[i].name<<" " << l.elem[i].price << endl; } int query(sqlist l)//Query book information according to book name {




 


 cout << "Please enter the title of the query:" << endl;
 string name1;
 cin >> name1;
 int low = 0;
 int high = l.length - 1;
 int mid = 0;
 double key = 0;// Search basis
 for (int i = 0; i < l.length - 1; i++) {//book title conversion price search
     if (l.elem[i].name == name1) {    key = l.elem[i] .price;   }  }  while (low <= high) {// gradually reduce the range   mid = (low + high) / 2;   if (l.elem[mid].price > key)    low = mid + 1;   else if ( l.elem[mid].price < key)    high = mid - 1;   else   cout<<l.elem[mid].ID<<" "<<l.elem[mid].name<<" "<<l .elem[mid].price<<endl;    return mid;  }  return -1; }














 

int Repetion(sqlist &l)//repetition check function, using the uniqueness of the book number for comparison
{     for(int i=0;i<l.length;i++){         for(int j=i+1;j<l.length ;j++){             if(l.elem[i].ID==l.elem[j].ID){                 for (int k = 0; k < l.length; k++)//The position of the book behind this book Move forward one bit                 {                  l.elem[k].ID = l.elem[k + 1].ID;                  l.elem[k].name = l.elem[k + 1].name;                 l.elem [k].price = l.elem[k + 1].price;                  }                 cout<<"The repeated book is: "<<l.elem[i].ID<<" "<<l.elem[i]. name<<" "<<l.elem[i].name<<endl;                     l.length--;                 return ok;             }          }     }















    return 0;
}
 
 
int delete_name(sqlist &l)//Delete the book information given by the user
{  cout << "Please enter the name of the book to be deleted:" << endl;  string name2;  cin >> name2;  for (int i = 0 ; i < l.length; i++)//The positions of the books behind this book are all moved forward one bit   if (l.elem[i].name == name2)   {    l.elem[i].ID = l. elem[i + 1].ID;    l.elem[i].name = l.elem[i + 1].name;    l.elem[i].price = l.elem[i + 1].price;   }  l.length--;  return ok; } int main() {  sqlist l;  initlist(l);//initialize  int select = 0;  while (ok)  {   menu();   cout << "Please enter selection" << endl;   cin >> select;























  switch (select)//根据用户选择实现功能
  {
  case 1:
   input(l);
   continue;
  case 2:
   output(l);
   continue;
  case 3:
   sort(l);
   continue;
  case 4:
   query(l);
   continue;
  case 5:
   delete_name(l);
   continue;
  case 6:
      Repetion(l);
      continue;
  case 7:
      {
          int location;
          cin>>location;
          insertNum(l,location);
          continue;
      }
  case 8:
      cout<<Length(l);
      continue;
  case 9:
      Adjust(l);
      continue;
  case 10:
      break;
  }
   system("pause");
   return 0;
  }
}

おすすめ

転載: blog.csdn.net/weixin_46279994/article/details/118076528