#include <iostream> #include <string> using namespace std; class book { public: int num; float price; book *next; }; bool check(string str){ for(int i= 0;i< (); i++){ if((str[i] > '9' || str[i] < '0') && (str[i] != '.')){ return false; }} return true; } book *head = NULL; book *create(){ // 创建图书 book *p1; book *p2; p1= new book; head = p1; // 这句是增加的 p2= p1; cout << " 请输入图书编号,必须是数字,输入 0 则返回主菜单" << endl; string str; cin >> str; while(!check(str)){ cout << " 输入的不是数字,请重新输入" << endl; cin >> str; } p1 -> num = atoi (()); if(p1 -> num != 0){ cout << " 请输入图书价格" << endl; cin >> str; while(!check(str)){ cout << " 输入的不是数字,请重新输入" << endl; cin >> str; } p1 -> price = atof(()); } else { delete p1; p2= NULL; head = NULL; return head; } while(p1 -> num != 0){ p2= p1; p1= new book; cout << " 请输入图书编号,必须为数字,输入 0 则返回主菜单" << endl; string str; cin >> str; while(!check(str)){ cout << " 输入的不是数字,请重新输入,按 0 返回!!!" << endl; cin >> str; } p1 -> num = atoi(()); if(p1 -> num != 0){ cout << " 请输入图书价格,必须是数字" << endl; cin >> str; while(!check(str)){ cout << " 输入的不是数字,请重新输入,按 0 返回!!!" <<endl; cin >> str; } p1 -> price = atof(()); } p2 -> next = p1; } delete p1; p2 -> next = NULL; return head; } void showbook(book *head){ // 显示图书信息 cout << endl; cout << " 图书信息如下: " << endl; while (head){ cout << " 图书编号: " << head -> num << "\t"; cout << " 图书价格: " << head -> price << e
图书管理系统链表实现 来自淘豆网www.taodocs.com转载请标明出处.