33,311
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
void main();
typedef struct AirportTicketSystem
{
//以下为vip相关元素
char VIPName[35];//会员名
float VIPPassword;//会员密码
char Birthday[45];//会员生日
char EmailAddress[40];//会员邮箱
float VIPNumber;//会员序列号,自动从100000开始
float VIPPlaneNumber;
//以上为vip相关元素
//以下为管理员相关元素
char AdminName[35];
float AdminPassword;
//以上为管理员相关元素
//以下为机票相关元素
char TTime[35];//起飞时间
char ATime[35];//降落时间
char TCity[35];//起飞城市
char ACity[35];//降落时间
float Price;//票价
float Discount;//折扣
int Count;//数量
float AIRNumber;//机票号,自动从747000开始
//以上为机票相关元素
struct AirportTicketSystem *next;
}System;
void CreatePlaneListF(System *&P, int n)//机票录入//头插法建立单链表
{
System *p; //小指针,指向System
int i;//计数器
P = (System *)malloc(sizeof(System)); //创建头结点
P->AIRNumber = 747000;//号码自增,从100000开始
P->next = NULL;
printf("请依次输入您的信息:\n");
for (i = 0; i<n; i++)
{
p = (System *)malloc(sizeof(System));//创建新结点
printf("请输入起飞时间\n");
scanf("%s", &p->TTime);
getchar();
printf("请输入降落时间\n");
scanf("%s", &p->ATime);
getchar();
printf("请输入起飞城市\n");
scanf("%s", &p->TCity);
getchar();
printf("请输入降落城市\n");
scanf("%s", &p->ACity);
getchar();
printf("请输入价格\n");
scanf("%f", &p->Price);
printf("请输入折扣\n");
scanf("%f", &p->Discount);
printf("请输入剩余票量\n");
scanf("%d", &p->Count);
p->AIRNumber = P->AIRNumber + 1;//号码自增
P->AIRNumber++;//号码自增
p->next = P->next; //将*s插在原开始结点之前,头结点之后
P->next = p;
}
P->next = NULL;
}
void InitPlaneList(System *&P)//初始化链表
{
P = (System *)malloc(sizeof(System)); //创建头结点
P->next = NULL;
}
void DestroyPlaneList(System *&P)//删除所有会员,递归操作
{
if (P == NULL)
{
return;
}
else
{
DestroyPlaneList(P->next);
free(P);
}
}
int DispSinglePlaneList(System *P, float Number)
{
System *p = P->next;
int n = 1;
;
while (p != NULL&&p->AIRNumber != Number)
{
p = p->next;
}
if (p == NULL)
{
printf("不存在\n");
}
else
{
printf("起飞时间:%s", p->TTime);
printf("降落时间:%s", p->ATime);
printf("起飞城市:%s", p->TCity);
printf("降落城市:%s", p->ACity);
printf("价格:%f", p->Price);
printf("折扣:%f", p->Discount);
printf("剩余票量:%d", &p->Count);
printf("\n");
}
return 0;
}
void DispAllPlane(System *P)
{
if (P == NULL)
{
return;
}
else
{
DispAllPlane(P->next);
printf("序号:%.0f\n", P->AIRNumber);
printf("起飞时间:%s\n", P->TTime);
printf("降落时间:%s\n", P->ATime);
printf("起飞城市:%s\n", P->TCity);
printf("降落城市:%s\n", P->ACity);
printf("价格:%.0f\n", P->Price);
printf("折扣:%.0f\n", P->Discount);
printf("剩余票量:%d\n", P->Count);
}
}
int ListPlaneLength(System *P)//计算机票种类数,递归操作
{
int i = 0;
if (P->next == NULL)
{
return 0;
}
else
{
return ListPlaneLength(P->next) + 1;
}
}
bool ListPlaneInsert(System *&P, int i, char *ttime, char *atime, char *tcity, char *acity, float price, float discount, int count)//插入到特定值后
{
int j = 0;
System *p = P, *s;
ListPlaneLength(P);
while (j<i - 1 && p != NULL) //查找第i-1个结点
{
j++;
p = p->next;
}
if (p == NULL) //未找到位序为i-1的结点
return false;
else //找到位序为i-1的结点*p
{
s = (System *)malloc(sizeof(System));//创建新结点*s
strcpy(s->TTime, ttime);
strcpy(s->ATime, atime);
strcpy(s->TCity, tcity);
strcpy(s->ACity, acity);
s->Price = price;
s->Discount = discount;
s->Count = count;
s->next = p->next; //将*s插入到*p之后
p->next = s;
return true;
}
}
void DeleteSinglePlane(System *&P, float number)//删除单个机票信息,递归操作
{
System *temp;
if (P == NULL)
{
return;
}
else if (number == P->AIRNumber)
{
temp = P;
P = P->next;
free(temp);
return;
}
else
{
DeleteSinglePlane(P->next, number);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct tagTicket{
//以下为机票相关元素
char TTime[35];//起飞时间
char ATime[35];//降落时间
char TCity[35];//起飞城市
char ACity[35];//降落时间
float Price;//票价
float Discount;//折扣
int Count;//数量
float AIRNumber;//机票号,自动从747000开始
//以上为机票相关元素
struct tagTicket* next;
}Ticket;
typedef struct tagPerson{
//以下为vip相关元素
char VIPName[35];//会员名
float VIPPassword;//会员密码
char Birthday[45];//会员生日
char EmailAddress[40];//会员邮箱
float VIPNumber;//会员序列号,自动从100000开始
float VIPPlaneNumber;
//以上为vip相关元素
bool isAdmin;
struct tagTicket* ticket;
struct tagPerson* next;
}Person;
typedef void (*act)();
void vip();
void admin();
char* cover_system_title = "欢迎光临大中华机票购买系统";
int cover_system_count = 3;
char* cover_system_items[] = {"进入会员相关界面", "进入管理员相关界面", "退出系统"};
act cover_system_doing[] = {vip, admin};
char* ticket_operate_title = "机票操作项";
int ticket_operate_count = 7;
char* ticket_operate_items[] = {"录入机票", "展示机票", "机票种类", "摧毁机库", "补充机票", "删除机票", "返回上级"};
act ticket_operate_doing[] = {NULL, NULL, NULL, NULL, NULL, NULL};
char* admin_main_title = "管理员选项";
int admin_main_count = 4;
char* admin_main_items[] = {"注册管理员", "管理员登录", "计算会员数量", "返回主菜单"};
act admin_main_doing[] = {NULL, NULL, NULL};
char* admin_logined_title = "管理员选项";
int admin_logined_count = 4;
char* admin_logined_items[] = {"注册管理员", "管理员登录", "计算会员数量", "返回主菜单"};
act admin_logined_doing[] = {NULL, NULL, NULL};
char* vip_main_title = "会员主菜单";
int vip_main_count = 5;
char* vip_main_items[] = {"注册会员", "会员登录", "新入会员", "会员人数", "回主菜单"};
act vip_main_doing[] = {NULL, NULL, NULL, NULL};
char* vip_logined_title = "会员操作";
int vip_logined_count = 5;
char* vip_logined_items[] = {"查询机票信息", "购买机票", "查询个人信息", "修改密码", "返回主菜单"};
act vip_logined_doing[] = {NULL, NULL, NULL, NULL};
char* vip_info_title = "会员信息";
int vip_info_count = 5;
char* vip_info_items[] = {"会员个数", "清空数据", "删除会员", "展示会员", "回主菜单"};
act vip_info_doing[] = {NULL, NULL, NULL, NULL};
Ticket* getTicket(int number){
Ticket* ticket = (Ticket*)malloc(sizeof(Ticket));
memset(ticket, 0, sizeof(Ticket));
printf("请输入起飞时间\n");
scanf("%s", ticket->TTime);
printf("请输入降落时间\n");
scanf("%s", ticket->ATime);
printf("请输入起飞城市\n");
scanf("%s", ticket->TCity);
printf("请输入降落城市\n");
scanf("%s", ticket->ACity);
printf("请输入价格\n");
scanf("%f", &ticket->Price);
printf("请输入折扣\n");
scanf("%f", &ticket->Discount);
printf("请输入剩余票量\n");
scanf("%d", &ticket->Count);
ticket->AIRNumber = number;
return (ticket);
}
void addTicket(Ticket* last){
char sure = 'n';
Ticket* ticket = getTicket(last->AIRNumber + 1);
ticket->next = last->next;
printf("Number: %0.0f, Time: %s -> %s, City: %s -> %s, Price: %0.2f, Discount: %0.2f, Count: %d, are you sure?",
ticket->AIRNumber, ticket->TTime, ticket->ATime, ticket->TCity, ticket->ACity, ticket->Price, ticket->Discount, ticket->Count);
fflush(stdin);
sure = getchar();
if('y' == sure){
last->next = ticket;
} else {
free(ticket);
}
}
Person* getPerson(int number, bool isAdmin = false){
Person* person = (Person*)malloc(sizeof(Person));
memset(person, 0, sizeof(Person));
printf("请输入您的姓名\n");
scanf("%s", person->VIPName);
printf("请输入您的密码\n");
scanf("%f", &person->VIPPassword);
printf("请输入您的生日\n");
scanf("%s", person->Birthday);
printf("请输入您的邮箱\n");
scanf("%s", person->EmailAddress);
person->isAdmin = isAdmin;
person->VIPNumber = number;
return (person);
}
void addPerson(Person* last, bool isAdmin = false){
char sure = 'n';
Person* person = getPerson(last->VIPNumber + 1, isAdmin);
person->next = last->next;
printf("Number: %0.0f, Name: %s, Password: %0.0f, Birthday: %s, EmailAddress: %s, Admin: %d, are you sure?",
person->VIPNumber, person->VIPName, person->VIPPassword, person->Birthday, person->EmailAddress, person->isAdmin);
fflush(stdin);
sure = getchar();
if('y' == sure){
last->next = person;
} else {
free(person);
}
}
void displayPerson(Person* person, int level = -1){
if (NULL == person || 0 == level){
return;
}
printf("会员:%s,您的信息为:\n", person->VIPName);
printf("您的密码是:%.0f\n", person->VIPPassword);
printf("您的生日是:%s\n", person->Birthday);
printf("您的邮箱是:%s\n", person->EmailAddress);
printf("您的序列号是:%0.f\n", person->VIPNumber);
printf("\n\n");
displayPerson(person->next, --level);
}
int choice(int argc, char* argv[], char* title){
system("cls");
system("time/t");
int c = -1;
printf("\n\n\n\n");
printf("\t\t\t\t");
int start = (45 - strlen(title)) / 2;
for(int i = 0; i < start; i++){
printf(" ");
}
printf("%s\n", title);
printf("\t\t\t\t +--------------------------------------+\n");
for(int i = 0; i < argc; i++){
printf("\t\t\t\t |%2d.%-35s|\n", i + 1, argv[i]);
}
printf("\t\t\t\t +--------------------------------------+\n");
printf("\t\t\t\t 请输入您的选择:");
scanf("%d", &c);
return (c);
}
int select(char* title, int count, char* items[], act doing[]){
int index = -1;
while((index = choice(count, items, title)) != count){
if(0 < index && index < count && NULL != doing[index - 1]){
doing[index - 1]();
}
}
return (index);
}
void vip(){
select(vip_main_title, vip_main_count, vip_main_items, vip_main_doing);
}
void admin(){
select(admin_main_title, admin_main_count, admin_main_items, admin_main_doing);
}
int main(){
system("color 5f");//改变界面颜色
//select(cover_system_title, cover_system_count, cover_system_items, cover_system_doing);
//Ticket* head = (Ticket*)malloc(sizeof(Ticket));
//memset(head, 0, sizeof(Ticket));
//addTicket(head);
Person* person = (Person*)malloc(sizeof(Person));
memset(person, 0, sizeof(Person));
Person* personHead = person;
for(int i = 0; i < 5; i++){
addPerson(person);
if(NULL != person->next){
person = person->next;
}
}
displayPerson(personHead->next);
return (0);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct tagPerson{
char name[35];
int password;
//...
}Person;
typedef struct tagTicket{
//以下为机票相关元素
char TTime[35];//起飞时间
char ATime[35];//降落时间
char TCity[35];//起飞城市
char ACity[35];//降落时间
float Price;//票价
float Discount;//折扣
int Count;//数量
float AIRNumber;//机票号,自动从747000开始
//以上为机票相关元素
struct tagTicket* next;
}Ticket;
typedef void (*act)();
void vip();
void admin();
char* cover_system_title = "欢迎光临大中华机票购买系统";
int cover_system_count = 3;
char* cover_system_items[] = {"进入会员相关界面", "进入管理员相关界面", "退出系统"};
act cover_system_doing[] = {vip, admin};
char* ticket_operate_title = "机票操作项";
int ticket_operate_count = 7;
char* ticket_operate_items[] = {"录入机票", "展示机票", "机票种类", "摧毁机库", "补充机票", "删除机票", "返回上级"};
act ticket_operate_doing[] = {NULL, NULL, NULL, NULL, NULL, NULL};
char* admin_main_title = "管理员选项";
int admin_main_count = 4;
char* admin_main_items[] = {"注册管理员", "管理员登录", "计算会员数量", "返回主菜单"};
act admin_main_doing[] = {NULL, NULL, NULL};
char* admin_logined_title = "管理员选项";
int admin_logined_count = 4;
char* admin_logined_items[] = {"注册管理员", "管理员登录", "计算会员数量", "返回主菜单"};
act admin_logined_doing[] = {NULL, NULL, NULL};
char* vip_main_title = "会员主菜单";
int vip_main_count = 5;
char* vip_main_items[] = {"注册会员", "会员登录", "新入会员", "会员人数", "回主菜单"};
act vip_main_doing[] = {NULL, NULL, NULL, NULL};
char* vip_logined_title = "会员操作";
int vip_logined_count = 5;
char* vip_logined_items[] = {"查询机票信息", "购买机票", "查询个人信息", "修改密码", "返回主菜单"};
act vip_logined_doing[] = {NULL, NULL, NULL, NULL};
char* vip_info_title = "会员信息";
int vip_info_count = 5;
char* vip_info_items[] = {"会员个数", "清空数据", "删除会员", "展示会员", "回主菜单"};
act vip_info_doing[] = {NULL, NULL, NULL, NULL};
Ticket* getTicket(int number){
Ticket* ticket = (Ticket*)malloc(sizeof(Ticket));
memset(ticket, 0, sizeof(Ticket));
printf("请输入起飞时间\n");
scanf("%s", ticket->TTime);
printf("请输入降落时间\n");
scanf("%s", ticket->ATime);
printf("请输入起飞城市\n");
scanf("%s", ticket->TCity);
printf("请输入降落城市\n");
scanf("%s", ticket->ACity);
printf("请输入价格\n");
scanf("%f", &ticket->Price);
printf("请输入折扣\n");
scanf("%f", &ticket->Discount);
printf("请输入剩余票量\n");
scanf("%d", &ticket->Count);
ticket->AIRNumber = number;
return (ticket);
}
void addTicket(Ticket* last){
char sure = 'n';
Ticket* ticket = getTicket(last->AIRNumber + 1);
ticket->next = last->next;
printf("Number: %0.0f, Time: %s -> %s, City: %s -> %s, Price: %0.2f, Discount: %0.2f, Count: %d, are you sure?",
ticket->AIRNumber, ticket->TTime, ticket->ATime, ticket->TCity, ticket->ACity, ticket->Price, ticket->Discount, ticket->Count);
fflush(stdin);
sure = getchar();
if('y' == sure){
last->next = ticket;
} else {
free(ticket);
}
}
int choice(int argc, char* argv[], char* title){
system("cls");
system("time/t");
int c = -1;
printf("\n\n\n\n");
printf("\t\t\t\t");
int start = (45 - strlen(title)) / 2;
for(int i = 0; i < start; i++){
printf(" ");
}
printf("%s\n", title);
printf("\t\t\t\t +--------------------------------------+\n");
for(int i = 0; i < argc; i++){
printf("\t\t\t\t |%2d.%-35s|\n", i + 1, argv[i]);
}
printf("\t\t\t\t +--------------------------------------+\n");
printf("\t\t\t\t 请输入您的选择:");
scanf("%d", &c);
return (c);
}
int select(char* title, int count, char* items[], act doing[]){
int index = -1;
while((index = choice(count, items, title)) != count){
if(0 < index && index < count && NULL != doing[index - 1]){
doing[index - 1]();
}
}
return (index);
}
void vip(){
select(vip_main_title, vip_main_count, vip_main_items, vip_main_doing);
}
void admin(){
select(admin_main_title, admin_main_count, admin_main_items, admin_main_doing);
}
int main(){
system("color 5f");//改变界面颜色
//select(cover_system_title, cover_system_count, cover_system_items, cover_system_doing);
Ticket* head = (Ticket*)malloc(sizeof(Ticket));
memset(head, 0, sizeof(Ticket));
addTicket(head);
return (0);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct tagPerson{
char name[35];
int password;
//...
}person;
typedef struct tagTicket{
char startTime[35];
char endTime[35];
//...
}ticket;
typedef void (*act)();
void vip();
void admin();
char* cover_system_title = "欢迎光临大中华机票购买系统";
int cover_system_count = 3;
char* cover_system_items[] = {"进入会员相关界面", "进入管理员相关界面", "退出系统"};
act cover_system_doing[] = {vip, admin};
char* ticket_operate_title = "机票操作项";
int ticket_operate_count = 7;
char* ticket_operate_items[] = {"录入机票", "展示机票", "机票种类", "摧毁机库", "补充机票", "删除机票", "返回上级"};
act ticket_operate_doing[] = {NULL, NULL, NULL, NULL, NULL, NULL};
char* admin_main_title = "管理员选项";
int admin_main_count = 4;
char* admin_main_items[] = {"注册管理员", "管理员登录", "计算会员数量", "返回主菜单"};
act admin_main_doing[] = {NULL, NULL, NULL};
char* admin_logined_title = "管理员选项";
int admin_logined_count = 4;
char* admin_logined_items[] = {"注册管理员", "管理员登录", "计算会员数量", "返回主菜单"};
act admin_logined_doing[] = {NULL, NULL, NULL};
char* vip_main_title = "会员主菜单";
int vip_main_count = 5;
char* vip_main_items[] = {"注册会员", "会员登录", "新入会员", "会员人数", "回主菜单"};
act vip_main_doing[] = {NULL, NULL, NULL, NULL};
char* vip_logined_title = "会员操作";
int vip_logined_count = 5;
char* vip_logined_items[] = {"查询机票信息", "购买机票", "查询个人信息", "修改密码", "返回主菜单"};
act vip_logined_doing[] = {NULL, NULL, NULL, NULL};
char* vip_info_title = "会员信息";
int vip_info_count = 5;
char* vip_info_items[] = {"会员个数", "清空数据", "删除会员", "展示会员", "回主菜单"};
act vip_info_doing[] = {NULL, NULL, NULL, NULL};
int choice(int argc, char* argv[], char* title){
system("cls");
system("time/t");
int c = -1;
printf("\n\n\n\n");
printf("\t\t\t\t");
int start = (45 - strlen(title)) / 2;
for(int i = 0; i < start; i++){
printf(" ");
}
printf("%s\n", title);
printf("\t\t\t\t +--------------------------------------+\n");
for(int i = 0; i < argc; i++){
printf("\t\t\t\t |%2d.%-35s|\n", i + 1, argv[i]);
}
printf("\t\t\t\t +--------------------------------------+\n");
printf("\t\t\t\t 请输入您的选择:");
scanf("%d", &c);
return (c);
}
int select(char* title, int count, char* items[], act doing[]){
int index = -1;
while((index = choice(count, items, title)) != count){
if(0 < index && index < count && NULL != doing[index - 1]){
doing[index - 1]();
}
}
return (index);
}
void vip(){
select(vip_main_title, vip_main_count, vip_main_items, vip_main_doing);
}
void admin(){
select(admin_main_title, admin_main_count, admin_main_items, admin_main_doing);
}
int main(){
system("color 5f");//改变界面颜色
select(cover_system_title, cover_system_count, cover_system_items, cover_system_doing);
return (0);
}
void CreatePlaneListF(System *&phead, int n)//机票录入//头插法建立单链表
{
System *p; //小指针,指向System
int i;//计数器
phead = (System *)malloc(sizeof(System)); //创建头结点
phead->AIRNumber = 747000;//号码自增,从100000开始
phead->next = NULL;
printf("请依次输入您的信息:\n");
for (i = 0; i<n; i++)
{
p = (System *)malloc(sizeof(System));//创建新结点
printf("请输入起飞时间\n");
scanf("%s", p->TTime);
printf("请输入降落时间\n");
scanf("%s", p->ATime);
printf("请输入起飞城市\n");
scanf("%s", p->TCity);
printf("请输入降落城市\n");
scanf("%s", p->ACity);
printf("请输入价格\n");
scanf("%f", &p->Price);
printf("请输入折扣\n");
scanf("%f", &p->Discount);
printf("请输入剩余票量\n");
scanf("%d", &p->Count);
p->AIRNumber = phead->AIRNumber + 1;//号码自增
P->AIRNumber++;//号码自增
p->next = phead->next; //将*s插在原开始结点之前,头结点之后
phead->next = p;
}
//phead->next = NULL; /*这一句把所有申请的节点弄没了*/
}
能用两个不同的变量名,就不要用大小区分的变量名。一会大写,一会小写,不自信看不好看明白void CreatePlaneListF(System *&P, int n)//机票录入//头插法建立单链表
{
System *p; //小指针,指向System
int i;//计数器
P = (System *)malloc(sizeof(System)); //创建头结点
P->AIRNumber = 747000;//号码自增,从100000开始
P->next = NULL;
printf("请依次输入您的信息:\n");
for (i = 0; i<n; i++)
{
p = (System *)malloc(sizeof(System));//创建新结点
printf("请输入起飞时间\n");
scanf("%s", p->TTime);
printf("请输入降落时间\n");
scanf("%s", p->ATime);
printf("请输入起飞城市\n");
scanf("%s", p->TCity);
printf("请输入降落城市\n");
scanf("%s", p->ACity);
printf("请输入价格\n");
scanf("%f", &p->Price);
printf("请输入折扣\n");
scanf("%f", &p->Discount);
printf("请输入剩余票量\n");
scanf("%d", &p->Count);
p->AIRNumber = P->AIRNumber + 1;//号码自增
P->AIRNumber++;//号码自增
p->next = P->next; //将*s插在原开始结点之前,头结点之后
P->next = p;
}
//P->next = NULL; /*这一句把所有申请的节点弄没了*/
}
去掉%s后面的&取地址符,因为数组名本身就是地址嘛
去掉P->next = NULL;不然,你创建的节点全没了,就剩头结点了。
//以下为管理员相关函数
void CreateAdmminListF(System *&A, int n)//会员注册 //头插法建立单链表
{
System *a; //小指针,指向vip
int i;//计数器
A = (System *)malloc(sizeof(System)); //创建头结点
A->next = NULL;
printf("请依次输入您的信息:\n");
for (i = 0; i<n; i++)
{
a = (System *)malloc(sizeof(System));//创建新结点
printf("请输入您的姓名\n");
scanf("%s", &a->AdminName);
getchar();
printf("请输入您的密码\n");
scanf("%f", &a->AdminPassword);
a->next = A->next; //将*s插在原开始结点之前,头结点之后
A->next = a;
}
}
void InitAdmminList(System *&A)//初始化链表
{
A = (System *)malloc(sizeof(System)); //创建头结点
A->next = NULL;
}
char AdmminNameJudgement(System *A, char *aname)//管理员姓名验证模块
{
System *a = A->next;
int n = 1;
while (a != NULL&&strcmp(a->AdminName, aname) != 0)
{
a = a->next;
n++;
}
if (a == NULL)
return (0);
else
return (n);
}
char AdmminPasswordJudgement(System *A, float pw)//管理员密码验证模块
{
System *a = A->next;
int n = 1;
while (a != NULL&&a->AdminPassword != pw)
{
a = a->next;
n++;
}
if (a == NULL)
return (0);
else
return (n);
}
void AdminFunctions();
char AdmminLogInedMenu(System *A, char *name)//管理员登陆后界面
{
float Number;
float number;
int n;
int i;//选择器
printf("\n\n\n\n");
printf("\t\t\t\t -------------------------------------\n");
printf("\t\t\t\t | 1.航班信息操作 |\n");
printf("\t\t\t\t | 2.计算会员人数 |\n");
printf("\t\t\t\t | 6.返回主菜单 |\n");
scanf("%d", &i);
switch (i)
{
case 1:
Airplane();
break;
case 2:
VIPInfos();
break;
case 6:
AdminFunctions();
break;
default:
printf("输入有误\n");
break;
}
return 0;
}
void AdmminLogIn(System *A)//管理员登录验证功能函数
{
System *p = A->next;
int r;//获取【输入的值与库中姓名比较的结果】,其值是0或1
float pw;//暂存密码,密码验证 2
char sname[35];//暂存姓名,通过姓名验证 1
printf("请输入管理员名\n");
scanf("%s", &sname);//键入姓名
r = AdmminNameJudgement(A, sname);
if (r == 0)
{
printf("管理员名输入错误!请重新输入!\n");
AdmminLogIn(A);
}
else
{
printf("请输入密码:\n");
scanf("%f", &pw);
r = AdmminPasswordJudgement(A, pw);
if (r == 0)
{
printf("管理员密码错误!请重新输入!\n");
AdmminLogIn(A);
}
else
AdmminLogInedMenu(A, sname);
}
}
void AdminFunctions()
{
System *A = NULL;
// System *P = NULL;
float password;
int i, j, r;
do {
printf("\n\n\n\n");
printf("\t\t\t\t -------------------------------------\n");
printf("\t\t\t\t | 主菜单 |\n");
printf("\t\t\t\t | 1 注册管理员 |\n");//注册管理员
printf("\t\t\t\t | 2 管理员登录 |\n");//显示管理员信息
printf("\t\t\t\t | 3 计算会员数量 |\n");
printf("\t\t\t\t | 4 回到主菜单 |\n");
printf("\t\t\t\t | 0 退出 |\n");
printf("\t\t\t\t -------------------------------------\n");
printf("请输入您选择的操作:");
scanf("%d", &i);
switch (i)
{
case 1:
if (A == NULL)
{
j = 1;
CreateAdmminListF(A, j);
}
else
{
printf("管理员已经创建,不能重复建立.\n");
}
break;
case 2:
AdmminLogIn(A);//登录功能,先验证用户名再验证密码
break;
case 3:
printf("%d", ListVIPLength(A));
break;
case 4:
main();//登录功能,先验证用户名再验证密码
break;
case 0:
exit(0);
default:
printf("输入有误,请重新输入\n");
break;
}
} while (1);
}
void main()
{
int i;//选择器
system("color 5f");//改变界面颜色
system("time/t");//显示当前时间
printf("\n\n\n\n\n\n\n\n");
printf("\t\t\t\t -------------------------------------\n");
printf("\t\t\t\t | 欢迎光临大中华机票购买系统 |\n");
printf("\t\t\t\t | 1.进入会员相关界面 |\n");
printf("\t\t\t\t | 2.进入管理员相关界面 |\n");
printf("\t\t\t\t | 请选择您要的功能: |\n");
printf("\t\t\t\t -------------------------------------\n");
scanf("%d", &i);
switch (i)
{
case 1:
VIPFunctions();
break;
case 2:
AdminFunctions();
break;
default:
printf("输入有误,请重新输入\n");
main();
break;
}
}
//以下为会员函数
void VIPFunctions();
void CreateVIPListF(System *&V, int n)//会员注册 //头插法建立单链表
{
System *v; //小指针,指向vip
int i;//计数器
V = (System *)malloc(sizeof(System)); //创建头结点
V->VIPNumber = 100000;//号码自增,从100000开始
V->next = NULL;
printf("请依次输入您的信息:\n");
for (i = 0; i<n; i++)
{
v = (System *)malloc(sizeof(System));//创建新结点
printf("请输入您的姓名\n");
scanf("%s", &v->VIPName);
getchar();
printf("请输入您的密码\n");
scanf("%f", &v->VIPPassword);
printf("请输入您的生日\n");
scanf("%s", &v->Birthday);
getchar();
printf("请输入您的邮箱\n");
scanf("%s", &v->EmailAddress);
v->VIPNumber = V->VIPNumber + 1;//号码自增
V->VIPNumber++;//号码自增
v->next = V->next; //将*s插在原开始结点之前,头结点之后
V->next = v;
}
}
void InitVIPList(System *&V)//初始化链表
{
V = (System *)malloc(sizeof(System)); //创建头结点
V->next = NULL;
}
void DestroyVIPList(System *&V)//删除所有会员,递归操作
{
if (V == NULL)
{
return;
}
else
{
DestroyVIPList(V->next);
free(V);
}
}
void DisplayAllVIPlist(System *V)//展示所有的会员及相关信息,递归操作
{
if (V == NULL)
{
return;
}
else
{
printf("会员:%s\n,您的信息为:\n", V->VIPName);
printf("您的密码是:%.0f\n", V->VIPPassword);
printf("您的生日是:%s\n", V->Birthday);
printf("您的邮箱是:%s\n", V->EmailAddress);
printf("您的序列号是:%0.f\n", V->VIPNumber);
printf("\n\n");
DisplayAllVIPlist(V->next);
}
}
int DispSingleVIPList(System *V, char *tempname)
{
System *v = V->next;
int n = 1;
;
while (v != NULL&&strcmp(v->VIPName, tempname) != 0)
{
v = v->next;
}
if (v == NULL)
{
printf("不存在\n");
}
else
{
printf("您的名字是:%s\n", v->VIPName);
printf("您的密码是:%.0f\n", v->VIPPassword);
printf("您的生日是:%s\n", v->Birthday);
printf("您的邮箱是:%s\n", v->EmailAddress);
printf("您的序列号是:%0.f\n", v->VIPNumber);
printf("\n");
}
return 0;
}
void ChangeVIPPassword(System *V, char *name)//修改密码
{
System *v = V->next;
int temp;
temp = strcmp(v->VIPName, name);
while (v != NULL)
{
if (temp == 0)
{
printf("请输入您的新密码\n");
scanf("%f", &v->VIPPassword);
printf("修改完成\n");
VIPFunctions();
}
else
{
printf("居然不存在?\n");
}
}
printf("\n");
}
char VIPNameJudgement(System *V, char *name)//会员姓名验证模块
{
System *v = V->next;
int n = 1;
while (v != NULL&&strcmp(v->VIPName, name) != 0)
{
v = v->next;
n++;
}
if (v == NULL)
return (0);
else
return (n);
}
char VIPPasswordJudgement(System *V, float pw)//会员密码验证模块
{
System *v = V->next;
int n = 1;
while (v != NULL&&v->VIPPassword != pw)
{
v = v->next;
n++;
}
if (v == NULL)
return (0);
else
return (n);
}
char VIPLogInedMenu(System *V, char *name)//会员登陆后界面
{
float Number;
char tempname[35];//临时存名字
strcpy(tempname, name);
int i;//选择器
printf("\t\t\t\t -------------------------------------\n");
printf("\t\t\t\t | 1.查询机票信息 |\n");
printf("\t\t\t\t | 2.购买机票 |\n");
printf("\t\t\t\t | 3.查询个人信息 |\n");
printf("\t\t\t\t | 4.修改密码 |\n");
printf("\t\t\t\t | 5.返回主菜单 |\n");
printf("\t\t\t\t | 请选择功能 |\n");
printf("\t\t\t\t -------------------------------------\n");
scanf("%d", &i);
switch (i)
{
case 1:
DispAllPlane(V);
break;
case 2:
printf("请输入您要购买的机票序列号:\n");
scanf("%f", &Number);
V->VIPPlaneNumber = Number;
printf("购买成功!\n");
break;
case 3:
DispSingleVIPList(V, tempname);//展示个人信息
break;
case 4:
ChangeVIPPassword(V, tempname);
//打到个人信息,修改密码
break;
case 5:
VIPFunctions();
break;
default:
printf("输入有误\n");
break;
}
return 0;
}
void VIPLogIn(System *V)//会员登录验证功能函数
{
System *p = V->next;
int r;//获取【输入的值与库中姓名比较的结果】,其值是0或1
float pw;//暂存密码,密码验证 2
char sname[35];//暂存姓名,通过姓名验证 1
printf("请输入会员名\n");
scanf("%s", &sname);//键入姓名
r = VIPNameJudgement(V, sname);
if (r == 0)
{
printf("该会员不存在!请重新输入!\n");
VIPLogIn(V);
}
else
{
printf("请输入密码:\n");
scanf("%f", &pw);
r = VIPPasswordJudgement(V, pw);
if (r == 0)
{
printf("密码错误!请重新输入!\n");
VIPLogIn(V);
}
else
VIPLogInedMenu(V, sname);
}
}
int ListVIPLength(System *V)//计算会员个数,递归操作
{
int i = 0;
if (V->next == NULL)
{
return 0;
}
else
{
return ListVIPLength(V->next) + 1;
}
}
bool ListVIPInsert(System *&V, int i, char *name, float password, char *birthday, char *emailaddress)//插入到特定值后
{
int j = 0;
System *v = V, *s;
ListVIPLength(V);
while (j<i - 1 && v != NULL) //查找第i-1个结点
{
j++;
v = v->next;
}
if (v == NULL) //未找到位序为i-1的结点
return false;
else //找到位序为i-1的结点*p
{
s = (System *)malloc(sizeof(System));//创建新结点*s
strcpy(s->VIPName, name);
s->VIPPassword = password;
strcpy(s->Birthday, birthday);
strcpy(s->EmailAddress, emailaddress);
s->next = v->next; //将*s插入到*p之后
v->next = s;
return true;
}
}
void DelectSingleVIP(System *&V, float number)
{
System *temp;
if (V == NULL)
{
return;
}
else if (number = V->VIPNumber)
{
temp = V;
V = V->next;
free(temp);
return;
}
else
{
DelectSingleVIP(V->next, number);
}
}
void VIPInfos()//会员相关操作
{
System *V = NULL;
char name[35];
float password;
char birthday[45];
char emailaddress[40];
float tempnumber;
int i, j;
bool re;
do {
printf("\t\t\t\t -------------------------------------\n");
printf("\t\t\t\t | 会员信息操作界面 |\n");
printf("\t\t\t\t | 1 求会员个数 |\n");//求会员数量
printf("\t\t\t\t | 2 清空数据 |\n");//递归摧毁链表
printf("\t\t\t\t | 3 删除会员 |\n");//删会员
printf("\t\t\t\t | 4 展示会员 |\n");//展示所有会员
printf("\t\t\t\t | 5 回主菜单 |\n");
printf("\t\t\t\t | 0 退出 |\n");
printf("\t\t\t\t -------------------------------------\n");
printf("请输入您选择的操作:");
scanf("%d", &i);
switch (i)
{
case 1:
printf("会员个数为:%d\n", ListVIPLength(V));
break;
case 2:
DestroyVIPList(V);
printf("会员信息清空完毕\n");
break;
case 3://按照序列号删除,递归操作
printf("请输入要删除的会员号码");
scanf("%f", &tempnumber);
DelectSingleVIP(V, tempnumber);
printf("删除完成\n");
break;
case 4:
DisplayAllVIPlist(V);
break;
case 5:
main();
break;
case 0:
exit(0);
default:
printf("输入有误,请重新输入\n");
break;
}
} while (1);
}
void VIPFunctions()//会员相关操作
{
System *V = NULL;
char name[35];
float password;
char birthday[45];
char emailaddress[40];
float tempnumber;
int i, j;
bool re;
do {
printf("\t\t\t\t -------------------------------------\n");
printf("\t\t\t\t | 主菜单 |\n");
printf("\t\t\t\t | 1 注册会员 |\n");//注册会员
printf("\t\t\t\t | 2 会员登录 |\n");//显示个人信息
printf("\t\t\t\t | 3 新入会员 |\n");//加会员
printf("\t\t\t\t | 4 会员人数 |\n");//求会员数量
/* printf("\t\t\t\t | 5 清空数据 |\n");//递归摧毁链表
printf("\t\t\t\t | 6 删除会员 |\n");//删会员*/
printf("\t\t\t\t | 7 回主菜单 |\n");
printf("\t\t\t\t | 0 退出 |\n");
printf("\t\t\t\t -------------------------------------\n");
printf("请输入您选择的操作:");
scanf("%d", &i);
switch (i)
{
case 1:
if (V == NULL)
{
printf("请输入要创建会员的个数:");
scanf("%d", &j);
CreateVIPListF(V, j);
}
else
{
printf("会员库已经创建,不能重复建立.\n");
}
break;
case 2:
VIPLogIn(V);//登录功能,先验证用户名再验证密码
break;
case 3://算出会员个数
//插入新会员,先算会员数量,然后加一
j = ListVIPLength(V) + 1;
printf("请输入您的相关信息:\n");
printf("请输入您的用户名:\n");
scanf("%s", &name);
printf("请输入您的密码:\n");
scanf("%f", &password);
printf("请输入您的生日:\n");
scanf("%s", &birthday);
printf("请输入您的邮编地址:\n");
scanf("%s", &emailaddress);
re = ListVIPInsert(V, j, name, password, birthday, emailaddress);
if (re)
printf("插入成功\n");
else
printf("插入失败\n");
break;
case 4://摧毁链表
printf("会员个数为:%d\n", ListVIPLength(V));
break;
case 5:
DestroyVIPList(V);
break;
case 6://按照序列号删除,递归操作
printf("请输入会员号码");
scanf("%f", &tempnumber);
DelectSingleVIP(V, tempnumber);
printf("删除完成\n");
break;
case 7:
main();
case 0:
exit(0);
default:
printf("输入有误,请重新输入\n");
break;
}
} while (1);
}
void Airplane()//机票相关操作在这里
{
System *P = NULL;
char TTime[35];
char ATime[35];
char TCity[35];
char ACity[35];
float Price;
float Discount;
int Count;
float tempnumber;
int i, j, r;
int e;
bool re;
do {
printf("\t\t\t\t -------------------------------------\n");
printf("\t\t\t\t | 主菜单 |\n");
printf("\t\t\t\t | 1 录入机票 |\n");//添加机票
printf("\t\t\t\t | 2 展示机票 |\n");//
printf("\t\t\t\t | 3 求机票种类数 |\n");//求机票
printf("\t\t\t\t | 4 摧毁机库 |\n");//递归摧毁机票库
printf("\t\t\t\t | 6 补充机票 |\n");//添加机票
printf("\t\t\t\t | 7 删除机票 |\n");//删除机票
printf("\t\t\t\t | 0 退出 |\n");
printf("\t\t\t\t -------------------------------------\n");
printf("请输入您选择的操作:");
scanf("%d", &i);
switch (i)
{
case 1:
if (P == NULL)
{
printf("请输入要创建机票的种类数:");
scanf("%d", &j);
CreatePlaneListF(P, j);
}
else
{
printf("机票库已经创建,不能重复建立.\n");
}
break;
case 2://展示
DispAllPlane(P);
break;
case 3://算出机票个数
printf("机票个数为:%d\n", ListPlaneLength(P));
break;
case 4://递归摧毁
DestroyPlaneList(P);
break;
case 6://插入新机票,先算机票数量,然后加一
j = ListPlaneLength(P) + 1;
printf("请输入起飞时间\n");
scanf("%s", &TTime);
getchar();
printf("请输入降落时间\n");
scanf("%s", &ATime);
getchar();
printf("请输入起飞城市\n");
scanf("%s", &TCity);
getchar();
printf("请输入降落城市\n");
scanf("%s", &ACity);
getchar();
printf("请输入价格\n");
scanf("%f", &Price);
printf("请输入折扣\n");
scanf("%f", &Discount);
printf("请输入剩余票量\n");
scanf("%d", &Count);
re = ListPlaneInsert(P, j, TTime, ATime, TCity, ACity, Price, Discount, Count);
if (re)
printf("插入成功\n");
else
printf("插入失败\n");
break;
case 7://删除旧机票信息,按照序列号改
scanf("%f", &tempnumber);
DeleteSinglePlane(P, tempnumber);
break;
case 0:
exit(0);
default:
printf("输入有误,请重新输入\n");
break;
}
} while (1);
}