共享单车管理系统

目前大家比较熟悉共享单车的使用。请编制一个共享单车的管理程序,实现如下基本功能。假设有5种品牌的共享单车(品牌内容自定)。
针对该5种品牌的共享单车,自行设计一套包含每种单车的品牌名称、投放量、投放点、某一时间点的在用数量、每辆车的每天骑行次数及单次里程和总里程、开锁过程中发现的损坏次数等信息(所有相关数据均自行设计)的数据结构;
随着骑行活动的开展,待使用单车的数量将发生变化。要求能对每种单车的使用数量及待使用的数量进行查询统计并输出;
对于某一投放点的某一品牌的单车,如果无备用车(待使用的车均为备用车),或备用车均为损坏的车,系统应能给出信息提示;
对于损坏报修的车辆,系统能够进行及时的统计,并能在投放数量中削减损坏车辆的数量,形成真实的有效投放量;
能够对客户信息进行处理,包括注册的用户名、电话号码、骑行里程、骑行习惯(比如70%以上的出行时间集中在某个时间段,时间段按时钟整点划分)、每天平均的骑行时间等;
该系统能进行当日使用状况的统计,请用链表排序(排序算法不限)提示交易使用次数排在前三名的单车品牌;

假设每种单车的使用是收费的,如第一个小时是免费的,第二个小时开始每小时收费0.5元,各品牌可各自推出优惠收费条件(优惠条件请自定义),然后根据假设的使用情况,统计出各种品牌的日营业额,并对各品牌的受欢迎程度进行排序。

有些地方如果写的比较乱 就是因为那个地方之前出过bug...

// 共享单车.cpp : 
/*
使用说明:
*为了测试简单,投放地点用数字1-5代替 ,车辆种类用数字1-5代替,分别为1牌车,2牌车…… 
*存在一些冗余函数和变量 
*利润的计算比较难,因为是以真实的时间为参考,所以至少一个小时才会有利益 
*/
//

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio> 
#include <string>
#include <windows.h>  
#include <map>
#include <cstdlib>
#include <ctime>
#include <conio.h>

#define MAX 65536
#define LEN_ sizeof(Node_user)  
#define LEN_1 sizeof(Node_bike)
using namespace std;



int totnumber_user = 0;//用户人数
int totnumber_bike[6];//车辆数
int totnumber_bike_inuse[6];//正在用的车辆数
multimap<int, int> totprofit;//总利润
						//骑行次数
struct tot_ride
{
	int category;
	int cnt;
	tot_ride* next;
}firstbike;

struct Time {	//作为一个时间节点或者时间段使用 
	int minu, hour, day;
	Time(int a = 0, int b = 0, int c = 0) :minu(a), hour(b), day(c) {}
	Time(SYSTEMTIME &a) {
		minu = a.wMinute;
		hour = a.wHour;
		day = a.wDay;
	}
	Time operator +(Time &a) {	//只做时间段累加 
		Time b = a;
		b.minu += minu;
		b.hour += hour;
		b.hour += b.minu / 60;
		b.minu %= 60;
		return b;
	}
	Time operator -(Time &a) {	//只做计算时间差 
		Time b = a;
		int h = hour;
		if (b.day != day)//只考虑半夜骑车的情况,不考虑骑24小时以上... 
		{
			if (b.day>day)b.hour += 24;
			else h += 24;
		}
		int m = abs((h - b.hour) * 60 + minu - b.minu);
		b.minu = m % 60;
		b.hour = m / 60;
		return b;
	}
	Time operator =(SYSTEMTIME &a) {
		minu = a.wMinute;
		hour = a.wHour;
		day = a.wDay;
	}
	int operator /(int day) {	//只做平均时间 
		int min = hour * 60 + minu;
		return min / day;
	}
};
struct Ride_time {
	Time st, ed;//起始时间和结束时间  
	Time lasting;
	Ride_time(int a = 0, int b = 0, int c = 0) :st(a), ed(b), lasting(c) {}
	Ride_time(Time &a, Time &b) :st(a), ed(b) { lasting = a - b; }

};
struct Ride_info {	//骑行历史信息 
	int ride_cnt;//骑行次数 
	double totdis; //总距离 距离都无法更新
	int totday;
	double dis[MAX];//每次骑行距离 
	Ride_time ride_time[MAX];
	Time totime;
	Ride_info(int a=0,int b=0,int c=0):totime(0),ride_cnt(a),totdis(b),totday(c) {memset(dis, 0, sizeof(dis));}
	void update(double dis0, Ride_time a) {	//更新数据
		ride_cnt++;
		dis[ride_cnt] = dis0;
		totdis += dis0;
		ride_time[ride_cnt] = a;
		if (ride_time[ride_cnt].st.day != ride_time[ride_cnt].ed.day || ride_cnt != 0 && ride_time[ride_cnt].st.day != ride_time[ride_cnt - 1].ed.day || ride_cnt == 0)totday++;
		totime = totime + a.lasting;
	}
	int average_ridetime() { //每天骑多少分钟 
		if (totday == 0)return 0;
		return totime / totday;
	}
	void main_ride() {	//骑行习惯输出
		int hours[13] = { 0 };
		for (int i = 1; i <= ride_cnt; i++)
			hours[ride_time[i].st.hour / 2]++;
		int max1 = 0, t;
		for (int i = 0; i<12; i++)
		{
			if (hours[i]>max1)
			{
				max1 = hours[i];
				t = i;
			}
		}
		if(ride_cnt)
			printf("有%d%%的出行时间集中在%d——%d时间段\n每天平均骑行时间为%d分钟\n", max1 / ride_cnt * 100, t * 2, t * 2 + 2, average_ridetime());
	}
};

//车辆数据
struct Node_bike {
	char number[105];//车牌 
	char pw[105];//密码
	int catrgory;//种类 好像打错了 但是不影响 1-5
	char address[5];//目前所在位置 只有一位 1-5
	int ride_cnt;//被骑次数
	Time used_time;//使用时间
	int damaged_cnt;//损坏次数
	bool isbad;
	bool isuse;
	bool be;//是否储存了数据,冗余 
	Node_bike* next;
	Node_bike() {
		ride_cnt = 0;
		damaged_cnt = 0;
		next = NULL;
		catrgory = 0;
		be = 0;
	}
	double charge() {
		srand((unsigned)time(NULL));
		if (used_time.hour <= 1)return 0;
		if (catrgory == 0)//1号车前两个小时免费
			if (used_time.hour <= 2)return 0;
			else return (used_time.hour - 2)*0.5;
		else if (catrgory == 1)
		{
			if (used_time.hour >= 3)//2号车骑3个小时以上减一块钱
				return (used_time.hour - 1)*0.5 - 1;
			else (used_time.hour - 1)*0.5;
		}
		else if (catrgory == 2)//3号车0.4元一小时
			return (used_time.hour - 1)*0.4;
		else if (catrgory == 3)//4号车随机减两块钱一下的金额(好想法)
		{
			double x = rand() *3.1415926;
			int t = (used_time.hour - 1)*0.5 - (x - (int)(x / 2) * 2);
			return t > 0 ? t : 0;
		}
		else return (used_time.hour - 1)*0.5;//5号车不优惠
	}
};

//用户数据 
struct Node_user {
	int number_user;
	char phone[105];
	char username[105];
	char password[105];
	bool isride;
	bool be;//是否储存了数据
	Node_bike* bike;//当前正在骑的车
	SYSTEMTIME first, second;//这一次骑车的经过时间
	Ride_info ride_info;
	Node_user* next;
	Node_user() {
		number_user = ++totnumber_user;
		isride = 0;
		next = NULL;
		bike = NULL;
		be = 0;
	}
};

Node_bike* First = new Node_bike;//第一辆车
Node_user* Second = new Node_user;//第一个用户
Node_user* readfile_user();//读取用户信息
Node_bike* readfile_bike();//读取车辆信息
Node_bike* search_bike(char s[100]);//搜索车牌为s的车
void update_bike(Node_bike* m);//及时更新车辆相关信息 
void savefile_user(Node_user *m);//保存用户信息
void savefile_Fbike(Node_bike *m);//保存损坏车辆
void print_user(Node_user* m);//输出所有用户的信息
void savefile_bike(Node_bike* m);//保存添加的车辆
void loolfor_bike(int n);	//输出n点的可用车辆信息
void print_bike();
void print_bike_place(int n);	//输出n点可用车辆数
void swap_node(tot_ride * & head, int i, int j);
tot_ride * getitem(tot_ride * & head, int i);
void rend(Node_user* m, Node_bike* h);//借车时更新数据
void return_bike(Node_user* m, int p);//还车时更新数据
void rewrite();//写入覆盖文件
void input();//输入所添加车辆的信息
void User(Node_user* user);
void Login();
void Register();
void user();
void admin();
void start();

void show_off()
{
	cout << "\n\n";
	cout << "现在正在进行夏季骑车活动,有各种各样的优惠等你来" << endl;
	cout << "1号车前2个小时免费" << endl;
	cout << "2号车骑3个小时以上减1元" << endl;
	cout << "3号车0.4元1小时" << endl;
	cout << "4号车随机减免金额(2元以内)" << endl;

}

void show1()
{
	cout << "欢迎使用YX共享单车管理程序" << endl;
	cout << "输入相应的数字并回车执行相应功能" << endl;
	cout << "1 管理员登录" << endl;
	cout << "2 用户登录" << endl;
	cout << "3 退出" << endl;
}

void show2()
{
	cout << "欢迎使用共享单车管理程序——客户端" << endl;
	cout << "输入相应的数字并回车执行相应功能" << endl;
	cout << "1 登录" << endl;
	cout << "2 注册" << endl;
	cout << "3 返回" << endl;
}

void show3()
{
	cout << "欢迎登录共享单车管理程序——客户端" << endl;
	cout << "现在你想做?" << endl;
	cout << "1 附近的车" << endl;
	cout << "2 立即用车" << endl;
	cout << "3 一键还车" << endl;
	cout << "4 车辆报修" << endl;
	cout << "5 我的信息" << endl;
	cout << "6 退出登录" << endl;
	show_off();
}

void show4()
{
	cout << "欢迎使用共享单车管理程序——管理端" << endl;
	cout << "现在你想做?" << endl;
	cout << "1 添加车辆" << endl;
	cout << "2 车辆信息" << endl;;
	cout << "3 用户信息" << endl;
	cout << "4 当日骑行数据" << endl;
	cout << "5 当日收费数据" << endl;
	cout << "6 退出登录" << endl;
}

Node_bike* search_bike(char s[100]) //找车 
{
	Node_bike* m;
	m = First;
	while (m != NULL)
	{
		if (strcmp(m->number, s) == 0)break;
		m = m->next;
	}
	if (m == NULL)
	{
		cout << "\n信息有误,按任意键后重新输入";
		getch();
	}
	
	return m;
}

Node_bike* new2 = new Node_bike;
Node_bike* readfile_bike()
{
	Node_bike *a = NULL;
	Node_bike *head = First, *u = First;
	int cnt = 0;
	FILE *fp;
	fp = fopen("bike.bin", "ab+");
	fclose(fp);
	fp = fopen("bike.bin", "rb+");
	if (fp == NULL)
	{
		fclose(fp);
		return (head);
	}
	do
	{
		if (!cnt)
		{
			if (!fread(head, LEN_1, 1, fp))break;
			cnt++;
			continue;
		}
		if (!fread(new2, LEN_1, 1, fp))break;
		head->next = new2;
		head = head->next;
		cnt++;
	}while (head != NULL);
	fclose(fp);
	if (!cnt)return a;
	return (u);
}

void rewrite()
{
	FILE* fp;
	fp = fopen("bike.bin", "wb");
	Node_bike* a = First;
	Node_user* b = Second;
	while (a != NULL)
	{
		fwrite(a, LEN_1, 1, fp);
		a = a->next;
	}
	fclose(fp);
	fp = fopen("user.bin", "wb");
	while (b != NULL)
	{
		fwrite(b, LEN_, 1, fp);
		b = b->next;
	}
	fclose(fp);
}

void update_bike(Node_bike* m)
{
	Node_bike* n = m;
	memset(totnumber_bike, 0, sizeof(totnumber_bike));
	memset(totnumber_bike_inuse, 0, sizeof(totnumber_bike_inuse));
	while (n != NULL)
	{
		if (!n->isbad)
			totnumber_bike[n->catrgory]++;
		if (n->isuse)
			totnumber_bike_inuse[n->catrgory]++;
		n = n->next;
	}
}

void savefile_bike(Node_bike* m)
{
	m->be = 1;
	Node_bike* n = First;
	while (First != NULL&&First->next != NULL)
	{
		First = First->next;
	}
	if (First == NULL)
		First = m;
	else
	{
		First->next = m;
		First = n;
	}
	rewrite();
}

void savefile_Fbike(Node_bike *m)
{
	FILE* fp;
	fp = fopen("Fbike.bin", "ab+");
	m->isbad = 1;
	m->isuse = 0;
	m->damaged_cnt++;
	fwrite(m, LEN_1, 1, fp);
	fclose(fp);
	rewrite();
}

Node_user* new1 = new Node_user;
Node_user* readfile_user()
{
	int cnt = 0;
	Node_user *a = NULL;
	Node_user *head = Second, *m = Second;
	FILE *fp;
	totnumber_user = 0;
	fp = fopen("user.bin", "ab+");
	fclose(fp);
	fp = fopen("user.bin", "rb");
	if (fp == NULL)
	{
		fclose(fp);
		return (head);
	}
	do
	{
		if (!cnt)//第一次读用head
		{
			if (!fread(head, LEN_, 1, fp))break;
			cnt++;
			continue;
		}
		if (!fread(new1, LEN_, 1, fp))break;//之后用new1作为head的next
		head->next = new1;
		totnumber_user++;
		cnt++;
		head = head->next;
	} while (head != NULL);
	fclose(fp);
	if (!cnt)return a;
	return (m);
}


void savefile_user(Node_user *m)
{
	Node_user *n = Second;
	m->be = 1;
	while (Second != NULL&&Second->next != NULL)
	{
		Second = Second->next;
	}
	if (Second == NULL)
		Second = m;
	else
	{
		Second->next = m;
		Second = n;
	}
	rewrite();
}
void print_user(Node_user* m)
{
	int i = 0;
	system("cls");
	while (m != NULL)
	{
		i++;
		printf("第%d个用户:\n", i);
		cout << "用户名:" << m->username << endl;
		cout << "密码:" << m->password << endl;
		cout << "电话号码:" << m->phone << endl;
		printf("骑行里程:%2lfkm\n", m->ride_info.totdis);
		if (m->ride_info.totdis != 0)m->ride_info.main_ride();
		cout << endl << endl;
		m = m->next;
	}
}

void print_bike()
{
	int i = 0;
	Node_bike* m = First;
	int temp[6] = { 0 };
	while (m != NULL)
	{
		if (m->isuse)
			temp[m->catrgory]++;
		m = m->next;
	}
	for (i = 1; i < 6; i++)
	{
		cout << i + 1 << "牌车 正在使用:" << temp[i] << "  待使用:" << totnumber_bike[i] - temp[i] << endl;
		cout << "按任意键返回";
		getch();
	}
}

tot_ride * getitem(tot_ride * & head, int i)
{
	//我们要求程序返回特定位置上的值
	//我们一样是从头结点开始寻找该位置
	int j = 0;
	tot_ride * L = head;
	//想要的那个位置是否合法
	if (i<1 || i >head->cnt)return NULL;
	//同样是先得到前一个结点
	while (j < i - 1) {
		L = L->next;
		++j;
	}
	return L;
}

void swap_node(tot_ride * & head, int i, int j) //有点绕 慢慢写
{
	//同一个位置不用交换
	if (i == j)return;
	//相邻两个交换比较简单
	if (abs(i - j) == 1) {
		//位置靠前的那个结点的前一个结点
		tot_ride * pre;
		if (i < j)
			pre = getitem(head, i);
		else
			pre = getitem(head, j);
		//保存第一个结点
		tot_ride * a = pre->next;
		//保存第二结点
		tot_ride * b = a->next;
		//改变pre下一个结点的值
		pre->next = b;
		//必须先把b的下一个结点值给a先
		a->next = b->next;
		//让b的下一个结点等于a
		b->next = a;
		return;
	}
	//第一个结点前一个结点
	tot_ride * a = getitem(head, i);
	//第二个结点的前一个结点
	tot_ride * b = getitem(head, j);
	//第一个结点
	tot_ride * p = a->next;
	//第二个结点
	tot_ride * q = b->next;
	//第一个结点的下一个结点
	tot_ride * p_next = p->next;
	//第二结点的下一个结点
	tot_ride * q_next = q->next;
	//a的下一个结点指向第二个结点q
	a->next = q;
	//第二结点的下一个结点指向第一个结点的下一个结点
	q->next = p_next;
	//b的下一个结点指向第一个结点p
	b->next = p;
	//第一个结点的下一个结点指向第二个结点的下一个结点
	p->next = q_next;

}

void rend(Node_user* m, Node_bike* h)
{
	m->isride = 1;
	h->isuse = 1;
	GetLocalTime(&m->first);
	m->bike = h;
	rewrite();
}

void return_bike(Node_user* m, int p)	//更新所有需要更新的
{
	m->isride = 0;
	m->bike->isuse = 0;
	GetLocalTime(&m->second);
	cout << "请输入骑行里程" << endl;
	double x;
	cin >> x;
	Time q = m->first, b = m->second;
	Ride_time a(q, b);
	m->ride_info.update(x, a);
	m->bike->ride_cnt++;
	m->bike->address[0] = p + '0';
	m->bike->used_time = m->bike->used_time + b - q;
	m->bike = NULL;
	rewrite();
	update_bike(First);
}

void print_bike_place(int n)
{
	Node_bike* m = First;
	int temp[6] = { 0 };
	while (m != NULL)
	{
		if (!m->isuse && !m->isbad)
			temp[m->address[0] - '0']++;
		m = m->next;
	}
	printf("%d处可用车辆有%d辆\n", n, temp[n]);
	for (int i = 1; i <= 5; i++)
	{
		if (temp[i] == 0)
			printf("%d处已无可用车辆,请及时补充!\n", i);
	}
}

void loolfor_bike(int n)
{
	Node_bike* m = First;
	int temp[6] = { 0 };
	cout << "当前可用车辆有:\n";
	if (m == NULL)cout << 0;
	while (m != NULL)
	{
		if (!m->isuse && !m->isbad && ((m->address[0] - '0') == n))
		{
			printf("%s\n", m->number);
		}
		m = m->next;
	}
	cout << "\n若无输出表示无可用车辆\n";
	cout << endl;
}

void input()
{
	char name[105];
	Node_bike *pnew;
	pnew = new Node_bike;
	while (1)
	{
		int i = 0;
		system("cls");
		int catrgery;
		char s[105];
		while (1)
		{
			system("cls");
			cout << "请输入车辆种类:" << endl;
			cin >> s;
			if (strlen(s) > 1 || !isdigit(s[0]) || s[0] == '0' || s[0] > '5')
			{
				cout << "车辆种类只能是1-5之间的数字,按任意键后重新输入" << endl;
				getch();
			}
			else break;
		}
		pnew->catrgory = s[0] - '0';
		cout << "请输入车辆车牌(数字):" << endl;
		cin >> name;
		strcpy(pnew->number, name);
		for (i = 0; i < strlen(name); i++)
		{
			if (!isdigit(name[i]))
			{
				cout << "车牌只能为数字" << endl;
				cout << "按任意键后重新输入" << endl;
				getch();
				break;
			}
		}
		if (i == strlen(name))break;
	}
	cout << "请输入车辆密码:" << endl;
	pnew->next = NULL;
	cin >> pnew->pw;
	while (1)
	{
		cout << "请输入车辆投放地点:" << endl;
		cin >> pnew->address;
		if (strlen(pnew->address)>1 || !isdigit(pnew->address[0]) || pnew->address[0] == '0' || pnew->address[0]>'5')//只能投放在5个地方
		{
			cout << "只能投放在1-5处,按任意键后重新输入" << endl;
			getch();
			system("cls");
			continue;
		}
		else break;
	}
	pnew->isbad = 0; pnew->isuse = 0;
	savefile_bike(pnew);
	cout << "添加成功" << endl;
}

void User(Node_user* m)//用户主界面
{
	system("cls");
	char s0[105];
	Node_bike* bike;
	while (1)
	{
		show3();
		cin.getline(s0, 100);
		if (strlen(s0)>1 || !isdigit(s0[0]) || s0[0] == '0' || s0[0]>'6')
		{
			cout << "非法输入,按任意键后重新输入";
			getch();
			system("cls");
			continue;
		}
		break;
	}
	if (s0[0] == '6') return start();
	if (s0[0] == '5')
	{
		update_bike(First);
		system("cls");
		cout << "用户名:" << m->username << endl;
		cout << "电话号码:" << m->phone << endl;
		printf("骑行里程:%2lfkm\n", m->ride_info.totdis);
		if (m->ride_info.totdis != 0)m->ride_info.main_ride();
		cout << "按任意键返回";
		getch();
		return User(m);
	}
	if (s0[0] == '4')//车坏了应该还要把信息传回管理 
	{
		update_bike(First);
		while (1)
		{
			system("cls");
			cout << "请输入要报修的车辆的车牌号或者输入0返回" << endl;
			char s1[105];
			cin.getline(s1, 100);
			if (strlen(s1) == 1 && s1[0] == '0') return User(m);
			bike = search_bike(s1);
			if (bike != NULL)break;
		}
		cout << "感谢您的反馈,我们会尽快维修损坏车辆\n按任意键返回";
		savefile_Fbike(bike);
		getch();
		return User(m);
	}
	if (s0[0] == '3')
	{
		update_bike(First);
		system("cls");
		if (!m->isride)
		{
			cout << "你未在行程中" << endl;
			cout << "按任意键返回" << endl;
			getch();
			return User(m);
		}

		char s1[105];
		while (1)
		{
			system("cls");
			cout << "请输入当前地址" << endl;
			cin.getline(s1, 100);
			if (strlen(s1) != 1 || !isdigit(s1[0]) || s1[0] == '0' || s1[0] > '5')
			{
				cout << "输入的位置有误,请重新输入\n";
				getch();
				continue;
			}
			else break;
		}
		return_bike(m, s1[0] - '0');
		cout << "归还成功" << endl;
		cout << "按任意键返回" << endl;
		getch();
		return User(m);

	}
	if (s0[0] == '2')
	{
		update_bike(First);
		system("cls");
		if (m->isride)
		{
			cout << "你已经在使用中,同一时间只能使用一辆车\n";
			cout << "按任意键返回\n";
			getch();
			return User(m);
		}
		char s1[105];
		while (1)
		{
			system("cls");
			cout << "请输入车牌号或输入0返回\n";
			cin.getline(s1, 100);
			if (s1[0] == '0')return User(m);
			Node_bike* h = search_bike(s1);
			if (h == NULL)continue;
			else
			{
				if (h->isbad)
				{
					cout << "这辆车已经损坏" << endl;
					cout << "按任意键后,重新输入" << endl;
					getch();
					continue;
				}
				if (h->isuse)
				{
					cout << "这辆车正在被使用" << endl;
					cout << "按任意键后,重新输入" << endl;
					getch();
					continue;
				}
				rend(m, h);
				cout << "按任意键返回" << endl;
				getch();
				break;
			}
		}
		return User(m);
	}
	if (s0[0] == '1')
	{
		update_bike(First);
		char s1[105];
		while (1)
		{
			system("cls");
			cout << "请输入你所在的位置,数字1-5\n";
			cin.getline(s1, 100);
			if (strlen(s1) != 1 || !isdigit(s1[0]) || s1[0] == '0' || s1[0] > '5')
			{
				cout << "输入的位置有误,请重新输入\n";
				continue;
			}
			else break;
		}
		loolfor_bike(s1[0] - '0');
		cout << "按任意键返回\n";
		getch();
		return User(m);
	}

}

void Login()//登录界面 
{
	Node_user *m, *n;
	m = n = Second;
	system("cls");
	cout << "请输入用户名和密码" << endl;
	cout << "用户名:";
	char s0[105], s1[105];
	cin.getline(s0, 100);
	cout << "密码:";
	cin.getline(s1, 100);
	while (m != NULL)
	{
		if (strcmp(m->username, s0) == 0 && strcmp(m->password, s1) == 0)
		{
			system("cls");
			printf("登陆成功,按任意键进入用户界面");
			getch();
			return User(m);
		}
		m = m->next;
	}
	if (m == NULL)
	{
		cout << "账号或密码错误,按任意键后重新输入";
		getch();
		Login();
	}

}

void Register()//注册界面 
{
	system("cls");
	char s0[105];
	Node_user *m = new Node_user, *n = NULL;
	while (1)
	{
		system("cls");
		cout << "注册YX,骑遍更广的世界" << endl;
		cout << "用户名:";
		cin.getline(m->username, 100);
		//检验用户名是否存在 
		n = Second;
		while (n != NULL)
		{
			//cout << 1111;
			if (strcmp(n->username, m->username) == 0)
			{
				cout << "该用户名已被注册,按任意键后重新输入" << endl;
				getch();
				break;
			}
			n = n->next;
		}
		if (n == NULL)
		{
			cout << "该用户名合法,按任意键后输入密码" << endl;
			getch();
			break;
		}
	}
	system("cls");
	cout << "注册YX,骑遍更广的世界" << endl;
	cout << "用户名:" << m->username << endl;
	cout << "密码:";
	cin.getline(m->password, 100);
	cout << "手机号码:";
	cin.getline(m->phone, 100);
	cout << "注册成功,按任意键后登录" << endl;
	savefile_user(m);
	getch();
	return Login();

}

void user()//用户界面1 
{
	system("cls");
	char s0[1005];
	while (1)
	{
		show2();
		cin.getline(s0, 1000);
		if (strlen(s0)>1 || !isdigit(s0[0]) || s0[0] != '1'&&s0[0] != '2'&&s0[0] != '3')
		{
			cout << "非法输入,按任意键后重新输入";
			getch();
			system("cls");
			continue;
		}
		break;
	}
	if (s0[0] == '3') return;
	if (s0[0] == '2') return Register();
	if (s0[0] == '1') return Login();

}

void admin()//管理员界面
{
	system("cls");
	char s0[105];
	while (1)
	{
		show4();
		cin.getline(s0, 100);
		if (strlen(s0)>1 || !isdigit(s0[0]) || s0[0] == '0' || s0[0]>'6')
		{
			cout << "非法输入,按任意键后重新输入";
			getch();
			system("cls");
			continue;
		}
		break;
	}
	if (s0[0] == '6')return start();
	if (s0[0] == '5')
	{
		system("cls");
		int i = 0;
		int temp[6] = { 0 };
		Node_bike* r = First;
		update_bike(r);
		while (r != NULL)
		{
			temp[r->catrgory] += r->charge();
			r = r->next;
		}
		totprofit.clear();
		for (i = 1; i <= 5; i++)
			totprofit.insert(pair<int, int>(temp[i], i));

		cout << "今日的利润为:\n";
		multimap<int, int>::reverse_iterator it;
		for (it = totprofit.rbegin(); it != totprofit.rend(); it++)
			cout << it->second << "牌车:" << it->first << endl;
		cout << "按任意键返回";
		getch();
		return admin();
	}
	if (s0[0] == '4')//冒泡链表排序
	{
		system("cls");
		int temp[6] = { 0 };
		Node_bike* r = First;
		update_bike(r);
		while (r != NULL)
		{
			temp[r->catrgory] += r->ride_cnt;
			r = r->next;
		}
		firstbike.next = new tot_ride;
		tot_ride* t = firstbike.next;
		for (int i = 1; i < 6; i++)
		{
			t->category = i;
			t->cnt = temp[i];
			t->next = new tot_ride;
			t = t->next;
		}
		tot_ride *p = NULL;
		bool isChange = true;
		tot_ride* head = firstbike.next;
		int i = 0;
		int j = 0;
		tot_ride * L = head;
		tot_ride * p1;
		int flag = 0;
		for (i = 0; i < head->cnt - 1; i++)
		{
			L = head->next;
			for (j = 0; j < head->cnt - 1 - i; j++)
			{
				if (L->cnt > L->next->cnt) {
					flag = 1;
					swap_node(head, j + 1, j + 2);
				}
				if (flag == 1)
					flag = 0;
				else
					L = L->next;
			}
		}
		head = firstbike.next;
		cout << "今日的交易使用次数为\n";
		for (int i = 1; i <= 3; i++)
		{
			cout << head->category << "牌车:" << head->cnt << endl;
			head = head->next;
		}
		cout << "按任意键返回";
		getch();
		return admin();
	}
	if (s0[0] == '3')
	{
		system("cls");
		Node_user* m = Second;
		print_user(m);
		cout << "按任意键返回";
		getch();
		return admin();
	}
	if (s0[0] == '2')
	{
		update_bike(First);
		char s1[105];
		while (1)
		{
			system("cls");
			for (int i = 1; i < 6; i++)
				cout << i << "牌车 正在使用:" << totnumber_bike_inuse[i] << "  待使用:" << totnumber_bike[i] - totnumber_bike_inuse[i] << endl;
			cout << "输入1-5查询各个投放点的车辆信息\n输入0返回\n";
			cin.getline(s1, 100);
			if (strlen(s1) > 1 || !isdigit(s1[0]) || s0[0] > '5')
			{
				cout << "非法输入,按任意键后重新输入";
				getch();
				system("cls");
				continue;
			}
			else break;
		}
		if (s1[0] == '0')return admin();
		else
		{
			print_bike_place(s1[0] - '0');
			cout << "按任意键返回";
			getch();
			return admin();
		}
	}
	if (s0[0] == '1')
	{
		system("cls");
		input();
		cout << "按任意键返回";
		update_bike(First);
		getch();
		return admin();
	}
}

void start()//开始界面
{
	system("cls");
	char s0[1005];
	while (1)
	{
		show1();
		cin.getline(s0, 1000);
		if (strlen(s0)>1 || !isdigit(s0[0]) || s0[0] != '1'&&s0[0] != '2'&&s0[0] != '3')
		{
			cout << "非法输入,按任意键后重新输入";
			getch();
			system("cls");
			continue;
		}
		break;
	}
	if (s0[0] == '3') return;
	if (s0[0] == '2') return user();
	if (s0[0] == '1') return admin();

}

int main()
{
	First = readfile_bike();
	Second = readfile_user();
	start();

	return 0;
}


阅读更多
文章标签: 长程序
个人分类: 杂类
想对作者说点什么? 我来说一句

公共自行车管理系统

2013年12月16日 368KB 下载

毕设共享单车源代码

2018年05月15日 17.9MB 下载

共享单车

车轮去了哪里?

JAVA_QinWXiao JAVA_QinWXiao

2017-01-03 00:35:17

阅读数:1383

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭