基础的图书馆管理系统
2016-03-09 21:44
274 查看
编写图书馆管理系统。要求编写一个类。
类中的数据成员:name(书名)、writer(著者)、public_name(出版社)、price(价格)、number(数量)、no(书号)
类中的成员函数:setbook(为数据成员赋值)
borrow和restore(借入和借出,表现为number的加一和减一)
print函数
set_no和get_no设置索书号和获得索书号#include <iostream>
#include <string>
using namespace std;
class book
{
string name;
string writer;
string public_name;
double price;
int number;
int no;
public:
void setbook(string,string,string,double,int,int);
void borrow();
void restore();
void print();
void set_no(int);
int get_no();
};
void book::setbook (string n,string w,string p,double pri,int num,int noo)
{
name=n;
writer=w;
public_name=p;
price=pri;
number=num;
no=noo;
}
void book::borrow()
{
--number;
}
void book::restore()
{
++number;
}
void book::print()
{
cout<<"name: "<<name<<endl;
cout<<"writer: "<<writer<<endl;
cout<<"public name: "<<public_name<<endl;
cout<<"price: "<<price<<endl;
cout<<"number: "<<number<<endl;
cout<<"NO: "<<no<<endl<<endl;
}
void book::set_no(int n)
{
no=n;
}
int book::get_no()
{
return no;
}
int main()
{
book b;
b.setbook("自动控制原理","王建辉","东大出版社",20,3,3589);
b.print();
b.borrow();
b.print();
b.restore();
b.print();
b.set_no(39048);
cout<<"索书号为"<<b.get_no()<<endl;
}这个类包含的只有数据成员和成员函数。实现了图书馆管理系统中一些最基础的功能。
注意:1。类中的数据成员一般设置为私有。私有的意思是只有类内的成员函数才可以访问这些成员。
当时编写的时候,进行void book::print()函数的定义时,忘记写book,这时print函数变成类外的函数,不能直接访问数据成员,出现数据成员未定义的错误。
2.函数一般在需要从键盘输入数据的时候需要形参。
3.类的编写首先确定其要实现的具体功能(即成员函数的确定),然后确定其数据成员。
类中的数据成员:name(书名)、writer(著者)、public_name(出版社)、price(价格)、number(数量)、no(书号)
类中的成员函数:setbook(为数据成员赋值)
borrow和restore(借入和借出,表现为number的加一和减一)
print函数
set_no和get_no设置索书号和获得索书号#include <iostream>
#include <string>
using namespace std;
class book
{
string name;
string writer;
string public_name;
double price;
int number;
int no;
public:
void setbook(string,string,string,double,int,int);
void borrow();
void restore();
void print();
void set_no(int);
int get_no();
};
void book::setbook (string n,string w,string p,double pri,int num,int noo)
{
name=n;
writer=w;
public_name=p;
price=pri;
number=num;
no=noo;
}
void book::borrow()
{
--number;
}
void book::restore()
{
++number;
}
void book::print()
{
cout<<"name: "<<name<<endl;
cout<<"writer: "<<writer<<endl;
cout<<"public name: "<<public_name<<endl;
cout<<"price: "<<price<<endl;
cout<<"number: "<<number<<endl;
cout<<"NO: "<<no<<endl<<endl;
}
void book::set_no(int n)
{
no=n;
}
int book::get_no()
{
return no;
}
int main()
{
book b;
b.setbook("自动控制原理","王建辉","东大出版社",20,3,3589);
b.print();
b.borrow();
b.print();
b.restore();
b.print();
b.set_no(39048);
cout<<"索书号为"<<b.get_no()<<endl;
}这个类包含的只有数据成员和成员函数。实现了图书馆管理系统中一些最基础的功能。
注意:1。类中的数据成员一般设置为私有。私有的意思是只有类内的成员函数才可以访问这些成员。
当时编写的时候,进行void book::print()函数的定义时,忘记写book,这时print函数变成类外的函数,不能直接访问数据成员,出现数据成员未定义的错误。
2.函数一般在需要从键盘输入数据的时候需要形参。
3.类的编写首先确定其要实现的具体功能(即成员函数的确定),然后确定其数据成员。
相关文章推荐
- while循环计算1到100之和
- 使用common-fileUpload和 Spring中MultipartHttpServletRequest实现文件上传
- Android中的缩略图制作
- 异常控制try-throw-catch用法小结
- OC-类和对象
- 第二周项目1宣告主权
- Activity生命周期
- Linux下查看/修改系统时区、时间
- 中缀表达式转化成后缀表达式
- unity视频笔记——flappy bird
- while循环计算1到100之和
- WIN32汇编语言在窗口添加按钮,点击按钮实现跳转到一个程序或者一个URL。。。
- hibernate和mybatis比较
- 第二周项目3——小试循环(1)
- Oracle数据库的权限、用户、角色管理
- POJ - 2115 C Looooops(扩展欧几里德求解模线性方程(线性同余方程))
- Conditional Random Fields as Recurrent Neural Networks
- poj 2676 深搜之sudo
- 关于VLOOUP函数与index match函数
- SQL实例整理