用c++写某图书馆的管理系统中Book类的部分设计及应用代码如下,请完善类 的设计,使其具有统计图书总数(count)及总金额(total)的功能,并在应用程序中输出。
时间: 2024-05-25 12:19:33 浏览: 5
好的,以下是我给出的代码:
class Book {
private:
string name; // 书名
string author; // 作者
double price; // 价格
int count; // 数量
double total; // 总金额
public:
Book(string name, string author, double price, int count) {
this->name = name;
this->author = author;
this->price = price;
this->count = count;
this->total = price * count;
}
string getName() {
return name;
}
string getAuthor() {
return author;
}
double getPrice() {
return price;
}
int getCount() {
return count;
}
double getTotal() {
return total;
}
};
// 应用程序部分
int main() {
Book book1("C++ Primer", "Stanley B. Lippman", 128.5, 10);
Book book2("Java核心技术", "Cay S. Horstmann", 99.5, 20);
Book book3("Python基础教程", "Magnus Lie Hetland", 68.0, 15);
int total_count = book1.getCount() + book2.getCount() + book3.getCount();
double total_money = book1.getTotal() + book2.getTotal() + book3.getTotal();
cout << "图书馆总书籍数:" << total_count << endl;
cout << "图书馆总金额:" << total_money << endl;
return 0;
}
我希望这个修改后的代码能够满足您的需求。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)