书店管理系统
设计一个书店管理系统,能完成书店的日常管理工作。
要求完成的基本功能:
1、进货入库记录。
2、销售出货记录。
3、图书信息查询:可通过书名、作者等途径查询某本图书的详细信息(含书名、作者、出版社、页数、最新入库时间、库存量、价格等)。
4、自动预警提示(当某图书的库存量为1时自动预警提示)
模块化
根据类的继承与多态,我们可以创建以书Book为基类,BookStore为派生类,分为头文件.h和函数文件.c再加上主函数main.c即可
类的分别实现
类的实现是在分别的.h文件当中,并且.h文件当中应当包含类所含成员函数和属性等等。
Book.h
#pragma once
#include <iostream>
#include <fstream>
#include <cstring>
#include <ctime>
#include <cstdlib>
using namespace std;
class Book {
private:
string title, author, publisher, time;
int pages, quantity;
float price;
public:
Book();
void setTitle(string title);
void setAuthor(string author);
void setPublisher(string publisher);
void setTime(string time);
void setPages(int pages);
void setQuantity(int quantity);
void setPrice(float price);
string getTitle();
string getAuthor();
string getPublisher();
string getTime();
int getPages();
int getQuantity();
float getPrice();
};
BookStore.h
#pragma once
#include <iostream>
#include <fstream>
#include <cstring>
#include <ctime>
#include <cstdlib>
using namespace std;
class BookStore
{
private:
Book books[1000];
int count;
public:
BookStore();
void addBook();
void sellBook();
void queryBook();
void checkStock();
};
在.c文件中类外定义
注意带上头文件
Book.c
#include <iostream>
#include <fstream>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include "Book.h"
using namespace std;
Book::Book()
{
// 初始化
title = "";
author = "";
publisher = "";
time = "";
pages = 0;
quantity = 0;
price = 0.0;
}
//设置图书信息
void Book::setTitle(string title)
{
this->title = title;
}
void Book::setAuthor(string author)
{
this->author = author;
}
void Book::setPublisher(string publisher)
{
this->publisher = publisher;
}
void Book::setTime(string time)
{
this->time = time;
}
void Book::setPages(int pages)
{
this->pages = pages;
}
void Book::setQuantity(int quantity)
{
this->quantity = quantity;
}
void Book::setPrice(float price)
{
this->price = price;
}
//获取图书信息
string Book::getTitle()
{
return title;
}
string Book::getAuthor()
{
return author;
}
string Book::getPublisher()
{
return publisher;
}
string Book::getTime()
{
return time;
}
int Book::getPages()
{
return pages;
}
int Book::getQuantity()
{
return quantity;
}
float Book::getPrice()
{
return price;
}
主函数进行运行和设置菜单操作等,其余的请关注用户CodeSeven
我都放在那里面了,感谢