设计书类Book,成员函数包括作者(char author[40]),书名(char title[40]),价格(double price)。根据给定的main函数设计必要的成员函数。 main函数已给定,提交时只需要提交main函数外的代码部分。 #include<iostream> #include<cstring> #include<iomanip> using namespace std; //你提交的代码在这里 int main() { cout<<fixed<<setprecision(2); Book b1; cout<<"Show object b1:"; cout<<b1.GetTitle()<<","<<b1.GetAuthor()<<","<<b1.GetPrice()<<endl; char title[40],author[40]; double price; cin>>title>>author>>price; Book b2(title,author,price); cout<<"Show object b2:"; cout<<b2.GetTitle()<<","<<b2.GetAuthor()<<","<<b2.GetPrice()<<endl; cin>>title>>author>>price; cout<<"Reset and Show object b1:"; b1.Set(title,author,price); b1.Show(); cout<<"Reset and Show object b2:"; b2.Set(); b2.Show(); return 0; } 输入 2行,每行3个数据,分别代表一本书的书名、作者以及价格。 输出 按照样例输出格式输出。 输入样例 1 C++程序设计 郑莉 45.12 c++程序设计基础 王育坚 68.5 输出样例 1 Show object b1:NULL,NONE,0.00 Show object b2:C++程序设计,郑莉,45.12 Reset and Show object b1:c++程序设计基础,王育坚,68.50 Reset and Show object b2:高等数学(第七版)上册,同济大学数学系,37.70

时间: 2024-03-26 08:36:27 浏览: 34
``` #include <iostream> #include <cstring> #include <iomanip> using namespace std; class Book { private: char author[40]; char title[40]; double price; public: Book() { strcpy(this->author, "NONE"); strcpy(this->title, "NULL"); this->price = 0.00; } Book(char title[], char author[], double price) { strcpy(this->author, author); strcpy(this->title, title); this->price = price; } char* GetAuthor() { return this->author; } char* GetTitle() { return this->title; } double GetPrice() { return this->price; } void Set(char title[], char author[], double price) { strcpy(this->author, author); strcpy(this->title, title); this->price = price; } void Set() { char title[40], author[40]; double price; cin >> title >> author >> price; Set(title, author, price); } void Show() { cout << this->title << "," << this->author << "," << fixed << setprecision(2) << this->price << endl; } }; int main() { cout << fixed << setprecision(2); Book b1; cout << "Show object b1:"; cout << b1.GetTitle() << "," << b1.GetAuthor() << "," << b1.GetPrice() << endl; char title[40], author[40]; double price; cin >> title >> author >> price; Book b2(title, author, price); cout << "Show object b2:"; cout << b2.GetTitle() << "," << b2.GetAuthor() << "," << b2.GetPrice() << endl; cin >> title >> author >> price; cout << "Reset and Show object b1:"; b1.Set(title, author, price); b1.Show(); cout << "Reset and Show object b2:"; b2.Set(); b2.Show(); return 0; } ```

最新推荐

recommend-type

定义一个Book类,实现简单操作实验报告

(1)数据成员:bookname(书名)、price(价格)、number(存书数量)。 (2)成员函数:display()显示图书的情况;borrow()将存书数量减1,并显示当前存书量;restore()将存书量加1,并显示当前存书量。 (3)在main函数中,...
recommend-type

软件系统架构设计说明书模板

本系统采用四层架构设计 - 2 - 一、展现层 - 2 - Web前端 - 2 - 二、通讯层 - 2 - 三、服务层 - 3 - 四、数据层 - 4 - 其他系统: - 4 - 1、认证系统: - 4 - 2、日志系统: - 7 - 3、会话治理 - 8 - 4、DNS劫持处理...
recommend-type

xx系统-接口设计说明书-20xxxxxx.docx

接口设计说明书接口设计说明书接口设计说明书接口设计说明书接口设计说明书接口设计说明书接口设计说明书接口设计说明书
recommend-type

学校图书借阅管理系统 数据库系统设计

约图书,查询时可按图书的书名,作者,出版社来 查询,查询到的图书用表格显示,并且可以显示图书 的借阅情况。 (2)借书还书界面:该界面主要是用于读者的借书和还 书的情况,并且读者可以归还图书。 八....
recommend-type

机械设计课程设计说明书(齿轮箱).pdf

目录 1 1 电动机的选择 3 1.1 选择电动机的转速 3 1.1.1 计算传动滚筒的转速 3 1.1.2 计算总传动比范围 3 1.1.3 确定电动机的转速 3 1.2 所需电动机的输出功率 3 1.2.1 工作机的功率 4 1.2.2 传动装置的总效率 4 ...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

get() { return this.photoState },

这是一个 JavaScript 中的方法定义,它定义了一个名为 `get` 的方法。这个方法没有参数,它返回了 `this.photoState`。在这个方法中,`this` 是指当前对象,而 `photoState` 是该对象的一个属性。通常情况下,`get` 方法用于获取对象的属性值,并且可以在获取属性值之前进行一些逻辑操作。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。