C++汽车销售管理系统

开发背景      

      随着现代科学技术的迅猛发展,计算机技术已经渗透到各个领域,成为各行业必不可少的工具,特别是Internet技术的推广和信息高速公路的建立,使IT产业在市场竞争中越发显示出其独特的优势,步入信息化时代,有巨大的数据信息等待加工处理和传输,这使得对数据库的进一步开发和利用显得尤为迫切。汽车工业经历了一百多年的发展历史,对国家经济的发展和腾飞以及对人类社会的文明带来了巨大影响。在许多国家,汽车工业已成为支柱产业,随着人们生活水平以及性能的不断提高,人们对汽车的消费和需求也越来越旺盛,世界汽车工业也保持庞大的市场需求和生产规模。

                                              题目:完成以下图片的基本要求

C++汽车销售管理系统_第1张图片

#include
#include"string"
#include
#include 
#include 
#include
#include
//N最大汽车数量
#define N 50
//f作为开关
int f = 0; 
using namespace std;
//p作为接收菜单选项的字符串
string p; 


//显示菜单
void menu(); 
class sale_car
{
public:
	sale_car() {}
	//显示汽车信息
	void show(); 
	~sale_car() {}
	friend class Sale_carList;
private:
	string num, name, dorm, uptown, address, distance;
	int grade ;
};


class Sale_carList 
{
private:
	sale_car w[N];
	//计算汽车数量
	int NUM; 
	//用来暂时记录当前操作汽车
	int count;
public:
	//汽车信息录入
	void add(); 
	//汽车信息排序
	void sort(); 
	//汽车信息查找
	void search(); 
	//汽车信息删除
	void dele(); 
	//汽车信息修改
	void modify(); 
	//汽车信息以文件保存
	void save(); 
	//显示汽车信息在屏幕上
	void load();
	void showsale_car();
	Sale_carList() {
		NUM = 0;
		count = 0;
	}
};


void menu() //显示菜单
{
	cout << endl;
	cout << "********************************************************" << endl;
	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 << "*******************************************************" << endl;
	cout << endl;
}

void domain() //主菜单函数实现
{

	Sale_carList wl;
	while (1)
	{
		system("cls");
		menu();
		cout << "请选择数字编号0~8" << endl;
		int i1;
		cin >> i1;
		while (!(i1 >= 0 && i1 <= 8))
		{
			cout << "输入有误,请重新输入:" << endl;
			cin >> i1;
		}
		switch (i1)
		{
		case 1:wl.add(); break;
		case 2:wl.modify(); break;
		case 3:wl.dele(); break;
		case 4:wl.sort(); break;
		case 5:wl.search(); break;
		case 6:wl.showsale_car(); break;
		case 7:wl.save(); break;
		case 8:wl.load(); break;
		case 0:cout << "系统退出!!" << endl;
			exit(0);
		default:
			break;
		}
		cout << "是否返回主菜单? Y/N" << endl;
		cin >> p;
		if (p == "n" || p == "N")
		{
			cout << "系统退出!!" << endl;
			exit(0);
		}
	}
}

//汽车信息添加函数实现
void Sale_carList::add()
{
	cout << "请输入汽车信息:" << endl;

	cout << "车号:";
	string num;
	cin >> num;
	for (int i = 0; i < NUM; i++)
		while (num == w[i].num)
		{
			cout << "此汽车类型已存在,请重新输入:" << endl; break;
			cout << "车号:";
			cin >> num;
		}
	w[NUM].num = num;
	cout << "车名:"; cin >> w[NUM].name;
	cout << "突破100km/小时时间:"; cin >> w[NUM].dorm;
	cout << "颜色:"; cin >> w[NUM].uptown;
	cout << "购买年份:"; cin >> w[NUM].grade;
	cout << "自动挡还是手动挡:"; cin >> w[NUM].distance;
	cout << "售价:"; cin >> w[NUM].address;
	++NUM;
	count = NUM;
}

void sale_car::show() //汽车信息显示函数实现
{
	cout << "车号:" << num << endl;
	cout << "车名:" << name << endl;
	cout << "突破100km/小时时间:" << dorm << endl;
	cout << "颜色:" << uptown << endl;
	cout << "购买年份:" << grade << endl;
	cout << "自动挡还是手动挡:" << distance << endl;
	cout << "售价:" << address << endl;

	cout << endl;
}

//汽车信息修改函数实现
void Sale_carList::modify()
{
	if (NUM <= 0)
	{
		cout << "没有汽车信息存入,系统将返回主菜单" << endl;
		menu();
	}
	cout << "请输入需要修改信息汽车的车号:" << endl;
	string num1;
	cin >> num1;
	int j = 0, k;
	int flag = 1;
	while (flag)
	{
		for (; j < count; j++)
		{
			if (num1 == w[j].num)
			{
				flag = 0;
				k = j;
				break;
			}
		}
		if (flag)
		{
			cout << "不存在此车,请重新输入:" << endl;
			j = 0;
			cin >> num1;
		}
	}
	cout << "你选择的汽车的信息为:" << endl;
	cout << " 车号:" << w[k].num << endl;
	cout << " 车名:" << w[k].name << endl;
	cout << " 突破100km/小时时间:" << w[k].dorm << endl;
	cout << " 颜色:" << w[k].uptown << endl;
	cout << " 购买年份:" << w[k].grade << endl;
	cout << " 自动挡还是手动挡:" << w[k].distance << endl;
	cout << " 售价:" << w[k].address << endl;

	cout << endl;
	cout << "***********************************************" << endl;
	cout << "** 1.修改车号 **" << endl;
	cout << "** 2.修改车名 **" << endl;
	cout << "** 3.修改突破100km/小时时间 **" << endl;
	cout << "** 4.修改颜色 **" << endl;
	cout << "** 5.修改购买年份**" << endl;
	cout << "** 6.修改自动挡还是手动挡 **" << endl;
	cout << "** 7.修改售价 **" << endl;
	cout << "** 0.返回主菜单 **" << endl;
	cout << "***********************************************" << endl;
	cout << endl;
	cout << "请选择数字编号0~7" << endl;
	int i3;
	cin >> i3;
	while (i3 < 0 || i3>8)
	{
		cout << "输入有误,请重新输入:" << endl;
		cin >> i3;
	}
	switch (i3)
	{
	case 1:
		cout << "请输入新的汽车车号:";
		cin >> w[k].num;
		cout << "修改信息已保存,现返回主菜单:" << endl;
		menu();
		break;
	case 2:
		cout << "请输入新的汽车车名:";
		cin >> w[k].name;
		cout << "修改信息已保存,现返回主菜单:" << endl;
		menu();
		break;
	case 3:
		cout << "请输入新的突破100km/小时时间:";
		cin >> w[k].dorm;
		cout << "修改信息已保存,现返回主菜单:" << endl;
		menu();
		break;
	case 4:
		cout << "请输入新的汽车颜色:";
		cin >> w[k].uptown;
		cout << "修改信息已保存,现返回主菜单:" << endl;
		menu();
		break;
	case 5:
		cout << "请输入新的汽车购买年份:";
		cin >> w[k].grade;
		cout << "修改信息已保存,现返回主菜单:" << endl;
		menu();
		break;
	case 6:
		cout << "请输入新的汽车是自动挡还是手动挡:";
		cin >> w[k].distance;
		cout << "修改信息已保存,现返回主菜单:" << endl;
		menu();
		break;
	case 7:
		cout << "请输入新的汽车售价:";
		cin >> w[k].address;
		cout << "修改信息已保存,现返回主菜单:" << endl;
		menu();
		break;
		cout << "修改信息已保存,现返回主菜单:" << endl;
		menu();
		break;
	case 0:
		menu();
	default:
		break;
	}
}

//汽车信息显示函数实现
void Sale_carList::showsale_car()
{
	if (NUM <= 0)
	{
		cout << "没有汽车信息存入,系统将返回主菜单" << endl;
		menu();
	}
	else
		cout << "已保存的汽车信息如下:" << endl;
	for (int i = 0; i < count; i++)
	{
	cout << " 车号:" << w[i].num << endl;
	cout << " 车名:" << w[i].name << endl;
	cout << " 突破100km/小时时间:" << w[i].dorm << endl;
	cout << " 颜色:" << w[i].uptown << endl;
	cout << " 购买年份:" << w[i].grade << endl;
	cout << " 自动挡还是手动挡:" << w[i].distance << endl;
	cout << " 售价:" << w[i].address << endl;

	cout << "***********************************************" << endl;
	}
}





//汽车信息查询函数实现
void Sale_carList::search()
{
	if (NUM <= 0)
	{
		cout << "没有汽车信息存入,系统将返回主菜单" << endl;
		menu();
	}
	else
		cout << "***********************************************" << endl;
	cout << "** 请选择查找方式: **" << endl;
	cout << "** 1.按车号查找 **" << endl;
	cout << "** 2.按车名查找 **" << endl;
	cout << "** 3.按突破100km/小时时间**" << endl;
	cout << "** 0.返回主菜单 **" << endl;
	cout << "***********************************************" << endl;
	cout << endl;
	cout << "请选择数字编号0~3" << endl;
	int i4;
	cin >> i4;
	while (i4 < 0 || i4>3)
	{
		cout << "输入有误,请重新输入:" << endl;
		cin >> i4;
	}
	if (i4 == 1)
	{
		string num2;
		cout << "请输入要查询的汽车的车号:" << endl;
		cin >> num2;
		int j = 0, k;
		int flag = 1;
		while (flag)
		{
			for (; j < count; j++)
			{
				if (num2 == w[j].num)
				{
					flag = 0;
					k = j;
					cout << "查询的汽车信息如下:" << endl;
					cout <> name2;
		int j2 = 0, k2;
		int flag2 = 1;
		while (flag2)
		{
			for (; j2 < count; j2++)
			{
				if (name2 == w[j2].name)
				{
					flag2 = 0;
					k2 = j2;
					cout << setw(10) << std::left << "查询的汽车信息如下:" << endl;
					cout << setw(10) << std::left << " 车号:" << w[k2].num << " ";
					cout << setw(10) << std::left << " 车名:" << w[k2].name << " ";
					cout << setw(10) << std::left << " 突破100km/小时时间:" << w[k2].dorm << " ";
					cout << setw(10) << std::left << " 颜色:" << w[k2].uptown << " ";
					cout << setw(10) << std::left << " 购买年份:" << w[k2].grade << " ";
					cout << setw(10) << std::left << " 自动挡还是手动挡:" << w[k2].distance << " ";
					cout << setw(10) << std::left << " 售价:" << w[k2].address << " ";
					break;
				}
			}
			if (flag2)
			{
				flag2 = 0;
				cout << "不存在此车型!!\n返回主菜单" << endl;
				break;
			}
		}

	}
	else if (i4 == 3)
	{
		string dorm2;
		cout << "请输入要查询的汽车突破100km/小时时间:" << endl;
		cin >> dorm2;
		int j4 = 0, k4;
		int flag4 = 1;
		while (flag4)
		{
			for (; j4 < count; j4++)
			{
				if (dorm2 == w[j4].uptown)
				{
					flag4 = 0;
					k4 = j4;
					cout << setw(10) << std::left << "查询的汽车信息如下:" << endl;
					cout << setw(10) << std::left << " 车号:" << w[k4].num << " ";
					cout << setw(10) << std::left << " 车名:" << w[k4].name << " ";
					cout << setw(10) << std::left << " 突破100km/小时时间:" << w[k4].dorm << " ";
					cout << setw(10) << std::left << " 颜色:" << w[k4].uptown << " ";
					cout << setw(10) << std::left << " 购买年份:" << w[k4].grade << " ";
					cout << setw(10) << std::left << " 自动挡还是手动挡:" << w[k4].distance << " ";
					cout << setw(10) << std::left << " 售价:" << w[k4].address << " ";
					break;
				}
			}
			if (flag4)
			{
				flag4 = 0;
				cout << "不存在此车型!!\n返回主菜单" << endl;
				break;
			}
		}

	}
	else if (i4 == 0)
		menu();
}

//汽车信息排序功能实现
void Sale_carList::sort()
{
	if (NUM <= 0)
	{
		cout << "没有汽车信息存入,系统将返回主菜单" << endl;
		menu();
	}
	else
	cout << "***************************************************" << endl;
	cout << "**                 请选择排序方式:              **" << endl;
	cout << "** 1.按突破100km/小时时间排序(升序)            **" << endl;
	cout << "** 2.按突破100km/小时时间排序(降序)            **" << endl;
	cout << "** 3.按车号排序(升序)                          **" << endl;
	cout << "** 4.按车号排序(降序)                          **" << endl;
	cout << "** 5.按售价排序(升序)                          **" << endl;
	cout << "** 6.按售价排序(降序)                          **" << endl;
	cout << "** 0.返回主菜单                                  **" << endl;
	cout << "***************************************************" << endl;
	cout << endl;
	cout << "请选择数字编号0~6" << endl;
	int i5;
	cin >> i5;
	while (i5 < 0 || i5>6)
	{
		cout << "输入有误,请重新输入:" << endl;
		cin >> i5;
	}
	if (i5 == 1)
	{
		for (int i = 0; i < count - 1; i++)
			for (int j = 0; j < count - i - 1; j++)
				if (w[j].dorm > w[j + 1].dorm)
				{
					sale_car temp;
					temp = w[j];
					w[j] = w[j + 1];
					w[j + 1] = temp;
				}
		cout << "按突破100km/小时时间升序后的信息如下:" << endl;
		cout << "查询的汽车信息如下:" << endl;
		cout << "车号:" << " \t车名" << " \t突破100km / 小时时间" << " \t颜色" << "\t 购买年份" << " \t自动挡还是手动挡" << " \t售价" << endl;
		for (int i = 0; i < count; i++)
		{
			
			cout << w[i].num<<"\t" << w[i].name << "\t" << w[i].dorm << "\t\t\t" << w[i].uptown << "\t" << w[i].grade << "\t\t  " << w[i].distance << "\t\t" << w[i].address << endl;
		} 
	}
	else if (i5 == 2)
	{
		for (int i = 0; i < count - 1; i++)
			for (int j = 0; j < count - i - 1; j++)
				if (w[j].dorm < w[j + 1].dorm)
				{
					sale_car temp;
					temp = w[j];
					w[j] = w[j + 1];
					w[j + 1] = temp;
				}
		cout << "按突破100km/小时时间降序后的信息如下:" << endl;
		cout << "查询的汽车信息如下:" << endl;
		cout << "车号:" << " \t车名" << " \t突破100km / 小时时间" << " \t颜色" << "\t 购买年份" << " \t自动挡还是手动挡" << " \t售价" << endl;
		for (int i = 0; i < count; i++)
		{
			
			cout << w[i].num << "\t" << w[i].name << "\t" << w[i].dorm << "\t\t\t" << w[i].uptown << "\t" << w[i].grade << "\t\t  " << w[i].distance << "\t\t" << w[i].address << endl;
		}
	}
	else if (i5 == 3)
	{
		for (int i = 0; i < count - 1; i++)
			for (int j = 0; j < count - i - 1; j++)
				if (w[j].num > w[j + 1].num)
				{
					sale_car temp;
					temp = w[j];
					w[j] = w[j + 1];
					w[j + 1] = temp;
				}
		cout << "按车号升序后的信息如下:" << endl;
		cout << "查询的汽车信息如下:" << endl;
		cout << "车号:" << " \t车名" << " \t突破100km / 小时时间" << " \t颜色" << "\t 购买年份" << " \t自动挡还是手动挡" << " \t售价" << endl;
		for (int i = 0; i < count; i++)
		{
			
			cout << w[i].num << "\t" << w[i].name << "\t" << w[i].dorm << "\t\t\t" << w[i].uptown << "\t" << w[i].grade << "\t\t  " << w[i].distance << "\t\t" << w[i].address << endl;
		}
	}

	else if (i5 == 4)
	{
		for (int i = 0; i < count - 1; i++)
			for (int j = 0; j < count - i - 1; j++)
				if (w[j].num > w[j + 1].num)
				{
					sale_car temp;
					temp = w[j];
					w[j] = w[j + 1];
					w[j + 1] = temp;
				}
		cout << "按车号降序后的信息如下:" << endl;
		for (int i = 0; i < count; i++)
		{
			cout << "***********************************************" << endl;
			cout << setw(10) << std::left << " 车号:" << w[i].num << " ";
			cout << setw(10) << std::left << " 车名:" << w[i].name << " ";
			cout << setw(10) << std::left << " 突破100km/小时时间:" << w[i].dorm << " ";
			cout << setw(10) << std::left << " 颜色:" << w[i].uptown << " ";
			cout << setw(10) << std::left << " 购买年份:" << w[i].grade << " ";
			cout << setw(10) << std::left << " 自动挡还是手动挡:" << w[i].distance << " ";
			cout << setw(10) << std::left << " 售价:" << w[i].address << " ";
			cout << "***********************************************" << " ";
		}
	}

	else if (i5 == 5)
	{
	for (int i = 0; i < count - 1; i++)
		for (int j = 0; j < count - i - 1; j++)
			if (w[j].address > w[j + 1].address)
			{
				sale_car temp;
				temp = w[j];
				w[j] = w[j + 1];
				w[j + 1] = temp;
			}
	cout << "按售价升序后的信息如下:" << endl;
	for (int i = 0; i < count; i++)
	{
		cout << "***********************************************" << endl;
		cout << setw(10) << std::left << "车号:" << w[i].num << " ";
		cout << setw(10) << std::left << "车名:" << w[i].name << " ";
		cout << setw(10) << std::left << " 突破100km/小时时间:" << w[i].dorm << " ";
		cout << setw(10) << std::left <<" 颜色:" << w[i].uptown << " ";
		cout << setw(10) << std::left << " 购买年份:" << w[i].grade << " ";
		cout << setw(10) << std::left << " 自动挡还是手动挡:" << w[i].distance << " ";
		cout << setw(10) << std::left << " 售价:" << w[i].address << " ";
		cout << "***********************************************" << " ";
	}
	}

	else if (i5 == 6)
	{
	for (int i = 0; i < count - 1; i++)
		for (int j = 0; j < count - i - 1; j++)
			if (w[j].address > w[j + 1].address)
			{
				sale_car temp;
				temp = w[j];
				w[j] = w[j + 1];
				w[j + 1] = temp;
			}
	cout << "按售价降序后的信息如下:" << endl;
	for (int i = 0; i < count; i++)
	{
		cout << "***********************************************" << endl;
		cout << setw(10) << std::left << " 车号:" << w[i].num << " ";
		cout << setw(10) << std::left << " 车名:" << w[i].name << " ";
		cout << setw(10) << std::left << " 突破100km/小时时间:" << w[i].dorm << " ";
		cout << setw(10) << std::left << " 颜色:" << w[i].uptown << " ";
		cout << setw(10) << std::left << " 购买年份:" << w[i].grade << " ";
		cout << setw(10) << std::left << " 自动挡还是手动挡:" << w[i].distance << " ";
		cout << setw(10) << std::left << " 售价:" << w[i].address << " ";
		cout << "***********************************************" << " ";
	}
	}
	else if (i5 == 0)
	for (int i = 0; i < count; i++)
	{
		cout << "***********************************************" << endl;
		cout << setw(10) << std::left << " 车号:" << w[i].num << " ";
		cout << setw(10) << std::left << " 车名:" << w[i].name << " ";
		cout << setw(10) << std::left << " 突破100km/小时时间:" << w[i].dorm << " ";
		cout << setw(10) << std::left << " 颜色:" << w[i].uptown << " ";
		cout << setw(10) << std::left <<" 购买年份:" << w[i].grade << " ";
		cout << setw(10) << std::left << " 自动挡还是手动挡:" << w[i].distance << " ";
		cout << setw(10) << std::left << " 售价:" << w[i].address << " ";
		cout << "***********************************************" << " ";
	}
}

//汽车信息删除函数实现
void Sale_carList::dele()
{
	if (NUM <= 0)
	{
		cout << "没有汽车信息存入,系统将返回主菜单" << endl;
		menu();
	}
	cout << "请输入需要删除信息汽车的车号:" << endl;
	string num3;
	cin >> num3;
	int j = 0, k;
	int flag = 1;
	while (flag)
	{
		for (; j < count; j++)
		{
			if (num3 == w[j].num)
			{
				flag = 0;
				k = j;
				break;
			}
		}
		if (flag)
		{
			cout << "不存在此车型,请重新输入:" << endl;
			j = 0;
			cin >> num3;
		}
	}
	cout << "你选择的汽车的信息为:" << endl;
	cout << " 车号:" << w[k].num << endl;
	cout << " 车名:" << w[k].name << endl;
	cout << " 突破100km/小时时间:" << w[k].dorm << endl;
	cout << " 颜色:" << w[k].uptown << endl;
	cout << " 购买年份:" << w[k].grade << endl;
	cout << " 自动挡还是手动挡:" << w[k].distance << endl;
	cout << " 售价:" << w[k].address << endl;
	cout << endl;
	cout << "确认删除请输入Y,返回主菜单请输入N " << endl;
	string p;
	cin >> p;
	while (1)
	{
		if (p == "y" || p == "Y")
		{
			cout << "汽车信息已删除!" << endl;
			for (int i = 0; i < count; i++)
				if (w[i].num == num3)
					int j = i;
			for (; j <= count - 1; j++)
				w[j] = w[j + 1];
			count--;
			break;
		}
		else if (p == "n" || p == "N")
		{
			menu();
		}
		else
		{
			cout << "输入有误,请重新输入:";
			cin >> p;
		}
	}
}

//汽车信息保存函数实现
void Sale_carList::save()
{
	if (NUM <= 0)
	{
		cout << "没有汽车信息存入,系统将返回主菜单" << endl;
		menu();
	}
	else
	{
		ofstream fout;
		fout.open("Sale_car.txt", ios::out);
		cout << "文件正在保存......请稍候!!" << endl;
		cout << "数据保存成功!!!" << endl;

		for (int i = 0; i < count; i++)
		{
			
			fout <<  w[i].num <<"\t" << w[i].name << "\t" << w[i].dorm << "\t\t\t" << w[i].uptown << "\t" << w[i].grade << "\t\t" << w[i].distance << "\t\t\t" << w[i].address << endl;
			 
		}
		cout << "系统返回主菜单:" << endl;
		menu();
		fout.close();
	}
}

void Sale_carList::load()汽车信息读取函数实现
{
	int sel;

	system("cls");

	cout << "-------------------------------------------------\n";
	cout << "|                  欢迎进入数据读取功能         |\n";
	cout << "|                 1. 选择读取                   |\n";
	cout << "|                 2. 放弃读取                   |\n";
	cout << "-------------------------------------------------\n";
	cout << "              输入你的选择(1-2):";
	cin >> sel;

	while (sel <= 0 || sel >= 3)
	{
		cout << "              输入错误\n";
		cout << "              重新输入你的选择(1-2):";
		cin >> sel;
	}

	if (sel == 1)
	{
		ifstream infile;
		string file = "Sale_car.txt";
		infile.open(file.data());
		assert(infile.is_open());
		string Sale_car;
		cout << "车号" <<"\t" << "车名" << "\t" << "突破100km/小时时间" << "\t" << "颜色" << "\t" << "购买年份" << "\t" << "自动挡还是手动挡" << "\t" << "售价" << endl;
		while (getline(infile, Sale_car)) {
			cout << Sale_car<

你可能感兴趣的:(大数据,c++)