青年烤饼上饼顺序系统学生时代小作品源码(C语言版)

/*****************************************************************************/

/*

煎饼上饼系统

姓名:danyuan              学校:湖南理工学院信息学院              专业:12级 信息工程

 

                                                                                                                                                                                 */

/*****************************************************************************/

#include <stdio.h>

#include <stdlib.h>

#define maxnumber 100

int index1=0,index2=0;

typedef struct cus{

         char name[20];

         int wait_time;

         int arrive_time;

}Customer;

 

void input_time(int&a,int &b)

{

         printf("请输入来的时间:");

         scanf("%d:%d",&a,&b);

}

 

void change_timetype1(Customer *C)

{

         int a,b;

         input_time(a,b);

         (*C).arrive_time=a*60+b;

}

void change_timetype2(Customer *C)

{

         int a,b;

         a=(*C).arrive_time%60;

         b=(*C).arrive_time/60;

         printf("%d:%d\n",b,a);

}

void input_name_and_waittime(Customer *C)

{

         printf("请输入顾客的名字:");

         scanf("%s",(*C).name);

         printf("请输入顾客愿意的等待时间:");

         scanf("%d",&(*C).wait_time);

}

void input_customer_information(Customer*C)

{

         Customer *p=C;

         for(int i=0;i<index1;i++)

         {

                   p++;

         }

         printf("请输入顾客的信息:\n");

         change_timetype1(p);

         input_name_and_waittime(p);

         index1++;

         index2=index1;

}

void putout_onecustomer(Customer*C)

{

 

        

         for(int i=0;i<10;i++)

                   printf("******");

         printf("\n");

         printf("   %s              %d                  ",(*C).name,(*C).wait_time);

         change_timetype2(C);

         printf("\n");

}

void putout_all(Customer*C)

{

         int num=0;

         for(int i=0;i<10;i++)

                   printf("******");

         printf("\n");

         printf("  顾客名字 愿意等待时间         到达时间         \n");

         while(num<index1)

         {

                   putout_onecustomer(C++);

                   num++;

         }

}

void sort_time(Customer *C)

{

         Customer *q=(Customer*)malloc(sizeof(Customer)),*p=C,*t;

         Customer *temp=(Customer*)malloc(sizeof(Customer));

         change_timetype1(q);

         int a,b,num1=0,num2=0;

         while(num1<index1)

         {

                   t=p;

                   a=(*p).arrive_time+(*p).wait_time-(*q).arrive_time;

                   b=(*t).arrive_time+(*t).wait_time-(*q).arrive_time;

                   while(num2<index2)

                   {

                            if(a>b)

                            {

                                     *temp=*p;

                                     *p=*t;

                                     *t=*temp;

                            }

                            num2++;

                            t++;

                            if(num2<index1)

                            b=(*t).arrive_time+(*t).wait_time-(*q).arrive_time;

                   }

                   index2--;

                   num2=0;

                   num1++;

                   p++;

         }

         index2=index1;

         num2=0;num1=0;p=C;

         printf("上饼顺序为:");

         while(num1<index1)

         {

                   printf("%s         ",(*p).name);

                   p++;

                   num1++;

         }

         printf("\n");

}

void main()

{

         FILE *sp;

         sp=freopen("in.txt","r",stdin);

         Customer customer[maxnumber];

         Customer *p=customer;

         int Operate,i;

         while(1)

         {

                   printf("1.输入顾客信息 2.输出所有顾客信息      3.输出所有的成员 4.输出上饼顺序      \n");

                   scanf("%d",&Operate);

                   switch(Operate)

                   {

                   case 1:input_customer_information(p);break;

                   case 2:      for(i=0;i<10;i++)

                                               printf("******");

                                     printf("\n");     

                                     printf("  顾客名字 愿意等待时间         到达时间         \n"); putout_onecustomer(p);break;

                   case 3:putout_all(p);

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

                                     printf("******");

                            printf("\n");               break;

                   case 4:      sort_time(p);   break;

                   case 0:break;

                   default:continue;

                   }

                   if(Operate==0)

                            break;

         }

         fclose(sp);

}

 

/**********************************************************2013年5月20日作**/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值