本课程设计报告,对整个系统及其内部的各个功能模块的构想、设计思路、实现方法和过程,做出了详细的说明和介绍。
#include<iostream.h>#include<windows.h>
#include<fstream.h>
#define N 20 //车辆总存储量
struct Cars{
int num //车辆编号
int pnum //车牌号
char made[20]//车辆制造公司
double year //车辆购买时间
char type //车辆型号,B-大客车,C-小轿车,L-卡车
int km //总公里数
int cost //基本维护费用
}
class Manager{
private:
Cars car[N]
int people[N]//载客量
int coach[N] //箱数
int weight[N]//载重量
int top //记录当前车辆数量
public:
Manager(){top = 0}//车辆初始值为0
void add() //添加函数
void search()//查询函数
void show() //显示函数
void edit() //编辑函数
void delet() //删除函数
void sum() //统计函数
void read() //读取函数
void write() //存储函数
void jiemian()//总界面
}
void Manager::add(){
int a = 0, y
while(1){
if(top <N){
int i
cout<<"请输入需添加的车辆信息:"<<endl
cout<<"车辆编号:"
cin>>i
for(int j = 0j <topj++){
if(car[j].num == i){
cout<<"编号重复,添加失败!系统将自动返回..."<<endl
a++
break
}
}
if(a == 0){ //编号不重复
car[top].num = i
cout<<"车牌号:"
cin>>car[top].pnum
cout<<"车辆制造公司:"
cin>>car[top].made
cout<<"购买时间:"
cin>>car[top].year
cout<<"车辆型号(B-大客车,C-小轿车,L-卡车):"
cin>>car[top].type
cout<<"总公里数:"
cin>>car[top].km
if(car[top].type == 'B'|| car[top].type == 'b'){
cout<<"载客量:"
cin>>people[top]
car[top].cost = 2000
}
else if(car[top].type == 'C'|| car[top].type == 'c'){
cout<<"车厢数:"
cin>>coach[top]
car[top].cost = 1000
}
else{
cout<<"载重量:"
cin>>weight[top]
car[top].cost = 1500
}
top++
cout<<"是否继续添加?(1-是, 2-否)"<<endl
cin>>y
if(y == 2){
cout<<"请稍等,系统将自动返回功能界面..."<<endl
break
}
}
else //编号重复
break
}
else{
cout<<"车辆信息库已满,不能再添加!"<<endl
cout<<"系统将自动返回功能界面..."<<endl
break
}
}
Sleep(2000)
jiemian()
}
void Manager::search(){
int i, j, a = 0, b
char k
cout<<"1.按车辆制造公司查询"<<endl
cout<<"2.按编号查询"<<endl
cout<<"3.按类别查询"<<endl
cout<<"请输入你的选项:(1-3)"<<endl
cin>>i
switch(i){
case 1:
char m[20]
cout<<"请输入需查询车辆的制造公司:"<<endl
cin>>m
for(j = 0j <topj++){
if(strcmp(car[j].made, m) == 0){
cout<<"车辆编号:"<<car[j].num<<""<<"车牌号:"<<car[j].pnum<<"
"<<"车辆制造公司:"<<car[j].made<<""<<"车辆购买时间:"<<car[j].year<<"
"<<"车辆型号:"<<car[j].type<<""<<"总公里数:"<<car[j].km<<"
"
if(car[j].type == 'B'|| car[j].type == 'b')
cout<<"载客量:"<<people[j]<<""<<"基本费用:"<<car[j].cost<<endl
else if(car[j].type == 'C'|| car[j].type == 'c')
cout<<"车厢数:"<<coach[j]<<""<<"基本费用:"<<car[j].cost<<endl
else
cout<<"载重量:"<<weight[j]<<""<<"基本费用:"<<car[j].cost<<endl
a++
}
}
if(a == 0)
cout<<"该车辆制造公司不存在!"<<endl
else{
cout<<"是否进行修改?(Y-是,N-否)"<<endl
cin>>k
if(k == 'Y' || k == 'y')
edit()
}
break
case 2:
int n
cout<<"请输入需查询的车辆编号:"<<endl
cin>>n
for( j = 0j <topj++){
if(car[j].num == n){
cout<<"车辆编号:"<<car[j].num<<""<<"车牌号:"<<car[j].pnum<<"
"<<"车辆制造公司:"<<car[j].made<<""<<"车辆购买时间:"<<car[j].year<<"
"<<"车辆型号:"<<car[j].type<<""<<"总公里数:"<<car[j].km<<"
"
if(car[j].type == 'B'|| car[j].type == 'b')
cout<<"载客量:"<<people[j]<<""<<"基本费用:"<<car[j].cost<<endl
else if(car[j].type == 'C'|| car[j].type == 'c')
cout<<"车厢数:"<<coach[j]<<""<<"基本费用:"<<car[j].cost<<endl
else
cout<<"载重量:"<<weight[j]<<""<<"基本费用:"<<car[j].cost<<endl
a++
}
}
if(a == 0)
cout<<"该车辆编号不存在!"<<endl
else{
cout<<"是否进行修改?(Y-是,N-否)"<<endl
cin>>k
if(k == 'Y' || k == 'y')
edit()
}
break
case 3:
char t
cout<<"请输入需查询的车辆型号:(B-大客车,C-小轿车,L-卡车)"<<endl
cin>>t
for(j = 0j <topj++){
if(car[j].type == t){
cout<<"车辆编号:"<<car[j].num<<""<<"车牌号:"<<car[j].pnum<<"
"<<"车辆制造公司:"<<car[j].made<<""<<"车辆购买时间:"<<car[j].year<<"
"<<"车辆型号:"<<car[j].type<<""<<"总公里数:"<<car[j].km<<"
"
if(car[j].type == 'B'|| car[j].type == 'b')
cout<<"载客量:"<<people[j]<<""<<"基本费用:"<<car[j].cost<<endl
else if(car[j].type == 'C'|| car[j].type == 'c')
cout<<"车厢数:"<<coach[j]<<""<<"基本费用:"<<car[j].cost<<endl
else
cout<<"载重量:"<<weight[j]<<""<<"基本费用:"<<car[j].cost<<endl
a++
}
}
if(a == 0){
cout<<"该车辆型号不存在!"<<endl
}
else{
cout<<"是否进行修改?(Y-是,N-否)"<<endl
cin>>k
if(k == 'Y' || k == 'y')
edit()
}
break
default:
cout<<"输入有误!"<<endl
break
}
// Sleep(2000)
cout<<"按1返回主界面:"<<endl
cin>>b
if(b == 1)
jiemian()
else{
cout<<"输入有误,系统将退出..."<<endl
Sleep(3000)
return
}
}
void Manager::show(){
int i
if(top != 0){
cout<<"当前车库中的所有车辆信息为:"<<endl
for(int j = 0j <topj++){
cout<<"车辆编号:"<<car[j].num<<""<<"车牌号:"<<car[j].pnum<<"
"<<"车辆制造公司:"<<car[j].made<<""<<"车辆购买时间:"<<car[j].year<<"
"<<"车辆型号:"<<car[j].type<<""<<"总公里数:"<<car[j].km<<"
"
if(car[j].type == 'B'|| car[j].type == 'b')
cout<<"载客量:"<<people[j]<<""<<"基本费用:"<<car[j].cost<<endl
else if(car[j].type == 'C'|| car[j].type == 'c')
cout<<"车厢数:"<<coach[j]<<""<<"基本费用:"<<car[j].cost<<endl
else
cout<<"载重量:"<<weight[j]<<""<<"基本费用:"<<car[j].cost<<endl
}
}
else
cout<<"车辆库为空!"<<endl
cout<<"按1返回主界面:"<<endl
cin>>i
if(i == 1)
jiemian()
else{
cout<<"输入有误,系统将退出..."<<endl
Sleep(3000)
return
}
}
void Manager::edit(){
int i, j, a = 0
char m[20]
cout<<"请依次输入需要修改的车辆信息:"<<endl
while(1){
cout<<"车辆编号:"
cin>>i
for(j = 0j <topj++){
if(car[j].num == i){
cout<<"车牌号:"
cin>>car[j].pnum
cout<<"车辆制造公司:"
cin>>m
strcpy(car[j].made, m)
cout<<"购买时间:"
cin>>car[j].year
cout<<"车辆型号(B-大客车,C-小轿车,L-卡车):"
cin>>car[j].type
cout<<"总公里数:"
cin>>car[j].km
if(car[j].type == 'B'||car[j].type == 'b'){
cout<<"载客量:"
cin>>people[j]
}
else if(car[j].type == 'C'||car[j].type == 'c'){
cout<<"车厢数:"
cin>>coach[j]
}
else{
cout<<"载重量:"
cin>>weight[j]
}
a++
}
}
if(a == 0)
cout<<"此编号不存在,不能进行修改,请重新输入!"<<endl
if(a != 0){
cout<<"修改成功!系统将返回主界面..."<<endl
break
}
}
Sleep(1500)
jiemian()
}
void Manager::delet(){
int i, a = 0
while(1){
if(top == 0){
cout<<"车辆信息库为空!系统将返回功能界面..."<<endl
break
}
else{
cout<<"请输入需要删除的车辆编号:"
cin>>i
for(int j = 0j <topj++){
if(car[j].num == i){//车辆编号存在
if(car[top - 1].type == 'B'|| car[top - 1].type == 'b'){
people[j] = people[top - 1]
car[j].cost = 2000
}
else if(car[top - 1].type == 'C'|| car[top - 1].type == 'c'){
coach[j] = coach[top - 1]
car[j].cost = 1000
}
else{
weight[j] = weight[top - 1]
car[j].cost = 1500
}
car[j].num = car[top - 1].num
car[j].pnum = car[top - 1].pnum
strcpy(car[j].made, car[top - 1].made)
car[j].year = car[top - 1].year
car[j].type = car[top - 1].type
car[j].km = car[top - 1].km
top--
a++
}
}
if(a == 0)
cout<<"此编号不存在,不能进行删除,请重新输入!"<<endl
else{
cout<<"删除成功!系统将返回功能界面..."<<endl
break
}
}
}
Sleep(1500)
jiemian()
}
void Manager::sum(){
if(top != 0){
int j, b = 0, c = 0, l = 0
cout<<"当前车辆信息库中总车辆数为:"<<top<<"辆"<<endl
for(j = 0j <topj++){
if(car[j].type == 'B'|| car[j].type == 'b')
b++//统计大客车的数量
else if(car[j].type == 'C'|| car[j].type == 'c')
c++//统计小轿车的数量
else
l++//统计卡车的数量
}
cout<<"各型号车辆数为:"<<endl
cout<<"大客车:"<<b<<"辆"<<""<<"小轿车:"<<c<<"辆"<<"
"<<"卡车:"<<l<<"辆"<<endl
}
else
cout<<"车库信息为空!"<<endl
cout<<"系统将返回主界面..."<<endl
Sleep(5000)
jiemian()
}
void Manager::write(){
ofstream write("a.txt")
for(int i = 0i <topi++){
write<<"车辆编号:"<<car[i].num<<""
write<<"车牌号:"<<car[i].pnum<<""
write<<"车辆制造公司:"<<car[i].made<<""
write<<"车辆购买时间:"<<car[i].year<<""
write<<"车辆型号:"<<car[i].type<<""
write<<"总公里数:"<<car[i].km<<""
write<<"基本维护费用:"<<car[i].cost<<""
if(car[i].type == 'B'|| car[i].type == 'b')
write<<"载客量:"<<people[i]<<endl
else if(car[i].type == 'C'|| car[i].type == 'c')
write<<"车厢数:"<<coach[i]<<endl
else
write<<"载重量:"<<weight[i]<<endl
}
write.close()
cout<<"车辆信息已成功写入同目录下的a.txt文件中!系统将返回主界面..."<<endl
Sleep(3000)
jiemian()
}
void Manager::read(){
ifstream read("b.txt")
while(!read.eof()){
read>>car[top].num>>car[top].pnum>>car[top].made>>car[top].year>>car[top].type>>car[top].km>>car[top].cost
if(car[top].type == 'B'|| car[top].type == 'b')
read>>people[top]
else if(car[top].type == 'C'|| car[top].type == 'c')
read>>coach[top]
else
read>>weight[top]
top++
}
read.close()
cout<<"读取同目录下的b.txt文件成功!系统将返回主界面..."<<endl
Sleep(3000)
jiemian()
}
void Manager::jiemian(){
system("cls")
int i
cout<<"***********************************"<<endl
cout<<"*欢迎进入车辆管理系统 *"<<endl
cout<<"*1.添加车辆 *"<<endl
cout<<"*2.查询车辆 *"<<endl
cout<<"*3.显示车辆 *"<<endl
cout<<"*4.编辑车辆 *"<<endl
cout<<"*5.删除车辆 *"<<endl
cout<<"*6.统计车辆 *"<<endl
cout<<"*7.存储车辆 *"<<endl
cout<<"*8.读取车辆 *"<<endl
cout<<"*0.退出系统 *"<<endl
cout<<"***********************************"<<endl
cout<<"请输入你需要 *** 作的选项:(0-8)"<<endl
cin>>i
switch(i){
case 1:
add()
break
case 2:
search()
break
case 3:
show()
break
case 4:
edit()
break
case 5:
delet()
break
case 6:
sum()
break
case 7:
write()
break
case 8:
read()
break
case 0:
return
default:
cout<<"输入有误!系统将退出..."<<endl
return
}
}
void main(){
Manager a
a.jiemian()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)