求问使用了链表的航班管理系统在VS2015上出错很多

黑葉 2019-04-18 09:59:22
报错有:
->custname的左边必须指向类/结构/联合/泛指类型
“p”:未声明的标识符
等,请问这是什么原因?
代码如下:(原本分了文件但为了提问方便我全塞一个文件里了)
#include <cstring>
#include <iostream>
using namespace std;
void menu();
void flight_insert();
void flight_delete();
void ticket_book();
void ticket_cancle();
void customer_show();
void flight_show();
typedef struct Flight
{
char start_address[20];
char des_address[20];
char flightNum[10];
char planeNum[10];
int Ration;
int freeTicket;
float prize;
Customer *custname;
struct Flight*next;
};Flight;
typedef struct Customer
{
char Name[20];
char ID[20];
int tickets;
int seatnum;
char flightnum[10];
struct Customer *next;
};Customer;
Flight *head;
Flight *rear;
Customer *chead;
Customer *crear;
int m = 0;
void menu()
{
int choice = 1;
for (;choice != 0;)
{
std::cout << "Welcome to this flight management system!" << endl;
std::cout << "-----------------------------------------------------------------" << endl;
std::cout << "I'm customer:" << endl;
std::cout << "1.book ticket 2.show the ticket 3.cancle ticket" << endl;
std::cout << "-------------------------------------------------------" << endl;
std::cout << "I'm manager:" << endl;
std::cout << "4.insert flight 5.delete flight 6.show the customer" << endl;
std::cout << "-------------------------------------------------------" << endl;
std::cout << "0.exit" << endl;
std::cin >> choice;
switch (choice)
{
case 1:ticket_book(); break;
case 2:flight_show(); break;
case 3:ticket_cancle(); break;
case 4:flight_insert(); break;
case 5:flight_delete(); break;
case 6:customer_show(); break;
default:std::cout << "error!" << endl; break;
}
}
}
void flight_insert()
{
Flight *p;
m++;
int M = m;
p = new Flight;
if (m == 0) head = p;
else
{
head->next = p;
for (;M > 1;M--) p = p->next;
}
std::cout << "----------------------------------" << endl;
std::cout << "Please enter the starting address:" << endl;
std::cin >> p->start_address;
std::cout << "Please enter the destination:" << endl;
std::cin >> p->des_address;
std::cout << "Please enter the number of the flight:" << endl;
std::cin >> p->flightNum;
std::cout << "Please enter the number of the plane:" << endl;
std::cin >> p->planeNum;
std::cout << "Please enter the tickets that can be booked:" << endl;
std::cin >> p->Ration;
p->freeTicket = p->Ration;
std::cout << "Please enter the prize of the ticket:" << endl;
std::cin >> p->prize;
p->custname = new Customer;
p->custname->next = NULL;
rear = p;
rear->next = NULL;
}
void flight_delete()
{
Flight *p;
char Flightnum[10];
p = head;
int i = 0;
while (i != 1)
{
std::cout << "-------------------------------" << endl;
std::cout << "Please enter the flight number:" << endl;
std::cin >> Flightnum;
while (p->next&&strcmp(p->flightNum, Flightnum))
{
p = p->next;
}
if (p != NULL) p->next = p->next->next;
else std::cout << "Not Found!" << endl;
std::cout << "1.exit 2.continue" << endl;
std::cin >> i;
}
}
void customer_show()
{
Flight *p;
char Flightnum[10];
p = head;
int i = 0;
while (i != 1)
{
std::cout << "-------------------------------" << endl;
std::cout << "Please enter the flight number:" << endl;
std::cin >> Flightnum;
while (p->next&&strcmp(p->flightNum, Flightnum))
{
p = p->next;
}
p->custname = chead;
if (p != NULL)
{
while (p->custname)
{
std::cout << p->custname->Name << endl;
std::cout << p->custname->tickets << endl;
std::cout << p->custname->seatnum << endl << endl;
p->custname = p->custname->next;
}
}
else
{
std::cout << "Not Found!" << endl;
}
std::cout << "1.exit 2.continue" << endl;
std::cin >> i;
}
}
void buy_ticket(Flight *f, int t)
{
Flight *f1;
Customer *c1;
c1 = new Customer;
int n;
n = f->Ration - f->freeTicket;
if (n == 0)
{
f->custname = c1;
}
else
{
f->custname->next = c1;
for (;n > 1;n--)
{
c1 = c1->next;
}
}
f->freeTicket -= t;
std::cout << "Please enter your name:" << endl;
cin >> c1->Name;
std::cout << "Please enter your ID:" << endl;
cin >> c1->ID;
c1->tickets = t;
c1->seatnum = f->Ration - f->freeTicket + 1;
strcpy_s(c1->flightnum, f->flightNum);
crear = c1;
crear->next = NULL;
}
void ticket_book()
{
Flight *p;
char start[20];
char des[20];
int ticket_amount;
int i = 2;
std::cout << "-----------------------------------" << endl;
std::cout << "Please enter your starting address:" << endl;
std::cin >> start;
std::cout << "Please enter your destination:" << endl;
cin >> des;
p = head;
while (p->next&&strcmp(p->start_address, start))
{
p = p->next;
}
while (p->des_address != des)
{
while (p->next&&strcmp(p->start_address, start))
{
p = p->next;
}
}
if (p == NULL)
{
std::cout << "Not Found!" << endl;
}
else
{
while (i != 1)
{
std::cout << "How many tickets do you need to book?" << endl;
cin >> ticket_amount;
while (ticket_amount == 0)
{
std::cout << "Please enter a number bigger than 0:" << endl;
cin >> ticket_amount;
}
if (ticket_amount <= p->freeTicket)
{
buy_ticket(p, ticket_amount);
}
else
{
std::cout << "The rest seats is not enough!" << endl;
}
std::cout << "1.return to the menu 2.continue" << endl;
cin >> i;
}
}
std::cout << "1.exit 2.continue" << endl;
cin >> i;
}
void flight_show()
{
Flight *p;
Customer *c;
char id[20];
p = head;
int i = 0;
while (i != 1)
{
std::cout << "-----------------------" << endl;
std::cout << "Please enter your ID:" << endl;
cin >> id;
while (p->next&&strcmp(p->custname->ID, id))
{
c = p->custname;
while (c->next&&strcmp(c->ID, id))
{
c = c->next;
}
if (strcmp(c->ID, id)) break;
p = p->next;
}
if (!strcmp(c->ID, id)) std::cout << "Not Found!" << endl;
else
{
cout << "Your flight:" << endl;
cout << p->start_address << endl;
cout << p->des_address << endl;
cout << p->flightNum << endl;
cout << p->planeNum << endl;
cout << p->Ration << endl;
cout << p->freeTicket << endl;
cout << p->prize << endl;
}
std::cout << "1.exit 2.continue" << endl;
std::cin >> i;
}
}
void ticket_cancle()
{
Flight *p;
Customer *c, *d = nullptr;
char flightnum[20], id[20];
p = head;
int i = 0;
while (i != 1)
{
cout << "--------------------------------------" << endl;
cout << "Please enter the number of the flight:" << endl;
cin >> flightnum;
cout << "Please enter your ID:" << endl;
cin >> id;
while (p->next&&strcmp(p->flightNum, flightnum))
{
p = p->next;
}
if (!strcmp(p->flightNum, flightnum)) cout << "Not Found!" << endl;
else
{
c = p->custname;
while (c->next&&strcmp(c->ID, id))
{
c = c->next;
}
if (!strcmp(c->ID, id)) cout << "Not Found!" << endl;
else
{
if (c->next == NULL)
{
d->next = c;
d->next = NULL;
delete c;
crear = d;
}
else
{
d->next = c;
d->next = d->next->next;
delete c;
}
p->freeTicket++;
}
}
std::cout << "1.exit 2.continue" << endl;
std::cin >> i;
}
}
int main()
{
void menu();
return 0;
}
...全文
42 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
幻夢之葉 2019-04-18
  • 打赏
  • 举报
回复
Customer *custname; struct Flight*next; };Flight; typedef struct Customer { char Name[20]; char ID[20]; int tickets; int seatnum; char flightnum[10]; struct Customer *next; };Customer; 注意顺序问题和语法问题:结构体没声明就使用了该类型,把结构体的定义提到前面或者进行前置声明

65,189

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧