C++面向对象课程设计报告_快递系统
面向对象程序课程设计题目:快件管理系统需求分析该系统为两种角色的用户提供服务,一种是代收点服务人员,一种是收件人。代收点服务人员根据账号、密码登录系统。收件人无需登录即可使用系统。代收点服务人员可将快件信息录入系统,快件信息包括快递单号、快递公司、收件人、收件人联系电话、收件人地址、邮编、寄件人、寄件人联系电话、寄件...
面向对象程序课程设计
目 录
-
题目:快件管理系统
-
需求分析
该系统为两种角色的用户提供服务,一种是代收点服务人员,一种是收件人。代收点服务人员根据账号、密码登录系统。收件人无需登录即可使用系统。代收点服务人员可将快件信息录入系统,快件信息包括快递单号、快递公司、收件人、收件人联系电话、收件人地址、邮编、寄件人、寄件人联系电话、寄件人地址、邮编。系统自动为每个快递生成一个取件号,每个取件号都对应一个存放位置(假设站点有20个货架,每个货架有5层,每层可放10个快件)只有空的位置才能存放快件。如收件人来取件,服务人员可根据手机号或者取件号查询到该快件并标记取件成功。收件人可以通过手机号查询自己在该代收点的快件的取件号以及是否收取的情况,服务人员还可以查询全部的快递,同样也可以通过手机号查询收件人在该代收点的快件的取件号以及是否收取的情况,系统退出后能保存当天的快件信息。代收点服务人员可以根据快递单号查找、删除、修改某个快件中的部分信息,可以查询所有未取快件的数量,可以查询新进的快件和已取的快件,同时也可以查询未取件人的快递信息。
-
系统结构图
-
类的设计
-
程序代码与说明
//admin.h
#pragma once
#include "manageexpress.h"
#include<vector>
#include<string>
using std::string;
using std::vector;
class Admin {
private:
string account;//管理员账号
string password;//管理员密码
Manageexpress manage;
public:
Admin();
void homepage();//进入系统
int login();//账号密码的检验
};
//manageexpress.h
#pragma once
#include"express.h"
#include<fstream>
#include <algorithm>
#include<string>
#include<iostream>
#include<vector>
#include <ctime>
using namespace std;
class Manageexpress {
private:
int takeup[21][6][11];//取件号
public:
vector<Express>exp;//将信息存到exp中
void getinfo();//读取快递信息
void search();//查收快递
void searchpickcode();//查找取件号
void setshouname(string id2_);//修改收件人名字
void setshouphone(string id2_);
void setshousite(string id2_);
void setshoucode(string id2_);
void settake(string id2_);
void setpickcode(string id2_);
void gettake();//返回取件信息
void renew();//覆写快递
void unpickexpress();//查询未取快递
};
//express.h
#pragma once
#include<iostream>
#include<cstring>
#include <string>
using namespace std;
class Express {
private:
string id;//快递信息
string gongsi;
string shouname;
string shouphone;
string shousite;
string shoucode;
string jiname;
string jiphone;
string jisite;
string jicode;
string pickcode;
bool take;
public:
Express(string id_, string gongsi_, string shouname_, string shouphone_, string shousite_, string shoucode_, string jiname_, string jiphone_, string jisite_, string jicode_,int take_,string pickcode_);//将快递信息读取到类
void setpickcode(int i, int j, int k);//将随机的取件号改为字符
string getid();//返回快递单号
string getgongsi();//返回快递公司
string getshouname();
string getshouphone();
string getshousite();
string getshoucode();
string getjiname();
string getjiphone();
string getjisite();
string getjicode();
string getpickcode();
bool gettake();
void setshouname(string shouname2_);//修改收件人姓名
void setshouphone(string shouphone2_);
void setshousite(string shousite2_);
void setshoucode(string shoucode2_);
void settake(int i);
void setpickcode(string pickcode2_);
};
//admin.cpp
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include"admin.h"
#include"manageexpress.h"
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
Admin::Admin() {
account = "admin";
password = "admin";
}
void Admin::homepage() {
cout << "*****************************************************\n";
cout << "* *\n";
cout << "* 欢迎来到快递系统 *\n";
cout << "* 请选择你的身份 *\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 1.代收点服务管理员 2.收件人 3.退出 *\n";
cout << "* *\n";
cout << "* *\n";
cout << "*****************************************************\n";
int n, m;
string day;
while (cin >> n) {
vector<Express>::iterator i;
switch (n) {
case 1: //代收点服务管理员
if (login()) {
while (1) {
int n;
cout << " 请选择功能 " << endl;
cout<<"1.查询快递 2.收件人取快递 3.查询全部快递 4.查询、增加或删除快递信息 5.查询未取快递 6.退出" << endl;
cin >> n;
if (n == 6) break;
manage.getinfo();
if (n == 1) {
cout << " 请选择功能 " << endl;
cout << "1.查询取件号 2.查询取件信息 3.退出" << endl;
int n;
cin >> n;
if (n == 1) {
manage.searchpickcode();
}
if (n == 2) {
manage.gettake();
}
if (n == 3)break;
if (n != 1 && n != 2 && n != 3) {
cout << "您的输入有误" << endl;
break;
}
manage.search();
//manage.exp.clear();//清除读入的数据
//break;
}
if (n == 2) {
manage.search();
//manage.exp.clear();//清除读入的数据
}
if (n == 3) {
cout << "快递单号\t" << "快递公司\t" << "收件人\t" << "收件人联系电话\t" << "收件人地址\t" << "邮编\t" << "寄件人\t" << "寄件人联系电话\t" << "寄件人地址\t" << "邮编\t" << "是否取件\t" << "取件码\t" << endl;
for (i = manage.exp.begin(); i != manage.exp.end(); i++) {
cout << (*i).getid() << "\t" << (*i).getgongsi() << "\t" << (*i).getshouname() << "\t" << (*i).getshouphone() << "\t" << (*i).getshousite() << "\t"
<< (*i).getshoucode() << "\t" << (*i).getjiname() << "\t" << (*i).getjiphone() << "\t" << (*i).getjisite() << "\t" << (*i).getjicode() << "\t";
if ((*i).gettake() == 1)cout << "已取件\t";
else cout << "未取件\t";
cout << (*i).getpickcode() << endl;
}
manage.renew();
}
if (n == 4) {
cout << "请输入快递单号" << endl;
string id2;
cin >> id2;
cout << "快递单号\t" << "快递公司\t" << "收件人\t" << "收件人联系电话\t" << "收件人地址\t" << "邮编\t" << "寄件人\t" << "寄件人联系电话\t" << "寄件人地址\t" << "邮编\t" << "是否取件\t" << "取件码\t" << endl;
for (i = manage.exp.begin(); i != manage.exp.end(); i++) {
if (id2 == (*i).getid()) {
cout << (*i).getid() << "\t" << (*i).getgongsi() << "\t" << (*i).getshouname() << "\t" << (*i).getshouphone() << "\t" << (*i).getshousite() << "\t"
<< (*i).getshoucode() << "\t" << (*i).getjiname() << "\t" << (*i).getjiphone() << "\t" << (*i).getjisite() << "\t" << (*i).getjicode() << "\t";
if ((*i).gettake() == 1)cout << "已取件\t";
else cout << "未取件\t";
cout << (*i).getpickcode() << endl;
break;
}
}
manage.renew();
if (i == manage.exp.end()) {
cout << "您输入的快递单号查询不到快递" << endl;
}
if (i != manage.exp.end()) {
cout << "是否修改该快递信息" << endl;
cout << " 1.是 2.否 " << endl;
int m;
cin >> m;
if (m == 1) {
cout << "您将要修改哪个信息" << endl;
cout << "1.收件人姓名" << endl
<< "2.收件人联系电话"<<endl
<< "3.收件人地址" << endl
<< "4.邮编" << endl
<< "5.是否取件信息" << endl
<< "6.取件号" << endl;
int k;
cin >> k;
if (k == 1)manage.setshouname(id2);
if (k == 2)manage.setshouphone(id2);
if (k == 3)manage.setshousite(id2);
if (k == 4)manage.setshoucode(id2);
if (k == 5)manage.settake(id2);
if (k == 6)manage.setpickcode(id2);
if (k < 1 || k > 6) {
cout << "您的输入有误" << endl;
}
}
if (m == 2);
if (m != 1 && m != 2) {
cout << "您的输入有误" << endl;
}
}
}
if (n == 5) {
manage.unpickexpress();
manage.renew();
}
if (n != 1 && n != 2 && n != 3 && n != 4 && n != 5 && n != 6) {
cout << "您的输入有误" << endl;
//break;
}
manage.exp.clear();//清除读入的数据
}
}
break;
case 2: //收件人
manage.getinfo();
cout <<" 请选择功能 " << endl;
cout <<"1.查询取件号或取件 2.查询取件信息 3.退出" << endl;
int n;
cin >> n;
if (n == 1) {
manage.searchpickcode();
}
if (n == 2) {
manage.gettake();
}
if (n == 3)break;
if (n != 1 && n != 2 && n != 3) {
cout << "您的输入有误" << endl;
break;
}
manage.search();
manage.exp.clear();//清除读入的数据
break;
case 3:
exit(0);
break;
default:
cout << "请选择正确的选项!\n";
break;
}
homepage();
}
}
int Admin::login() {
string username, password;
cout << "请输入用户名:";
cin >> username;
cout << "请输入密码:";
cin >> password;
system("cls");
if (username == account && password == this->password) {
cout << "登录成功\n";
return 1;
}
else {
cout << "密码错误!请重新选择你的操作!" << endl;
return 0;
}
}
//manageexpress.cpp
#include"manageexpress.h"
#include<ctime>
using namespace std;
void Manageexpress::getinfo() {
string name;
name = "快递数据.txt";
ifstream in(name.c_str());
string id, gongsi, shouname, shouphone, shousite, shoucode, jiname, jiphone, jisite, jicode, pickcode;
string date;
int take;
getline(in,date);
//cout << date<< endl;
srand((unsigned)time(nullptr));
while (!in.eof()) {
in >> id >> gongsi >> shouname >> shouphone >> shousite >> shoucode >> jiname >> jiphone >> jisite >> jicode >> take >> pickcode;
//cout << id << endl;
if (in.fail())break;//读掉最后一行空行
Express a(id, gongsi, shouname, shouphone, shousite, shoucode, jiname, jiphone, jisite, jicode, take, pickcode);
if (a.getpickcode() == "0") {
while (1) {
int i, j, k, flag = 0;
i = rand() % 20 + 1; j = rand() % 5 + 1; k = rand() % 10 + 1;
if (takeup[i][j][k] == 0) {
takeup[i][j][k] = 1;
flag = 1;
a.setpickcode(i, j, k);
}
if (flag == 1)break;
}
}
exp.push_back(a);
}
}
void Manageexpress::search(){
string phone, code2;
cout << " 是否取件 " << endl;
cout << " 1.取件 2.退出 " << endl;
int num;
cin >> num;
if (num == 1) {
cout << "请输入手机号码或取件号进行取件" << endl;
cout << " 1.手机号 2.取件号 3.退出 " << endl;
int m;
cin >> m;
if (m == 1) {
cout << "请输入您的手机号" << endl;
cin >> phone;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
//cout << (*i).getphone()<< endl;
if (phone == (*i).getshouphone()) {
if ((*i).gettake() == 0)
cout << "取件成功,感谢您的取件!" << endl;
else cout << "您已经取过该快递" << endl;
(*i).settake(1);
renew();
break;
}
}
if (i == exp.end()) {
cout << "您输入的手机号查询不到快递,请选择" << endl;
search();
}
}
if (m == 2) {
cout << "请输入您的取件号" << endl;
cin >> code2;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if (code2 == (*i).getpickcode()) {
if ((*i).gettake() == 0)
cout << "取件成功,感谢您的取件!" << endl;
else cout << "您已经取过该快递" << endl;
(*i).settake(1);
renew();
break;
}
}
if (i == exp.end()) {
cout << "您输入的取件号查询不到快递,请选择" << endl;
search();
}
}
if (m == 3)renew();
if (m != 1 && m != 2 && m != 3){
cout << "您的输入有误,请重新选择" << endl;
search();
}
}
if (num == 2)renew();
if (num != 1 && num != 2) {
cout << "您输入有误,请重新输入" << endl;
search();
}
}
void Manageexpress::searchpickcode()
{
string phone;
cout << "请输入您的手机号,退出请按0" << endl;
cin >> phone;
if (phone == "0")return;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if (phone == (*i).getshouphone()) {
cout << "您的取件号为:"<<(*i).getpickcode() << endl;
break;
}
}
if (i == exp.end()) {
cout << "您输入的手机号查询不到快递" << endl;
searchpickcode();
}
}
void Manageexpress::setshouname(string id2_)
{
string id2,shouname2;
id2 = id2_;
cout << "请输入修改后的收件人姓名,退出请按0" << endl;
cin >> shouname2;
if (shouname2 == "0")return;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if (id2 == (*i).getid()) {
(*i).setshouname(shouname2);
renew();
break;
}
}
cout << "您已修改完毕" << endl;
}
void Manageexpress::setshouphone(string id2_)
{
string id2, shouphone2;
id2 = id2_;
cout << "请输入修改后的收件人联系电话,退出请按0" << endl;
cin >> shouphone2;
if (shouphone2 == "0")return;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if (id2 == (*i).getid()) {
(*i).setshouphone(shouphone2);
renew();
break;
}
}
cout << "您已修改完毕" << endl;
}
void Manageexpress::setshousite(string id2_)
{
string id2, shousite2;
id2 = id2_;
cout << "请输入修改后的收件人地址,退出请按0" << endl;
cin >> shousite2;
if (shousite2 == "0")return;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if (id2 == (*i).getid()) {
(*i).setshousite(shousite2);
renew();
break;
}
}
cout << "您已修改完毕" << endl;
}
void Manageexpress::setshoucode(string id2_)
{
string id2, shoucode2;
id2 = id2_;
cout << "请输入修改后的收件人邮编,退出请按0" << endl;
cin >> shoucode2;
if (shoucode2 == "0")return;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if (id2 == (*i).getid()) {
(*i).setshoucode(shoucode2);
renew();
break;
}
}
cout << "您已修改完毕" << endl;
}
void Manageexpress::settake(string id2_)
{
string id2;
int take2;
id2 = id2_;
cout << "请输入修改后的取件的状态,退出请按0" << endl;
cout << " 1.已取件 2.未取件 " << endl;
cin >> take2;
if (take2 == 0)return;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if (id2 == (*i).getid()) {
if(take2==1)
(*i).settake(1);
else
(*i).settake(0);
renew();
break;
}
}
cout << "您已修改完毕" << endl;
}
void Manageexpress::setpickcode(string id2_)
{
string id2, pickcode2;
id2 = id2_;
cout << "请输入修改后的取件号(请写成例如:1-1-1 的形式),退出请按0" << endl;
cin >> pickcode2;
if (pickcode2 == "0")return;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if ((*i).getpickcode() == pickcode2) {
cout << "该位置已被占用,请选择其他位置" << endl;
cin >> pickcode2;
}
}
for (i = exp.begin(); i != exp.end(); i++) {
if (id2 == (*i).getid()) {
(*i).setpickcode(pickcode2);
renew();
break;
}
}
cout << "您已修改完毕" << endl;
}
void Manageexpress::gettake()
{
string phone;
cout << "请输入您的手机号,退出请按0" << endl;
cin >> phone;
if (phone == "0")return;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if (phone == (*i).getshouphone()) {
if ((*i).gettake() == 0)
cout << "您还未取件" << endl;
else
cout << "您已经取过该快递" << endl;
break;
}
}
if (i == exp.end()) {
cout << "您输入的手机号查询不到快递" << endl;
gettake();
}
}
void Manageexpress::renew()
{
string name;
name = "快递数据.txt";
vector<Express>::iterator i;
ofstream out(name);
out << "快递单号\t" << "快递公司\t" << "收件人\t" << "收件人联系电话\t" << "收件人地址\t" << "邮编\t" << "寄件人\t" << "寄件人联系电话\t" << "寄件人地址\t" << "邮编\t" << "是否取件\t" << "取件码\t" << endl;
for (i = exp.begin(); i != exp.end(); i++) {
out << (*i).getid() << "\t" << (*i).getgongsi() << "\t" << (*i).getshouname() << "\t" << (*i).getshouphone() << "\t" << (*i).getshousite() << "\t"
<< (*i).getshoucode() << "\t" << (*i).getjiname() << "\t" << (*i).getjiphone() << "\t" << (*i).getjisite() << "\t" << (*i).getjicode() << "\t" << (*i).gettake() << "\t" << (*i).getpickcode() << endl;
}
}
void Manageexpress::unpickexpress()
{
cout << "快递单号\t" << "快递公司\t" << "收件人\t" << "收件人联系电话\t" << "收件人地址\t" << "邮编\t" << "寄件人\t" << "寄件人联系电话\t" << "寄件人地址\t" << "邮编\t" << "是否取件\t" << "取件码\t" << endl;
int j = 0;
vector<Express>::iterator i;
for (i = exp.begin(); i != exp.end(); i++) {
if ((*i).gettake() == 0) {
cout << (*i).getid() << "\t" << (*i).getgongsi() << "\t" << (*i).getshouname() << "\t" << (*i).getshouphone() << "\t" << (*i).getshousite() << "\t"
<< (*i).getshoucode() << "\t" << (*i).getjiname() << "\t" << (*i).getjiphone() << "\t" << (*i).getjisite() << "\t" << (*i).getjicode() << "\t";
if ((*i).gettake() == 1)cout << "已取件\t";
else cout << "未取件\t";
cout << (*i).getpickcode() << endl;
j++;
}
}
cout << "还有未取快递为:" << j << endl;
}
//express.cpp
#pragma once
#include"express.h"
#include<vector>
#include<string>
#include<iostream>
using std::vector;
using namespace std;
Express::Express(string id_, string gongsi_, string shouname_, string shouphone_, string shousite_, string shoucode_, string jiname_, string jiphone_, string jisite_, string jicode_,int take_,string pickcode_) {
id = id_; gongsi = gongsi_; shouname = shouname_; shouphone = shouphone_; shousite = shousite_; shoucode = shoucode_; jiname = jiname_; jiphone = jiphone_; jisite = jisite_; jicode = jicode_;
take = take_; pickcode = pickcode_;
}
void Express::setpickcode(int i, int j, int k)
{
pickcode = to_string(i) + "-"+to_string(j)+"-" + to_string(k);
}
string Express::getid()
{
return id;
}
string Express::getgongsi()
{
return gongsi;
}
string Express::getshouname()
{
return shouname;
}
string Express::getshouphone()
{
return shouphone;
}
string Express::getshousite()
{
return shousite;
}
string Express::getshoucode()
{
return shoucode;
}
string Express::getjiname()
{
return jiname;
}
string Express::getjiphone()
{
return jiphone;
}
string Express::getjisite()
{
return jisite;
}
string Express::getjicode()
{
return jicode;
}
string Express::getpickcode()
{
return pickcode;
}
bool Express::gettake()
{
return take;
}
void Express::setshouname(string shouname2_)
{
shouname = shouname2_;
}
void Express::setshouphone(string shouphone2_)
{
shouphone = shouphone2_;
}
void Express::setshousite(string shousite2_)
{
shousite = shousite2_;
}
void Express::setshoucode(string shoucode2_)
{
shoucode = shoucode2_;
}
void Express::settake(int i)
{
take = i;
}
void Express::setpickcode(string pickcode2_)
{
pickcode = pickcode2_;
}
//main.cpp
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include "admin.h"
int main() {
Admin admin;
admin.homepage();
return 0;
}
-
运行结果与分析
1.首先将快递信息录入excle当中,将文件另存为.txt格式。
2.选择1进入管理员系统
3.登录成功,进行清屏,进入功能选项,选择1进行快递查询,又进入查询什么信息的选项,选择2进行取件的查询,输入手机号显示还未取件,进而询问是否取件,选择1取件,进入手机号取件还是取件号取件,但是选择了退出不取件,然后选择3显示全部的快递信息,又选择5显示未取件信息,选择4进行单个快递的查询或修改,输入快递单号,输出快递信息,进入是否修改该快递信息,选择1是。
3.输入修改的名字:张三,然后又查询全部快递,此时该快递信息名字已改为“张三”,然后进行其他快递的取件,取件完成,查询单个快递的信息,此时已显示已取件。
4.将快递的取件号修改,故意将已占有的取件位置输入,会输出该位置已经被占有,那么重新修改一个取件号,进而查询全部快递。如下也是以上操作。
5.进入收件人系统,收件人只有管理员中的,查询快件的取件号和取件信息,以及取件系统,操作和上面一样。
6.如上一样,但最后不小心点到了什么键,导致系统不是正常关闭,此时要是选择3,系统才会正常关闭。
7.关闭系统,文件会被自动修改和保存。
总结:该快递程序设计管理,分别有二个用户,一个是收件人,收件人不能管理快递信息,只能通过自己的手机号来查询自己的快递是否取件,并且可以通过手机号或者取件号来进行取件。服务管理人员可以进行快递的修改,也可以通过手机号或者取件号来进行对收件人的取件,管理人员也可以通过快递单号查询快递信息,也可以生成全部的快递信息,或者生成已取件的快递信息。
更多推荐
所有评论(0)