设计一个书类Book能够保存书名、定价所有书的本数和总价。提示:class Bookprivate string bkName; double price; static int number; static double totalPrice;public Bookstringdouble; ~Book; double getPrice return p
class Book{ private: string bkName; double price; static int number; static double totalPrice; public: Book(string name, double p){ bkName = name; price = p; number++; totalPrice += p; } ~Book(){ number--; totalPrice -= price; } double getPrice(){ return price; } string getName(){ return bkName; } static int getNumber(){ return number; } static double getTotalPrice(){ return totalPrice; } }; int Book::number = 0; double Book::totalPrice = 0.0
原文地址: https://www.cveoy.top/t/topic/eHX9 著作权归作者所有。请勿转载和采集!