#include<stdio.h>
#include<stdlib.h>
typedef struct node List;
//typedef (List*)malloc(sizeof(List)) creak;
struct node
{
int car_num;
int enter_h;
int enter_m;
int out_h;
int out_m;
List *next;
};
FILE *fp;
List *Head;
void prime_menu();
List *Add_car_information();
void Find_car_information();
void Out_car();
char name[1000];
int main()
{
puts("欢迎,进入停车系统");
prime_menu();
return 0;
}
int menu()
{
puts("停车,请输入’1‘");
puts("查询,请输入’2‘");
puts("泊车,请输入‘3’");
puts("退出,请输入‘0’");
int n;
do
{
scanf("%d", &n);
} while (n < 0 || n>3);
return n;
}
void prime_menu()
{
int flag = 1;
while (1)
{
if (flag == 0)
break;
switch (menu())
{
case 1:
Head = Add_car_information(); break;
case 2:
Find_car_information(); break;
case 3:
Out_car(); break;
case 0:
flag = 0; break;
default:
puts("Goodbay"); flag = 0;
}
}
}
List *Add_car_information()
{
List *head, *tail, *p;
puts("1.请输入车牌号,输入的时间格式‘15:11’,数据间用空格隔开");
puts("2.请使用英文输入法");
puts("3.输入车牌号为'-1'时,输入结束");
puts("4.仅输入车牌中的数字");
puts("5.默认将数据都入到'car_park1'文本中");
head = (List*)malloc(sizeof(List));
head->next = NULL;
p = head;
while (1)
{
tail = (List*)malloc(sizeof(List));
puts("请输入车牌号");
scanf("%d", &tail->car_num);
if (tail->car_num == -1)
break;
puts("请输入停车时间");
scanf("%d:%d", &tail->enter_h, &tail->enter_m);
puts("请输入泊车时间");
scanf("%d:%d", &tail->out_h, &tail->out_m);
if ((fp = fopen("car_park1", "w")) == NULL)
{
puts("can't open file");
return NULL;
}
fprintf(fp, "%d %d:%d %d:%d\n", tail->car_num, tail->enter_h, tail->enter_m, tail->out_h, tail->out_m);
fclose(fp);
p->next = tail;
p = tail;
}
p->next = NULL;
return head->next;
}
void Find_car_information()
{
puts("请输入车牌号");
int num;
scanf("%d", &num);
List *L = Head;
if (L == NULL)
{
puts("没有该车辆信息,请重新查找");
return;
}
else
{
while (L)
{
if (L->car_num == num)
{
printf("车牌号 :%d\n", num);
printf("停车时间 :%d:%d\n", L->enter_h, L->enter_m);
printf("泊车时间 :%d:%d\n", L->out_h, L->out_m);
//break;
return;
}
L = L->next;
}
puts("没有该车辆信息,请重新查找");
return;
}
}
void Out_car()
{
puts("请输入车牌号泊车");
int pos;
scanf("%d", &pos);
List *P = NULL, *L;
L = Head;
if (L == NULL)
P = NULL;
else
{
while (L)
{
if (L->car_num == pos)
{
P = L;
break;
}
L = L->next;
}
}
L = Head;
if (P == NULL || L == NULL)
{
puts("停车场不存在该车辆信息,请重新输入");
return;
}
else
{
if (P == L)
{
Head = Head->next;
puts("取车成功");
return;
}
else
{
while (L->next != NULL&&L->next != P)
L = L->next;
if (L->next != P)
{
puts("停车场不存在该车辆信息,请重新输入");
return;
}
else
{
L->next = L->next->next;
puts("取车成功");
return;
}
}
}
}
/*
void delete1()
{
puts(" please intput position");
int pos;
cin >> pos;
Position *P = Findnum(pos);
List *L = Head;
if (P == false)
{
puts(" Delete error,please intput right position");
return;
}
if (L == NULL || pos == NULL)
{
puts(" Delete error,please intput right position");
return;
}
else
{
if (P == L)
{
L->book_num--;
if (!L->book_num)
{
L = L->next;
Head = L;
}
puts(" Delete success");
return;
}
else
{
while (L->next != NULL&&L->next != P)
L = L->next;
if (L->next != P)
{
puts(" Delete error,please intput right position");
return;
}
else
{
L->next->book_num--;
if (!L->next->book_num)
{
L->next = L->next->next;
}
puts(" Delete success");
}
}
}
}
*/
nitC语言大作业 停车信息管理系统
最新推荐文章于 2024-06-16 09:38:50 发布