第五次实验
来源:互联网 发布:mac复制文件夹到u盘 编辑:程序博客网 时间:2024/06/07 04:50
一、问题及代码
/**文件名称:Ex1-1.cpp*作 者:贾金铎*完成日期:2017年4月10日*对问题及求解方法的描述部分:*输入描述:无*问题描述:编写一个Book类,包含name(书名)、writer(作者)、publicer(出版社)、price(价格)、number(数量)、NO(书号)等数据成员。定义成员函数setBook,用来给书籍的数据成员赋值,定义成员函数borrow和restore,分别办理借书和还书业务,定义成员函数print用于输出—有关书的信息,定义set_NO与get_NO来实现修改类对象的书号与获得类对象的书号。*程序输出:书籍相关内容*问题分析:*算法设计:*/#include <iostream>#include<cstring>using namespace std;class Book{public: string name; /**为什么不是string */ string writer; string Public; double price; int number; int No;public: void setBook(string a,string b,string c,double d,int e,int f); void borrow(); void restore(); void print(); void set_No(); void get_No(); void numb();}date,date2,date3;void Book::setBook(string a,string b,string c,double d,int e,int f){ name=a; writer=b; Public=c; price=d; number=e; No=f;}void Book::borrow(){ No--;}void Book::restore(){ No--;}void Book::print(){ cout<<"name "<<name<<endl; cout<<"writer "<<writer<<endl; cout<<"Public "<<Public<<endl; cout<<"price "<<price<<endl; cout<<"number "<<number<<endl; cout<<"No "<<No<<endl;}int main(){ Book date1,date2,date3; date.setBook("高等数学","贾金铎","花椒",11,9,1); date.print();cout<<endl; date2.setBook("大学物理","贾金铎","花椒",12.0,8,2); date2.print();cout<<endl; date3.setBook("电路分析","贾金铎","花椒",13,7,3); date3.print(); return 0;}
二、运行结果
三、心得体会
老师讲课没跟上,自己做题看了两天书才做好一个,不光要看书,操作很重要,我昨天晚上的问题今天晚上才解决。还是底子差啊。
四、知识点
类的构造,函数的定义,使用。
0 0
- 第五次实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次实验报告
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次实验作业
- 第五次上机实验
- 第五次上机实验
- 三体——哲学与现实
- for循环遍历数组里数组的值
- 浏览器插件之ActiveX开发(四)
- 【最简单】Electron 怎么将网页打包成桌面应用(web前端页面怎么生成exe可执行文件)
- 统计学习方法第四章朴素贝叶斯法-李航
- 第五次实验
- 浏览器插件之ActiveX开发(五)
- 预习指针
- nginx https http2
- 开发中遇到的问题汇总
- RxJava操作符(三) __过滤操作
- poj 1686
- excel分列功能
- Yougth的最大化(二分法加贪心)