注意了!Leaguer看这里!

2013年9月11日,Leaguer社区成立,旨在为互联网产品的健康发展提供一个多样化的交流平台。该社区将记录成员们的成长历程,并促进在问题解决、敏捷实践、资源共享和技术探索等方面的合作。

  


               距离已经消失,要么创新,要么死亡。
                                        ——托马斯·彼得斯

       2013年09月11日,一个值得兴奋的日子,Leaguer的社区诞生了。在这里将记录大家奋斗的过程,这里将变成一个多样化的交流平台,来支持我们的互联网产品健康有序的发展。我们的文章分类是这样产生的:

       Questions:记录奋斗过程中遇到的绊脚石。
        大家可以把自己遇到的所有问题发上来,供记录和分享。同时也会成为你解决问题最便捷的方式,因为大家会帮你解决问题。

        Agile:记录敏捷相关的所有信息。
        包括敏捷的实施过程,敏捷的心得分享,敏捷过程中遇到的问题,对敏捷的看法,敏捷的资料信息,一切和敏捷相关的东西,希望大家踊跃分享。

        Share:记录所有能分享的东西。
        涵盖沟通方式,管理方式,心得体会,比较优秀的技术和方式都可以拿来分享。让这里形成大家了解外界的便捷的窗口。
  
        Technology:记录技术轨迹。
        对于这个行业最核心的竞争力是技术,面对千变万化的技术,我们要以团队的实力来消化对我们产品有用的技术。以先进的技术来开拓我们面向互联网的产品。

        这里是一个小型社区,但这里人将会记录每个Leaguer成长的生命轨迹。用大家在这里的努力来颠覆、创新吧!



                                                                                                       Peter Zhang
                                                             

 

#include <string> #include <iostream> using namespace std; class buyer // 基类 { protected: string name; // 姓名 int buyerID; // 购书人编号 string address; // 地址 double pay; // 购书费用 public: buyer(); buyer(string n, int b, string a, double p); string getbuyname(); // 取姓名 string getaddress(); // 取地址 double getpay(); // 取应付费用 int getid(); // 取购书人编号 virtual void display() = 0; // 显示对象 virtual void setpay(double = 0) = 0; // 计算购书费用 }; // 会员类 class member : public buyer { private: int leaguer_grade; // 会员级别 public: member(string n, int b, int l, string a, double p) : buyer(n, b, a, p) { leaguer_grade = l; } // 构造函数 void display(); // 显示函数 void setpay(double p); }; // 贵宾类 class honoured_guest : public buyer { private: double discount_rate; // 折扣率 public: honoured_guest(string n, int b, double r, string a, double p) : buyer(n, b, a, p) { discount_rate = r; } // 构造函数 void display(); // 显示对象 void setpay(double p); // 计算购书费用 }; // 普通人类 class layfolk : public buyer { public: layfolk(string n, int b, string a, double p) : buyer(n, b, a, p) {} // 构造函数 void display(); // 显示对象 void setpay(double p); // 计算购书费用 }; // 基类构造函数 buyer::buyer() { name = “”; buyerID = 0; address = “”; pay = 0; } buyer::buyer(string n, int b, string a, double p) { name = n; buyerID = b; address = a; pay = p; } // 成员函数定义 double buyer::getpay() { return pay; } string buyer::getaddress() { return address; } string buyer::getbuyname() { return name; } int buyer::getid() { return buyerID; } // 会员类的显示函数 void member::display() { cout << “购书人姓名:” << name << “\t”; cout << “购书人编号:” << buyerID << “\t”; cout << “购书人为会员,级别:” << leaguer_grade << endl; cout << “地址:” << address << endl; } // 会员类的计算购书费用 void member::setpay(double p) { if (leaguer_grade == 1) pay = 0.95 * p + pay; else if (leaguer_grade == 2) pay = 0.90 * p + pay; else if (leaguer_grade == 3) pay = 0.85 * p + pay; else if (leaguer_grade == 4) pay = 0.80 * p + pay; else if (leaguer_grade == 5) pay = 0.70 * p + pay; else cout << “级别错误!” << endl; } // 贵宾类的显示函数 void honoured_guest::display() { cout << “购书人姓名:” << name << “\t”; cout << “购书人编号:” << buyerID << “\t”; cout << “购书人为贵宾!折扣率为:” << discount_rate * 100 << “%” << endl; cout << “地址:” << address << endl; } // 贵宾类计算购书费用 void honoured_guest::setpay(double p) { pay = pay + (1 - discount_rate) * p; } // 普通类显示函数 void layfolk::display() { cout << “购书人姓名:” << name << “\t”; cout << “购书人编号:” << buyerID << “\t”; cout << “购书人为普通人” << endl; cout << “地址:” << address << endl; } // 普通类计算购书费用 void layfolk::setpay(double p) { pay = pay + p; } // 图书类 class book { protected: string book_ID; // 书号 string book_name; // 书名 string author; // 作者 string publishing; // 出版社 double price; // 定价 public: book(); book(string b_id, string b_n, string au, string pu, double pr); void display(); string getbook_ID(); // 取书号 string getbook_name(); // 取书名 string getauthor(); // 取作者 string getpublishing(); // 取出版社 double getprice(); // 取定价 }; book::book(string b_id, string b_n, string au, string pu, double pr) { book_ID = b_id; book_name = b_n; author = au; publishing = pu; price = pr; } book::book() { book_ID = “”; book_name = “”; author = “”; publishing = “”; price = 0; } void book::display() { cout << “书号:” << book_ID << “\t”; cout << “书名:” << book_name << “\t”; cout << “作者:” << author << endl; cout << “出版社:” << publishing << “\t”; cout << “定价:” << price << endl; } string book::getbook_ID() { return book_ID; } string book::getbook_name() { return book_name; } string book::getauthor() { return author; } string book::getpublishing() { return publishing; } double book::getprice() { return price; } int main() { int i = 0, buyerid, flag; book *c[2]; layfolk b1("林小茶", 1, "北京", 0); honoured_guest b2("王遥遥", 2, 0.6, "上海", 0); member b3("赵红艳", 3, 5, "广州", 0); buyer *b[3] = {&b1, &b2, &b3}; book c1("7-302-04504-6", "C++程序设计", "谭浩强", "清华", 25); book c2("7-402-03388-9", "数据结构", "许卓群", "北大", 20); c[0] = &c1; c[1] = &c2; cout << "购书人信息:" << endl; for (i = 0; i < 3; i++) { b[i]->display(); } cout << "\n图书信息:" << endl; for (i = 0; i < 2; i++) { c[i]->display(); } cout << "\n请输入购书人编号:"; cin >> buyerid; flag = 0; for (i = 0; i < 3; i++) { if (b[i]->getid() == buyerid) { flag = 1; break; } } if (!flag) { cout << "编号不存在" << endl; } else { b[i]->setpay(c[0]->getprice()); b[i]->setpay(c[1]->getprice()); cout << "购书人需要付费:" << b[i]->getpay() << endl; } return 0; } 以该代码的内容为框架,扩展功能,设计 一个模拟网上购书的结账系统(或类似系统),要求包含至少5个类 以上,实现一组完整的功能.建议结合第7章的内容,增加将信息(客 户、书本信息)从文件中读取,最后结果(订单信息)再写人到文件 中去。使其充分使用类和对象 多态 派生类和继承 从不改变我给出的代码的基础上扩写 并且把交互系统做的更好点
06-05
#include <string> #include <iostream> using namespace std; class buyer // 基类 { protected: string name; // 姓名 int buyerID; // 购书人编号 string address; // 地址 double pay; // 购书费用 public: buyer(); buyer(string n, int b, string a, double p); string getbuyname(); // 取姓名 string getaddress(); // 取地址 double getpay(); // 取应付费用 int getid(); // 取购书人编号 virtual void display() = 0; // 显示对象 virtual void setpay(double = 0) = 0; // 计算购书费用 }; // 会员类 class member : public buyer { private: int leaguer_grade; // 会员级别 public: member(string n, int b, int l, string a, double p) : buyer(n, b, a, p) { leaguer_grade = l; } // 构造函数 void display(); // 显示函数 void setpay(double p); }; // 贵宾类 class honoured_guest : public buyer { private: double discount_rate; // 折扣率 public: honoured_guest(string n, int b, double r, string a, double p) : buyer(n, b, a, p) { discount_rate = r; } // 构造函数 void display(); // 显示对象 void setpay(double p); // 计算购书费用 }; // 普通人类 class layfolk : public buyer { public: layfolk(string n, int b, string a, double p) : buyer(n, b, a, p) {} // 构造函数 void display(); // 显示对象 void setpay(double p); // 计算购书费用 }; // 基类构造函数 buyer::buyer() { name = ""; buyerID = 0; address = ""; pay = 0; } buyer::buyer(string n, int b, string a, double p) { name = n; buyerID = b; address = a; pay = p; } // 成员函数定义 double buyer::getpay() { return pay; } string buyer::getaddress() { return address; } string buyer::getbuyname() { return name; } int buyer::getid() { return buyerID; } // 会员类的显示函数 void member::display() { cout << "购书人姓名:" << name << "\t"; cout << "购书人编号:" << buyerID << "\t"; cout << "购书人为会员,级别:" << leaguer_grade << endl; cout << "地址:" << address << endl; } // 会员类的计算购书费用 void member::setpay(double p) { if (leaguer_grade == 1) pay = 0.95 * p + pay; else if (leaguer_grade == 2) pay = 0.90 * p + pay; else if (leaguer_grade == 3) pay = 0.85 * p + pay; else if (leaguer_grade == 4) pay = 0.80 * p + pay; else if (leaguer_grade == 5) pay = 0.70 * p + pay; else cout << "级别错误!" << endl; } // 贵宾类的显示函数 void honoured_guest::display() { cout << "购书人姓名:" << name << "\t"; cout << "购书人编号:" << buyerID << "\t"; cout << "购书人为贵宾!折扣率为:" << discount_rate * 100 << "%" << endl; cout << "地址:" << address << endl; } // 贵宾类计算购书费用 void honoured_guest::setpay(double p) { pay = pay + (1 - discount_rate) * p; } // 普通类显示函数 void layfolk::display() { cout << "购书人姓名:" << name << "\t"; cout << "购书人编号:" << buyerID << "\t"; cout << "购书人为普通人" << endl; cout << "地址:" << address << endl; } // 普通类计算购书费用 void layfolk::setpay(double p) { pay = pay + p; } // 图书类 class book { protected: string book_ID; // 书号 string book_name; // 书名 string author; // 作者 string publishing; // 出版社 double price; // 定价 public: book(); book(string b_id, string b_n, string au, string pu, double pr); void display(); string getbook_ID(); // 取书号 string getbook_name(); // 取书名 string getauthor(); // 取作者 string getpublishing(); // 取出版社 double getprice(); // 取定价 }; book::book(string b_id, string b_n, string au, string pu, double pr) { book_ID = b_id; book_name = b_n; author = au; publishing = pu; price = pr; } book::book() { book_ID = ""; book_name = ""; author = ""; publishing = ""; price = 0; } void book::display() { cout << "书号:" << book_ID << "\t"; cout << "书名:" << book_name << "\t"; cout << "作者:" << author << endl; cout << "出版社:" << publishing << "\t"; cout << "定价:" << price << endl; } string book::getbook_ID() { return book_ID; } string book::getbook_name() { return book_name; } string book::getauthor() { return author; } string book::getpublishing() { return publishing; } double book::getprice() { return price; } int main() { int i = 0, buyerid, flag; book *c[2]; layfolk b1("林小茶", 1, "北京", 0); honoured_guest b2("王遥遥", 2, 0.6, "上海", 0); member b3("赵红艳", 3, 5, "广州", 0); buyer *b[3] = {&b1, &b2, &b3}; book c1("7-302-04504-6", "C++程序设计", "谭浩强", "清华", 25); book c2("7-402-03388-9", "数据结构", "许卓群", "北大", 20); c[0] = &c1; c[1] = &c2; cout << "购书人信息:" << endl; for (i = 0; i < 3; i++) { b[i]->display(); } cout << "\n图书信息:" << endl; for (i = 0; i < 2; i++) { c[i]->display(); } cout << "\n请输入购书人编号:"; cin >> buyerid; flag = 0; for (i = 0; i < 3; i++) { if (b[i]->getid() == buyerid) { flag = 1; break; } } if (!flag) { cout << "编号不存在" << endl; } else { b[i]->setpay(c[0]->getprice()); b[i]->setpay(c[1]->getprice()); cout << "购书人需要付费:" << b[i]->getpay() << endl; } return 0; } 以该代码的内容为框架,扩展功能,设计 一个模拟网上购书的结账系统(或类似系统),要求包含至少5个类 以上,实现一组完整的功能.建议结合第7章的内容,增加将信息(客 户、书本信息)从文件中读取,最后结果(订单信息)再写人到文件 中去。代码中的类名改用中文意思相应的拼音来代替使其充分使用类和对象 多态 派生类和继承 从不改变我给出的代码的基础上扩写 并且把交互系统做的更好点
06-05
修改这段代码中的错误 #include <iostream> #include <fstream> #include <vector> #include <string> #include <limits> using namespace std; class buyer; // 基类前向声明 class buyer // 基类 { protected: string name; // 姓名 int buyerID; // 购书人编号 string address; // 地址 double pay; // 购书费用 public: buyer(); buyer(string n, int b, string a, double p); virtual ~buyer(); // 虚析构函数 string getbuyname(); // 取姓名 string getaddress(); // 取地址 double getpay(); // 取应付费用 int getid(); // 取购书人编号 virtual void display() = 0; // 显示对象 virtual void setpay(double = 0) = 0; // 计算购书费用 }; // 会员类 class member : public buyer { private: int leaguer_grade; // 会员级别 public: member(string n, int b, int l, string a, double p) : buyer(n, b, a, p) { leaguer_grade = l; } // 构造函数 ~member(); // 析构函数 void display(); // 显示函数 void setpay(double p); }; // 贵宾类 class honoured_guest : public buyer { private: double discount_rate; // 折扣率 public: honoured_guest(string n, int b, double r, string a, double p) : buyer(n, b, a, p) { discount_rate = r; } // 构造函数 ~honoured_guest(); // 析构函数 void display(); // 显示对象 void setpay(double p); // 计算购书费用 }; // 普通人类 class layfolk : public buyer { public: layfolk(string n, int b, string a, double p) : buyer(n, b, a, p) {} // 构造函数 ~layfolk(); // 析构函数 void display(); // 显示对象 void setpay(double p); // 计算购书费用 }; // 图书类 class book { protected: string book_ID; // 书号 string book_name; // 书名 string author; // 作者 string publishing; // 出版社 double price; // 定价 public: book(); book(string b_id, string b_n, string au, string pu, double pr); virtual ~book(); // 虚析构函数 void display(); string getbook_ID(); // 取书号 string getbook_name(); // 取书名 string getauthor(); // 取作者 string getpublishing(); // 取出版社 double getprice(); // 取定价 }; class ShoppingCart { private: vector<book*> books; vector<int> quantities; public: ~ShoppingCart(); // 析构函数 void addBook(book* b, int quantity); void removeBook(int index); void display(); double calculateTotalPrice(); vector<book*> getBooks() const; vector<int> getQuantities() const; }; class Order { private: int orderID; buyer* customer; ShoppingCart cart; string orderDate; public: Order(int id, buyer* c, ShoppingCart& cart, string date) : orderID(id), customer(c), cart(cart), orderDate(date) {} ~Order(); // 析构函数 void display(); void writeToFile(ofstream& out); }; void displayMenu(); void processChoice(int choice, vector<buyer*>& customers, vector<book*>& books, ShoppingCart& cart, int& currentCustomerIndex); vector<buyer*> readCustomersFromFile(const string& filename); vector<book*> readBooksFromFile(const string& filename); void writeOrderToFile(const Order& order, const string& filename); // 基类构造函数 buyer::buyer() : name(""), buyerID(0), address(""), pay(0) {} buyer::buyer(string n, int b, string a, double p) : name(n), buyerID(b), address(a), pay(p) {} buyer::~buyer() {} // 成员函数定义 string buyer::getbuyname() { return name; } string buyer::getaddress() { return address; } double buyer::getpay() { return pay; } int buyer::getid() { return buyerID; } // 会员类的显示函数 void member::display() { cout << "会员信息:" << endl; cout << "姓名:" << name << endl; cout << "编号:" << buyerID << endl; cout << "级别:" << leaguer_grade << endl; cout << "地址:" << address << endl; } // 会员类的计算购书费用 void member::setpay(double p) { switch (leaguer_grade) { case 1: pay += p * 0.95; break; case 2: pay += p * 0.90; break; case 3: pay += p * 0.85; break; case 4: pay += p * 0.80; break; case 5: pay += p * 0.70; break; default: cout << "无效的会员级别!" << endl; } } member::~member() {} // 贵宾类的显示函数 void honoured_guest::display() { cout << "贵宾信息:" << endl; cout << "姓名:" << name << endl; cout << "编号:" << buyerID << endl; cout << "折扣率:" << discount_rate << endl; cout << "地址:" << address << endl; } // 贵宾类计算购书费用 void honoured_guest::setpay(double p) { pay += p * discount_rate; } honoured_guest::~honoured_guest() {} // 普通类显示函数 void layfolk::display() { cout << "普通客户信息:" << endl; cout << "姓名:" << name << endl; cout << "编号:" << buyerID << endl; cout << "地址:" << address << endl; } // 普通类计算购书费用 void layfolk::setpay(double p) { pay += p; } layfolk::~layfolk() {} // 图书类构造函数 book::book() : book_ID(""), book_name(""), author(""), publishing(""), price(0) {} book::book(string b_id, string b_n, string au, string pu, double pr) : book_ID(b_id), book_name(b_n), author(au), publishing(pu), price(pr) {} book::~book() {} // 图书类成员函数 void book::display() { cout << "书籍信息:" << endl; cout << "书号:" << book_ID << endl; cout << "书名:" << book_name << endl; cout << "作者:" << author << endl; cout << "出版社:" << publishing << endl; cout << "价格:" << price << endl; } string book::getbook_ID() { return book_ID; } string book::getbook_name() { return book_name; } string book::getauthor() { return author; } string book::getpublishing() { return publishing; } double book::getprice() { return price; } // 购物车类成员函数 void ShoppingCart::addBook(book* b, int quantity) { books.push_back(b); quantities.push_back(quantity); } void ShoppingCart::removeBook(int index) { if (index >= 0 && index < static_cast<int>(books.size())) { books.erase(books.begin() + index); quantities.erase(quantities.begin() + index); } } void ShoppingCart::display() { if (books.empty()) { cout << "购物车为空。" << endl; return; } cout << "购物车内容:" << endl; for (size_t i = 0; i < books.size(); ++i) { books[i]->display(); cout << "数量: " << quantities[i] << endl; cout << "-----------------" << endl; } } double ShoppingCart::calculateTotalPrice() { double total = 0.0; for (size_t i = 0; i < books.size(); ++i) { total += books[i]->getprice() * quantities[i]; } return total; } vector<book*> ShoppingCart::getBooks() const { return books; } vector<int> ShoppingCart::getQuantities() const { return quantities; } ShoppingCart::~ShoppingCart() {} // 订单类成员函数 void Order::display() { cout << "订单信息:" << endl; cout << "订单号:" << orderID << endl; cout << "日期:" << orderDate << endl; customer->display(); cout << "总价:" << cart.calculateTotalPrice() << endl; cout << "详细内容:" << endl; cart.display(); } void Order::writeToFile(ofstream& out) { out << "订单号:" << orderID << endl; out << "日期:" << orderDate << endl; out << "客户类型:" << (typeid(*customer).name() == typeid(member).name() ? "会员" : typeid(*customer).name() == typeid(honoured_guest).name() ? "贵宾" : "普通客户") << endl; out << "客户姓名:" << customer->getbuyname() << endl; out << "客户编号:" << customer->getid() << endl; out << "客户地址:" << customer->getaddress() << endl; out << "总价:" << cart.calculateTotalPrice() << endl; out << "详细内容:" << endl; for (size_t i = 0; i < cart.getBooks().size(); ++i) { out << "书名:" << cart.getBooks()[i]->getbook_name() << endl; out << "书号:" << cart.getBooks()[i]->getbook_ID() << endl; out << "数量:" << cart.getQuantities()[i] << endl; out << "单价:" << cart.getBooks()[i]->getprice() << endl; out << "-----------------" << endl; } } Order::~Order() {} // 显示菜单函数 void displayMenu() { cout << "===== 网上购书系统 =====" << endl; cout << "1. 显示所有客户" << endl; cout << "2. 显示所有书籍" << endl; cout << "3. 选择客户" << endl; cout << "4. 添加书籍到购物车" << endl; cout << "5. 显示购物车" << endl; cout << "6. 结账并生成订单" << endl; cout << "7. 退出系统" << endl; cout << "========================" << endl; cout << "请输入您的选择:"; } // 处理用户选择函数 void processChoice(int choice, vector<buyer*>& customers, vector<book*>& books, ShoppingCart& cart, int& currentCustomerIndex) { static int orderID = 1; // 用于生成订单号 switch (choice) { case 1: // 显示所有客户 if (customers.empty()) { cout << "没有客户信息。" << endl; } else { for (auto customer : customers) { customer->display(); cout << "-----------------" << endl; } } break; case 2: // 显示所有书籍 if (books.empty()) { cout << "没有书籍信息。" << endl; } else { for (auto book : books) { book->display(); cout << "-----------------" << endl; } } break; case 3: // 选择客户 if (customers.empty()) { cout << "没有客户信息。" << endl; } else { int id; cout << "请输入客户编号:"; cin >> id; cin.ignore(numeric_limits<streamsize>::max(), '\n'); // 清除输入缓冲区 for (size_t i = 0; i < customers.size(); ++i) { if (customers[i]->getid() == id) { currentCustomerIndex = static_cast<int>(i); cout << "已选择客户:" << customers[i]->getbuyname() << endl; break; } } if (currentCustomerIndex == -1) { cout << "未找到指定编号的客户。" << endl; } } break; case 4: // 添加书籍到购物车 if (currentCustomerIndex == -1) { cout << "请先选择客户。" << endl; } else if (books.empty()) { cout << "没有书籍信息。" << endl; } else { int bookIndex; cout << "请输入书籍编号(从1开始):"; cin >> bookIndex; cin.ignore(numeric_limits<streamsize>::max(), '\n'); // 清除输入缓冲区 if (bookIndex >= 1 && bookIndex <= static_cast<int>(books.size())) { int quantity; cout << "请输入购买数量:"; cin >> quantity; cin.ignore(numeric_limits<streamsize>::max(), '\n'); // 清除输入缓冲区 if (quantity > 0) { cart.addBook(books[bookIndex - 1], quantity); cout << "已将书籍添加到购物车。" << endl; } else { cout << "购买数量必须大于0。" << endl; } } else { cout << "无效的书籍编号。" << endl; } } break; case 5: // 显示购物车 cart.display(); break; case 6: // 结账并生成订单 if (currentCustomerIndex == -1) { cout << "请先选择客户。" << endl; } else if (cart.getBooks().empty()) { cout << "购物车为空。" << endl; } else { string date; cout << "请输入订单日期(格式:YYYY-MM-DD):"; cin >> date; cin.ignore(numeric_limits<streamsize>::max(), '\n'); // 清除输入缓冲区 Order order(orderID++, customers[currentCustomerIndex], cart, date); order.display(); char confirm; cout << "确认生成订单?(y/n): "; cin >> confirm; cin.ignore(numeric_limits<streamsize>::max(), '\n'); // 清除输入缓冲区 if (confirm == 'y' || confirm == 'Y') { writeOrderToFile(order, "orders.txt"); cout << "订单已生成并保存。" << endl; cart = ShoppingCart(); // 清空购物车 } else { cout << "订单已取消。" << endl; } } break; case 7: // 退出系统 cout << "感谢使用网上购书系统,再见!" << endl; exit(0); // 退出程序 break; default: cout << "无效的选择,请重新输入。" << endl; break; } cout << endl; } // 从文件读取客户信息 vector<buyer*> readCustomersFromFile(const string& filename) { vector<buyer*> customers; ifstream infile(filename); if (!infile) { cerr << "无法打开文件 " << filename << endl; return customers; } string type, name, address; int id; double rate; while (infile >> type >> id >> name >> address) { if (type == "会员") { int level; infile >> level; customers.push_back(new member(name, id, level, address, 0)); } else if (type == "贵宾") { infile >> rate; customers.push_back(new honoured_guest(name, id, rate, address, 0)); } else if (type == "普通客户") { customers.push_back(new layfolk(name, id, address, 0)); } } infile.close(); return customers; } // 从文件读取书籍信息 vector<book*> readBooksFromFile(const string& filename) { vector<book*> books; ifstream infile(filename); if (!infile) { cerr << "无法打开文件 " << filename << endl; return books; } string id, name, author, pub; double price; while (infile >> id >> name >> author >> pub >> price) { books.push_back(new book(id, name, author, pub, price)); } infile.close(); return books; } // 将订单写入文件 void writeOrderToFile(const Order& order, const string& filename) { ofstream outfile(filename, ios::app); if (!outfile) { cerr << "无法打开文件 " << filename << endl; return; } order.writeToFile(outfile); outfile << endl; outfile.close(); } int main() { vector<buyer*> customers; vector<book*> books; ShoppingCart cart; int currentCustomerIndex = -1; customers = readCustomersFromFile("customers.txt"); books = readBooksFromFile("books.txt"); int choice; do { displayMenu(); cin >> choice; cin.ignore(numeric_limits<streamsize>::max(), '\n'); // 清除输入缓冲区 processChoice(choice, customers, books, cart, currentCustomerIndex); } while (true); // 清理内存 for (auto customer : customers) { delete customer; } for (auto book : books) { delete book; } return 0; }
06-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值