用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c++代码库

汽车管理系统

2014-07-04 作者: 云代码会员举报

[c++]代码库

#include<conio.h>
#include<Windows.h>
#include<fstream>
#include<iomanip>
#include<iostream>
using namespace std;
vector<car> iver;
void System::ini_interface(){
	for (int i = 0; i < 10;i++){
		cout << "            *************************************          " << endl; cout << endl;
		cout << "                 欢        迎      光        临            " << endl; cout << endl;
		cout << "              大    众  4 S 店 天 津 分 店                 " << endl;
		cout << "                                                           " << endl;
		cout << "             请 按 任 意 键 进 入 店 铺 !!!!!         " << endl; cout << endl;
		cout << "              您 将 在" << 10 - i << "秒 后 自 动 进 入 店 铺     " << endl; cout << endl;
		cout << "            *************************************          " << endl;
		Sleep(1000);
		char keydown = 0;
		if (_kbhit()){
			_getch(); keydown = 1;
		}
		if (keydown){ i = 50; }
		system("cls");
	}
}
void System::list(){
	system("cls");
	char temp;
	if (power == '1'){
		cout << "                当前权限为:管理员权限    可使用所有功能。" << endl;
	}
	else
	{
		cout << "               当前权限为:普通权限     只能使用功能1,3,5,9." << endl;
	}
	cout << endl; cout << endl;
	cout << "              #************************************************************#" << endl;
	cout << "              #*                                                          *#" << endl;
	cout << "              #*  1:更改权限         2:信息录入           3:信息浏览      *#" << endl;
	cout << "              #*                                                          *#" << endl;
	cout << "              #*  4:信息修改         5:信息查询           6:信息删除      *#" << endl;
	cout << "              #*                                                          *#" << endl;
	cout << "              #*  7:保存信息         8:读取信息           9:退出程序      *#" << endl;
	cout << "              #*                                                          *#" << endl;
	cout << "              #************************************************************#" << endl;
	temp = _getch();
	switch (temp)
	{
	case'1':get_power(); break;
	case'2':input_information(); break;
	case'3':look_information(); break;
	case'4':alter(); break;
	case'5':refer(); break;
	case'6':remove(); break;
	case'7':output_file(); break;
	case'8':input_file(); break;
	case'9':drop_out(); break;
	default:cout << "请输入正确的序号!!" << endl; break;
	}
}
void System::get_power(){
	char temp;
	system("cls");
	while (1){
		cout << "请选择您的权限:" << endl;
		cout << "1:管理员权限。" << endl;
		cout << "2:普通权限。" << endl;
		cout << "请输入序号:" << "   ";
		temp = _getch();
		switch (temp){
		case'1':return get_password(); break;
		case'2':return list(); break;
		default:{
			system("cls");
			cout << "请选择正确的序号!" << endl;
			Sleep(500);
			system("cls");
		   }
		}
	}
}
void System::get_password(){
	system("cls");
	string temp;
	char number;
		cout << "请输入管理员密码:" << endl;
		cin >> temp;
	if (temp != password){
			system("cls");
			cout << "密码错误!" << endl;
			cout << "1:重新输入密码。" << endl;
			cout << "2:返回。" << endl;
			number = _getch();
			switch (number)
			{
			case'1':get_password(); break;
			case'2':get_power(); break;
			}
		}
	else
	{
		power ='1';
		return list();
	}
}
void System::input_information(){
	system("cls");
	if (power == '1'){
		car x;
		char temp;
		cout << "请依次输入汽车信息:1.类别(面包车,轿车,越野车)     2.ID            3.名字   " << endl;
		cout << "                   4.上市时间                        5.购买价格      6.出售价格" << endl;
		cout << "                   7.颜色                            8.厂商          9.发动机    " << endl;
		cout << "                   10.车身结构(如4门5座3车厢)  " << endl;
		cin >> x.type >> x.ID >> x.name >> x.date >> x.get_price >> x.sale_price;
		cin >> x.color >> x.factory >> x.engine >> x.structure;
		for (vector<car>::iterator iter = iver.begin(); iter != iver.end(); ++iter){
			if (x.ID == iter->ID){
				cout << "ID重复!!!!信息存储失败!!!   1(重新输入)  2(返回菜单)";
				temp = _getch();
				if (temp == '1')input_information();
				else if (temp == '2')list();
				else{
					cout << "请输入正确序号!!!!" << endl; Sleep(500);
					system("cls");
					list();
				}
			}
		}
		iver.push_back(x);
		++s;
		return list();
	}
	else
	{
		system("cls");
		cout << "无此功能权限,系统将在一秒后返回菜单页面" << endl;
		Sleep(1000);
		system("cls");
		return list();
	}
}
void System::look_information(){
	if (iver.size() == 0){
		system("cls");
		cout << "目前无任何信息!!!系统将在1秒后返回。。。" << endl;
		Sleep(1000);
		return list();
	}
	else{
		system("cls");
		for (vector<car>::iterator iter = iver.begin(); iter != iver.end(); ++iter){
			
			cout << setw(9) << "类别:" << setw(15) << iter->type << setw(15) << "ID:" << setw(15) << iter->ID << endl;
			cout << setw(9) << "名字:" << setw(15) << iter->name << setw(15) << "厂商:" << setw(15) << iter->factory << endl;
			cout << setw(4) << "上市时间:" << setw(15) << iter->date << setw(15) << "购买价格:" << setw(15) << iter->get_price << setw(10) << endl;
			cout << setw(4) << "车身结构:" << setw(15) << iter->structure << setw(15)<<"出售价格:" << setw(15) << iter->sale_price << endl;
			cout << setw(9) << "发动机:" << setw(15) << iter->engine << setw(15) << "颜色:" << setw(15) << iter->color << endl;
			cout << endl; cout << endl;
		}
		cout << "按任意键返回" << endl;
		_getch();
		return list();
	}
}
void System::refer(){
	system("cls");
	sort();
	char temp2;
	string temp1, temp3;
	int number = 0;
	system("cls");
	cout << "1:按汽车名字查询" << endl;
	cout << "2:按汽车类别查询" << endl;
	cout << "3:退       出   " << endl;
	temp2 = _getch();
	if (temp2 == '3'){ return list(); }
	else if (temp2 == '1'){
		system("cls");
		cout << "                      请输入需要查询的汽车名字" << endl;
		cin >> temp1;
		for (vector<car>::iterator iter = iver.begin(); iter != iver.end(); ++iter){
			if (iter->name == temp1){
				system("cls");
				cout << "类别:" << iter->type << "         ID:" << iter->ID << "         名字" << iter->name << endl;
				cout << "上市时间:" << iter->date << "       购买价格:" << iter->get_price << "        出售价格:" << iter->sale_price << endl;
				cout << "颜色:" << iter->color << "       厂商:" << iter->factory << "        发动机" << iter->engine << endl;
				cout << "车身结构:" << iter->structure << endl;
				cout << endl; cout << endl;
				++number;
			}
		}
	}
	else if (temp2 == '2'){
		system("cls");
		cout << "                       请输入需要查询的汽车类别" << endl;
		cin >> temp3;
		for (vector<car>::iterator iter = iver.begin(); iter != iver.end(); ++iter){
			if (iter->type == temp3){
				system("cls");
				cout << "类别:" << iter->type << "         ID:" << iter->ID << "         名字" << iter->name << endl;
				cout << "上市时间:" << iter->date << "       购买价格:" << iter->get_price << "        出售价格:" << iter->sale_price << endl;
				cout << "颜色:" << iter->color << "       厂商:" << iter->factory << "        发动机" << iter->engine << endl;
				cout << "车身结构:" << iter->structure << endl;
				cout << endl; cout << endl;
				++number;
			}
		}
	}
	else {
		cout << "请输入正确的序号!!!!" << endl;
		Sleep(500);
		refer();
	}
	if (number == 0){ cout << "无符合要求的汽车!!!!" << endl; }
	cout << "按任意键返回" << endl;
	_getch();
	return list();
}
void System::sort(){
	char temp, temp1;
	cout << "1:按名称排序" << endl;
	cout << "2:按ID排序" << endl;
	temp = _getch();
	if (temp = '1'){
		car x;
		for (vector<car>::size_type i = 0; i < iver.size(); ++i){
			for (vector<car>::size_type j = i + 1; j < iver.size(); ++j){
				if (iver[i].name == iver[j].name){ x = iver[i]; iver[i] = iver[j]; iver[j] = x; break; }
			}
		}
		if (temp = '2'){
			system("cls");
			cout << "1:按ID从小到大排列" << endl;
			cout << "2:按ID从大到小排列" << endl;
			temp1 = _getch();
			car x;
			for (vector<car>::size_type i = 0; i < iver.size(); ++i){
				for (vector<car>::size_type j = i; j < iver.size(); ++j){
					if (temp == '1'){ if (iver[i].ID>iver[j].ID){ x = iver[i]; iver[i] = iver[j]; iver[j] = x; } }
					if (temp == '2'){ if (iver[i].ID<iver[j].ID){ x = iver[i]; iver[i] = iver[j]; iver[j] = x; } }
				}
			}
		}
	}
}
void System::alter(){
	system("cls");
	if (power == '1'){
		string id;
			int number = 0;
		vector<car>::iterator iter;
		cout << "请输入修改的汽车ID:" << endl;
		cin >> id;
		for (iter = iver.begin(); iter != iver.end(); ++iter){
			if (id == iter->ID){ ++number; break; }
		}
		if (number == 0){
			cout << "无此ID!!!";
			Sleep(1000);
			system("cls");
			return list();
		}
		else
		{
			char m;
			cout << "请选择需要修改的数据:" << endl;
			cout << "1:类别      2:名字    3:上市时间      4:购买价格      5:出售价格" << endl;
			cout << "6:颜色      7:厂商    8:发动机        9:车身结构      10:ID" << endl;
			m = _getch();
			cout << "请输入需要修改的数据。" << endl;
			switch (m)
			{
			case'1':cin >> iter->type; break;
			case'2':cin >> iter->name; break;
			case'3':cin >> iter->date; break;
			case'4':cin >> iter->get_price; break;
			case'5':cin >> iter->sale_price; break;
			case'6':cin >> iter->color; break;
			case'7':cin >> iter->factory; break;
			case'8':cin >> iter->engine; break;
			case'9':cin >> iter->structure; break;
			case'10':cin >> iter->ID; break;
			default:cout << "请输入正确序号!!!即将返回菜单页面...."; break;
			}
			Sleep(1000);
			system("cls");
			return list();
		}
	}
	else
	{
		system("cls");
		cout << "无此功能权限,系统将在一秒后返回菜单页面" << endl;
		Sleep(1000);
		system("cls");
		return list();
	}
}
void System::remove(){
	system("cls");
	if (power == '1'){
		string id;
		int number = 0;;
		cout << "请输入所要删除的汽车信息的ID号" << endl;
		cin >> id;
		vector<car>::iterator iter;
		for (iter = iver.begin(); iter != iver.end(); ++iter){
			if (id == iter->ID){
				++number;
				iver.erase(iter);
				break;
			}
		}
		if (number == 0){ cout << "无此ID,即将返回菜单页面!!"; return list(); }
	}
	else
	{
		system("cls");
		cout << "无此功能权限,系统将在一秒后返回菜单页面" << endl;
		Sleep(1000);
		return list();
	}
}
void System::drop_out(){
	drop = 0;
}
int System::get_drop(){ 
	return drop;
}
void System::input_file(){
	if (power == '1'){
		ifstream infile("t.dat", ios::binary);
		infile.read((char*)&s, sizeof(s));
		int b = 100;
		car a[100];
		for (vector<car>::size_type ix = 0; ix != s; ++ix){
			infile.read((char*)&a[ix], sizeof(a[ix]));
			iver.push_back(a[ix]);
		}
		infile.close();
		cout << "读取成功!!" << endl;
		Sleep(500);
		return list();
	}
	else
	{
		system("cls");
		cout << "无此功能权限,系统将在一秒后返回菜单页面" << endl;
		Sleep(1000);
		return list();
	}
}
void System::output_file(){
	if (power == '1'){
		ofstream outfile("t.dat", ios::binary);
		outfile.write((char*)&s, sizeof(s));
		for (vector<car>::size_type ix = 0; ix != iver.size(); ++ix){
				outfile.write((char*)&iver[ix], sizeof(iver[ix]));
			}
			outfile.close();
			cout << "保存成功!!!" << endl;
			Sleep(500);
			return list();
	}
	else
	{
		system("cls");
		cout << "无此功能权限,系统将在一秒后返回菜单页面" << endl;
		Sleep(1000);
		return list();
	}
}


网友评论    (发表评论)

共4 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...