软件开发与创新作业——对“网上购书模拟系统”的改进
一)项目来源:
项目来自之前程序设计Ⅱ课程设计的结课作业,主题为“网上购书模拟系统”。
本次作业将对其进行分析并加以改进和优化,能力所限,只进行部分修改。
二)项目分析:
对原系统进行分析:
#include <iostream> #include<string> using namespace std; #include "buy.h" #include "book.h" #include "search.h" void main() { search gx, yh, cz, xs, cx; cout << " *********************************" << endl; cout << " ** 1.购书人信息 **" << endl; cout << " ** 2.图书信息 **" << endl; cout << " ** 3.图书查找 **" << endl; cout << " ** 4.购书 **" << endl; cout << " ** 5.查询订单 **" << endl; cout << " *********************************" << endl; int choice; cout << "请输入数字查询:"; cin >> choice; cout << endl; switch (choice) { case 1: cout<<"购书人信息:\n\n"; yh.display_buyer(); break; case 2: cout << "\n图书信息:\n\n"; gx.display_book(); break; case 3: cout << "\n\n图书查找:"; cz.searchforbook(); break; case 4: cout << "购书:"; xs.addReceipt(); break; case 5: cx.search_receipt(); break; } }
#include <string> #include <iostream> using namespace std; class book { protected: string book_ID;//编号 string book_name;//书名 string author;//作者 string publishing;//出版社 string price;//价格 public: book(); book(string b_id, string b_n, string au, string pu, string pr); void display(); string getbook_ID(); string getbook_name(); string getauthor(); string getpublishing(); string getprice(); };
通过编写“buy.h""book.h""search.h",分别实现购书、图书信息存储和调用、订单查询等功能。
三)项目改进:
“buy.h"代码改进如下:
增加会员折扣的功能
#include <string> #include <iostream> #include <iomanip> #include <fstream> #include <string> using namespace std; class Buyer// 购书者类 { public: Buyer(); Buyer(string id, string na, string ad); // 构造函数 virtual void display(); // 显示函数(虚函数) protected: string buyerID; // 买家ID string name; // 姓名 string address; // 地址 }; class People : public Buyer// 普通买家 { public: People(string id, string na, string ad) :Buyer(id, na, ad) { } void display(); }; class Member : public Buyer// 会员类 { public: Member(string id, string na, string ad, double dc) :Buyer(id, na, ad) { discount_member = dc; } void display(); private: double discount_member; // 折扣率 }; class Vip : public Buyer// 贵宾类 { public: Vip(string id, string na, string ad, double dc) :Buyer(id, na, ad) { discount_vip = dc; } void display(); private: double discount_vip; // 折扣率 };
系统管理员可在文档“buyer.txt”中录入店铺会员信息,即可使用户在购物时享受折扣;
“search.h”
分析代码后发现在订单中没有显示订单中书籍编号,这对于卖家和买家核对书目都存在不便,
故改进数据关联,并将图书编号加入到订单信息中。



浙公网安备 33010602011771号