帮忙编一道c语言程序题

帮忙编一道c语言程序题,第1张

#include <stdioh>

#include <mathh>

int main()

{

double a = 00; // 加速度

double t = 00; // 加速时间

double v0 = 00, s = 940, v = 2780; // 初速度,加速距离,起飞速度

printf("输入起飞速度(km/h)、d射距离(m),如输入278km/h,94m:\n");

scanf("%lfkm/h,%lfm", &v, &s);

v = v / 36; // 转换成m/s

a = pow(v, 2)/(2s); // 计算加速度

t = sqrt(2s/a); // 计算加速时间

printf("加速度a=%3lf,加速时间t=%3lf", a, t);

return 0;

}

#include <stdioh>

#include <conioh>

struct Plane

{

int p[20][4];

};

int main()

{

int i, j, row, num, flag = false;

char ch,n,name[30],id[25];

Plane plane1;

for (i=0;i<20;i++)

for (j=0;j<4;j++)

plane1p[i][j] = false; // 初始化所有位置为空

printf("\t\t========飞机订票系统=======\t\t\n\n");

printf("\t\t本飞机现在还有如下空位:\t\t\n\n");

for (i=0;i<20;i++)

{

if (i==18)

printf("\n\t\t以下为吸烟区\t\t\n\n");

printf("\t\t");

for (j=0;j<4;j++)

{

if (plane1p[i][j] == false)

printf("%d%c\t",i+1,j+65);

else printf(" \t");

}

printf("\n");

}

do{

printf("\t\t有您满意的座位吗?(y/n) ");

scanf("%c",&ch);

} while (ch != 'y' && ch != 'Y' &&

ch != 'n' && ch != 'N');

if (ch == 'y' || ch == 'Y')

{

do{

printf("\t\t请输入您满意的座位排数及编号:(如10D)\n\t\t");

scanf("%d%c",&row,&n);

num = (int)(n-65);

if (plane1p[row-1][num] == true)

{

printf("\t\t对不起,此座位已出售!请重新选择!\n");

flag = true;

}

} while (row<1||row>20||n<'A'||n>'D'||

flag == true);

plane1p[row-1][num] = true;

printf("\t\t请输入您的姓名: ");

scanf("%s",name);

printf("\t\t请输入您的身份z号: ");

scanf("%s",id);

printf("\t\t恭喜您,订票成功!\n");

printf("\t\t您的信息:\n");

printf("\t\t姓名: %s\n",name);

printf("\t\t身份z号: %s\n",id);

printf("\t\t座位: %d%c\n",row,n);

printf("\t\t祝您旅途愉快!");

}

else printf("\t\t对不起,请您选择另一航班!");

getch();

return 0;

}

#include "stdioh"

#include "malloch"

#include "stringh"

#define MAXN 100

typedef struct{

char hour[MAXN];

char minute[MAXN];

} time;

typedef struct node

{

char number[MAXN]; //航班号

time start; //起飞时间

time end; //到达时间

char start_station[MAXN]; //起点站

char end_station[MAXN]; //终点站

char type[MAXN]; //飞机型号

char price[MAXN]; //票价

struct nodelink;

}NODE;

NODE create_link_list(int n)

{

int i;

NODE head,p,q;

if(n==0)return(NULL);

head=(NODE)malloc(sizeof(NODE));

for(i=0;i <MAXN;i++)

{

head->number[i]='\0';

head->starthour[i]='\0';

head->startminute[i]='\0';

head->endhour[i]='\0';

head->endminute[i]='\0';

head->start_station[i]='\0';

head->end_station[i]='\0';

head->type[i]='\0';

head->price[i]='\0';

}

p=head;

for(i=1;i <n;i++)

{

printf("请输入航班号:");

scanf("%s",&(p->number));

printf("请输入起飞时间(时 分):");

scanf("%s %s",&(p->starthour),&(p->startminute));

printf("请输入达到时间(时 分):");

scanf("%s %s",&(p->endhour),&(p->endminute));

printf("请输入起点站 终点站:");

scanf("%s %s",&(p->start_station),&(p->end_station));

printf("请输入飞机型号:");

scanf("%s",&(p->type));

printf("请输入票价:");

scanf("%s",&(p->price));

printf("\n");

q=(NODE)malloc(sizeof(NODE));

p->link=q;

p=q;

}

printf("请输入航班号:");

scanf("%s",&(p->number));

printf("请输入起飞时间(时 分):");

scanf("%s %s",&(p->starthour),&(p->startminute));

printf("请输入达到时间(时 分):");

scanf("%s %s",&(p->endhour),&(p->endminute));

printf("请输入起点站 终点站:");

scanf("%s %s",&(p->start_station),&(p->end_station));

printf("请输入飞机型号:");

scanf("%s",&(p->type));

printf("请输入票价:");

scanf("%s",&(p->price));

printf("\n");

getchar();

p->link=NULL;

return(head);

}

void insert(NODE p_head,NODE q)

{

NODE p;

if(p_head==NULL)

p_head=q;

else

{

p=p_head;

while(p!=NULL&&p->link!=NULL)

p=p->link;

p->link=q;

}

}

unsigned int countit(NODE n)//计算链表长度

{

unsigned int counti = 0;

while(n!=NULL)

counti++,n=n->link;

return counti;

}

NODE getindex(NODE head, int num);

NODE getindex(NODE head, int num)//取得index为num 的节点!

{

if(num<0 || num>countit(head))

return NULL;

NODE rn = head;

while(--num>0)

rn = rn->link;

return rn;

}

int binSearch(NODE n,char strinput,int low, int high)// 二分查找

{

int i;

int middle = (high+low)/2;

if (high < low)

return 0;

if ((i=strcmp(strinput, n->number)) <0)

high= middle;

else if (i > 0)

low = middle;

else

{

i = middle;

return i;

}

binSearch(getindex(n,middle),strinput,low,high);

}

int bisect(char a[],int n,char s[MAXN])//二分查找

{

int i,j,m;

i=0;

j=n-1;

while(i <=j)

{

m=(i+j)/2;

}

return(-1);

}

NODE search1(NODE head,char v[MAXN])//起点站顺序查找

{

for(;head!=NULL&&strcmp(head->start_station,&v[0]);head=head->link);

return(head);

}

NODE search2(NODE head,char w[MAXN])//到达站顺序查找

{

for(;head!=NULL&&strcmp(head->end_station,&w[0]);head=head->link);

return(head);

}

NODE search3(NODE head,char x[MAXN],char y[MAXN])//起飞时间顺序查找

{

for(;head!=NULL&&(strcmp(head->starthour,&x[0]) || strcmp(head->startminute,&y[0]));head=head->link);

return(head);

}

NODE search4(NODE head,char t[MAXN],char u[MAXN])//到达时间顺序查找

{

for(;head!=NULL&&(strcmp(head->endhour,&t[0]) || strcmp(head->endminute,&u[0]));head=head->link);

return(head);

}

void output(NODE p)

{

while(p!=NULL)

{

printf("航班信息:\n");

printf("航班号:%s\n",p->number);

printf("起飞时间:%s点%s分,",p->starthour,p->startminute);

printf("到达时间:%s点%s分\n",p->endhour,p->endminute);

printf("起点站:%s,",p->start_station);

printf("到达站:%s\n",p->end_station);

printf("飞机型号:%s ",p->type);

printf("票价:%s元\n\n",p->price);

p=p->link;

}

}

NODE rank( NODE head)

{

NODE q=0,p=0,t,h1;

h1=head->link;

head->link=NULL;

while(h1!=NULL)

{

t=h1;

h1=h1->link;

p=head;

q=head;

while( p!=NULL && strcmp(t->number, p->number)>0 )

{

q=p;

p=p->link;

}

if(q == p)

{

t->link=p;

head=t;

}

else

{

t->link=p;

q->link=t;

}

}

return head;

}

int main(int argc, char argv[])

{

NODE p,q,r;

int a,b,i,j,n;

int count=0;

char o[MAXN];

char s[MAXN];

char v[MAXN];

char w[MAXN];

char x[MAXN];

char y[MAXN];

char t[MAXN];

char u[MAXN];

for(i=0;i <MAXN;i++)

{

o[i]='\0';

s[i]='\0';

v[i]='\0';

w[i]='\0';

x[i]='\0';

y[i]='\0';

t[i]='\0';

u[i]='\0';

}

while(true)

{

printf("航班信息的查询与检索\n");

printf("★★\n");

printf(" 1建立航班信息\n");

printf(" 2插入航班信息\n");

printf(" 3按航班号进行排序 \n");

printf(" 4航班信息查询\n");

printf(" 5显示航班信息\n");

printf(" 6退出本系统\n");

printf("★★\n");

scanf("%d",&a);

getchar();

switch(a)

{

case 1:

printf("请输入你所要建立的航班信息个数:");

scanf("%d",&n);

p=create_link_list(n);

break;

case 2:

q=create_link_list(1);

insert(&p,q);

break;

case 3:

p = rank(p);

break;

case 4:

printf("\n1、按照航班号查询\n");

printf("2、按照起点站查询\n");

printf("3、按照到达站查询\n");

printf("4、按照起飞时间查询\n");

printf("5、按照到达时间查询\n");

scanf("%d",&b);

getchar();

switch(b)

{

case 1:

p=rank(p);

printf("请输入您所要找的航班号:");

scanf("%s",s);

if( binSearch(p,s,1, countit(p)) )

printf("scuess!\n");

break;

case 2:

printf("请输入起点站");

scanf("%s",&v[MAXN]);

if(search1(p,&v[MAXN])!=NULL)

{

printf("查询成功!\n");

r=search1(p,&v[MAXN]);

output(r);

}

else

printf("查询失败,该信息录中没有该起点站!\n");

break;

case 3:

printf("请输入到达站");

scanf("%s",&w[MAXN]);

if(search2(p,&w[MAXN])!=NULL)

{

printf("查询成功!\n");

r=search2(p,&w[MAXN]);

output(r);

}

else

printf("查询失败,该信息录中没有该到达站!\n");

break;

case 4:

printf("请输入起飞时间(时 分)");

scanf("%s %s",&x[MAXN],&y[MAXN]);

if(search3(p,&x[MAXN],&y[MAXN])!=NULL)

{

printf("查询成功!\n");

r=search3(p,&x[MAXN],&y[MAXN]);

output(r);

}

else

printf("查询失败,该信息录中没有该到达站!\n");

break;

case 5:

printf("请输入到达时间");

scanf("%s %s",&t[MAXN],&u[MAXN]);

if(search4(p,&t[MAXN],&u[MAXN])!=NULL)

{

printf("查询成功!\n");

r=search4(p,&t[MAXN],&u[MAXN]);

output(r);

}

else

printf("查询失败,该信息录中没有该到达站!\n");

break;

}

break;

case 5:

output(p);

printf("\n");

break;

case 6:

return(0);

}

}

return(0);

}

以上就是关于帮忙编一道c语言程序题全部的内容,包括:帮忙编一道c语言程序题、c语言飞机订票系统设计、求C语言编程(航班信息查询与检索)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9723121.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存