a. The program uses an array of 12 structures. Each structure should hold a seat identification number, a marker that indicates whether the seat is assigned, the last name of the seat holder, and the first name of the seat holder.
b. The program displays the following menu:
To choose a function, enter its letter label:
a) Show number of empty seats
b) Show list of empty seats
c) Show alphabetical list of seats
d) Assign a customer to a seat assignment
e) Delete a seat assignment
f) Quit
c. The program successfully executes the promises of its menu. Choices d) and e) require additional input, and each should enable the user to abort an entry.
d. After executing a particular function, the program shows the menu again.
e. Data is saved in a file between runs. When the program is restarted, it first loads in the data, if any, from the file.
----------------解决方案--------------------------------------------------------
用单链表做就行了,确定好链表结构(包括订座人资料,座位信息),编个查找函数,剩下的就容易了。
----------------解决方案--------------------------------------------------------
帮忙把它具体的用标准C写出来好吗
我不知道怎么写啊 我是才学的啊
----------------解决方案--------------------------------------------------------
赞成二楼。。。用链表加结构体写就可以了。。。
另外拜托以后不要出现像这样的题目叫人整个帮你写的了。。。再说初学C还是不要做这样的题目。。。
以上纯属个人建议
[此贴子已经被作者于2006-12-26 18:37:33编辑过]
----------------解决方案--------------------------------------------------------
我以后会慢慢的学习的啊 现在是才接触的嘛
----------------解决方案--------------------------------------------------------
这个作业也太牛X了吧。
----------------解决方案--------------------------------------------------------
对题目意思似懂非懂
----------------解决方案--------------------------------------------------------
这个中文是这样的啊
实验7 结构体
某航空公司有一架飞机,共有12个座位,每天只飞一个航班。请你编写一个程序,能完成该航班的订票工作,要求如下:
a. 该程序使用一个长度为12的结构体数组。结构体的成员有4个,座位的编号,该座位是否已经售出的标志位,乘客的姓以及乘客的名。
b. 程序有如下菜单供选择:
To choose a function, enter its letter label:
a) Show number of empty seats
b) Show list of empty seats
c) Show alphabetical list of seats
d) Assign a customer to a seat assignment
e) Delete a seat assignment
f) Quit
c. 程序应该能根据不同的选择(a-f)调用相应的函数,完成指定的功能。选择d)和e)可能需要更多的输入。(进一步完善:考虑加入确认机制,提供放弃的机会)
d. 在执行完某个功能后,程序应该重新显示菜单,提供再次选择的机会。
(进一步完善:考虑采用读写文件的方式来保存数据,这样当程序重新运行时,原先的数据可以再次读出来)
----------------解决方案--------------------------------------------------------
给你一个简单的程序。只是关于第三个功能:Show alphabetical list of seats,说实话,我不知道到底想要什么。有关部分,你自己添上吧。
用了一个结构体数组,没用链表,当然如果改成用链表实现更好些,改动里面的部分代码就可以了。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct seats{
char id; //编号
char tag; //是否售出的标记,0:售出;1:未售出
char first_name[100];
char last_name[100];
};
struct airplane{
int empty; //空座数量
struct seats *head; //座位链表头指针
};
struct airplane example;
struct seats more_seats[12];
void fun1();
void fun2();
void fun3();
void fun4();
void fun5();
void show_empty_number(struct airplane);
void show_empty_list(struct airplane);
void assign_customer_seat(char*,char*,struct airplane*);
void delete_seat_assign(char,struct airplane*);
void msg()
{
printf("################################################\n");
printf("To choose a function, enter its letter label:\n");
printf("a) Show number of empty seats\n");
printf("b) Show list of empty seats\n");
printf("c) Show alphabetical list of seats\n");
printf("d) Assign a customer to a seat assignment\n");
printf("e) Delete a seat assignment\n");
printf("f) Quit\n");
printf("################################################\n");
}
void gogogo()
{
char ch=0,id=0;
char first_name[100]="\0";
char last_name[100]="\0";
printf("\n");
while(ch!='f')
{
printf(">>");
ch=getch();
if(ch==10){
printf("\n");
continue;
}
putchar(ch);
printf("\n");
switch(ch){
case 'a': fun1(); break;
case 'b': fun2(); break;
case 'c': fun3(); break;
case 'd': fun4(); break;
case 'e': fun5(); break;
case 'f': break;
}
}
}
void fun1()
{
show_empty_number(example);
}
void fun2()
{
show_empty_list(example);
}
void fun3()
{
printf("In fact, I do not know what you want to do exactly. Sorry.\n");
}
void fun4()
{
char first_name[100]="\0";
char last_name[100]="\0";
printf("Input the first name: ");
scanf("%s",first_name);
printf("Input the last name: ");
scanf("%s",last_name);
assign_customer_seat(first_name,last_name,&example);
free(first_name);
free(last_name);
}
void fun5()
{
int id=0;
if(example.empty==12)
{
printf("Sorry. There is no assignment.\n");
return ;
}
printf("Input the seat's id: ");
scanf("%d",&id);
getchar();
delete_seat_assign(id,&example);
}
void show_empty_number(struct airplane air)
{
printf("Empty number: %d\n",air.empty);
}
void show_empty_list(struct airplane air)
{
struct seats *tmp;
int i=0,j=0;
if(air.head!=NULL)
tmp=air.head;
else return ;
while(i<12)
{
if((tmp+i)->tag==0)
{
printf("%d ",(tmp+i)->id);
j++;
if(j==air.empty)
break;
}
i++;
}
printf("\n");
}
void assign_customer_seat(char* first_name,char *last_name,struct airplane *air)
{
struct seats *tmp,newseat;
int i=0,j=0,newid=0;
if(air->empty==0)
{
printf("Sorry, seats already full. Please try soon.\n");
return ;
}
newid=air->head->id;
tmp=air->head;
while(i<12)
{
if((tmp+i)->tag==0)
{
printf("assign id: %d\n",i);
(tmp+i)->tag=1;
strcpy((tmp+i)->first_name,first_name);
strcpy((tmp+i)->last_name,last_name);
break;
}
i++;
}
air->empty-=1;
}
void delete_seat_assign(char del_id,struct airplane *air)
{
struct seats *tmp;
char i=0;
tmp=air->head;
while(i<12)
{
if(((tmp+i)->id==del_id)&&((tmp+i)->tag==1))
{
(tmp+i)->tag=0;
free((tmp+i)->first_name);
free((tmp+i)->last_name);
air->empty++;
printf("ok\n");
return ;
}
if((tmp+i)->id==del_id&&(tmp+i)->tag==0)
{
printf("This seats not assigned.\n");
return ;
}
i++;
}
}
int main()
{
char i=0;
for(i=0;i<12;i++)
{more_seats[i].id=i+1;
more_seats[i].tag=0;
}
example.empty=12;
example.head=more_seats;
msg();
gogogo();
return 0;
}
----------------解决方案--------------------------------------------------------
另外,加上文件操作也容易实现。这里就不解释了。
----------------解决方案--------------------------------------------------------