| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1171 人关注过本帖
标题:银行业务模拟课设 严蔚敏版C 语言
只看楼主 加入收藏
杨亚勤
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-1-29
结帖率:0
收藏
 问题点数:0 回复次数:2 
银行业务模拟课设 严蔚敏版C 语言


急!!! 求高手帮忙编译成功
本人用 Dev-C++ 编译都是相同的 语法错误 ,不知怎么改   

 

typedef    struct
{

    int    time;                                                /*    type=1 入列1, type=2 出列1, type=3 出列3     */
    int    type;

}Event;                                                  /*    事件类型    */










typedef    struct    LNode
{

    Event   data;
    struct  LNode   *next;

}LNode, *ListPtr;                                            /*    结点类型,  指针类型    */













typedef    struct
{

    ListPtr    head;

}LinkList;                                                       /*    链表类型, 链表有头结点   */











typedef    struct
{

    int    ArriveTime;
    int    ServiceTime;
    int    Cash;

}Customer;                                                         /*   顾客类型    */








typedef    struct    QNode
{

    Customer    data;
    struct  QNode    * next;

}QNode,  *QueuePtr;                                                 /*    结点和指针    */










typedef    struct
{

    QueuePtr    front;
    QueuePtr    rear;
    int    length;
                                                                      /*    队列类型    */
}LinkQueue;






#if !defined(NULL)
#define NULL (0)
#endif





Event   event;
LinkList    eventlist;
Customer    customer;
LinkQueue   q[2];
int    TotalTime,  CustomerNum;
int    TotalCash=10000;
int    CloseTime=600;
                                                                         /*     全局变量    */








/*    以下是链表函数实现    */




void    InitList( LinkList  &L )                                             /*    初始化链表   */
{
   
    L.head=( ListPtr )malloc( sizeof( LNode ) );
    if( !L.head )     exit( -1 );
    L.head->next= NULL;

}













void    OrderInsert( LinkList  &L, Event  e )                                /*    根据事件发生的时间把事件插入事件表   */
{

    ListPtr  p,q,pre;
    p=( ListPtr )malloc( sizeof( LNode ) );
    if( !p )    exit( -1 );
    p->data=e;
    q=L.head->next;
    while( q!=NULL && ( q.data ).time<  ( p.data ).time )
    {

        pre=q;
        q=q->next;

    }
    p->next=q;
    pre->next=p;


}















void    DelFirst( LinkList  &L, Event  &e )                          /*    把正发生事件从事件表中删除   */
{

    ListPtr  p;
    p=L.head->next;
    if( p==NULL )    exit( -1 );
    L.head->next=p->next;
    e=p->data;
    free( p );

}















/*    以下是队列函数的实现    */








                                                                               /*   初始化队列  */
void    InitQueue( LinkQueue  &Q)
{

    Q.front=Q.rear=( QueuePtr )malloc( sizeof( QNode ) );
    if( !Q.front )    exit( -1 );
    Q.front->next=NULL;
    Q.length=0;


}















void    EnQueue( LinkQueue  &Q,  Customer  e )                              /*    插入队列  */
{

    QueuePtr  p;
    p=( QueuePtr )malloc( sizeof( QNode ) );
    if( !p )    exit( -1 );
    p->data=e;
    p->next=NULL;
    Q.rear->next=p;
    Q.rear=p;
    Q.length++;


}















void    DeQueue( LinkQueue  &Q,  Customer  &e )                          /*    元素出列    */
{

    QueuePtr  p;
    if( Q.length==0 )    exit( -1 );
    p=Q.front->next;
    Q.front->next=p->next;
    Q.length--;
    e=p->data;
    if( p==Q.rear )   Q.rear=Q.front;
    free( p );


}














void    GetHead( LinkQueue  &Q,  Customer  &e )                          /*    取头元素    */
{

    QueuePtr  p;
    if( Q.lengeh==0 )   exit( -1 );
    p=Q.front->next;
    e=p->data;


}


















void    OpenForDay()                                                    /*    银行模拟初始化    */
{

    int  i;
    TotalTime=0;
    CustomerNum=0;
    event.time=0;
    event.type=1;
    InitList( eventlist );
    OrderInsert( eventlist,  event );
    for( i=1; i<=4; i++ )
    {

        InitQueue( q[i] );

    }


}














void    CustomerArrived()                                                            /*    客户入队    */
{

    int  servicetime,  intertime,  cash;
    int  t;
    Customer  e;

    ++CustomerNum;

    srand( time( 0 ) );
    servicetime = 3 + rand()%7;
    intertime = 5 + rand()%10;
    cash = -5000 + rand()%10000;

    EnQueue( q[0], ( event.time,  servicetime,  cash ) );
    if( q[0].length==1 )
    {

        if( TotalCash + cash >= 0 )
        {

            OrderInsert( eventlist,  ( event.time + servicetime,  2 ) );
        }
        else
        {

            DeQueue( q[0], e );
            EnQueue( q[1], e );

        }
    }

    t=event.time + intertime;
    if( t< CloseTime )
    {
        OrderInsert( eventlist,  ( t,  1 ) );

    }


}















void    CustomerDepature_Q1()                                                            /*     从队列1中删除   */
{

    int  TempCash;
    int  t;
    int  count;
    Customer  e,  next_customer;

    DeQueue( q[0],  customer );
    TotalTime += ( event.time - customer.ArriveTime );
    TempCash = TotalCash;
    TotalCash += customer.Cash;
    t=event.time;

    if( customer.Cash > 0 )                                                        /*   有人注资, 检查队列2    */
    {

        count=1;
        while( TotalCash > TempCash && count <= q[1].length )
        {

            GetHead( q[1], e );
            if( TotalCash + e.Cash >= 0 )
            {

                TotalCash += e.Cash;
                srand( time( 0 ) );
                e. ServiceTime = 3 + rand()%7;
                t += e. ServiceTime;
                OrderInsert( eventlist, ( t, 3 ) );

            }
            else
            {

                DeQueue( q[1], e );
                EnQueue( q[1], e );

            }
            count++;

       }
    }

    if( q[0].length != 0 )
    {

        GetHead( q[0], next_customer );
        if( TotalCash + next_customer.Cash >=0 )
        {

            OrderInsert( eventlist,  ( t + next_customer.ServiceTime,  2 ) );

        }
        else
        {

            DeQueue( q[0], next_customer );
            EnQueue( q[1], next_customer );

        }

    }



}






void    CustomerDepature_Q2()                                                          /*     从队列2中删除   */
{

    Customer  customer;

    DeQueue( q[1],  customer );
    TotalTime += ( event.time - customer.ArriveTime );
    TotalCash += customer.Cash;

}
















int    main()
{

    OpenForDay();
    while( eventlist.head->next != NULL )
    {

        DelFirst( eventlist,  event );
        switch ( event.type )
        {

            case 1 :    CustomerArrived();

            case 2 :    CustomerDepature_Q1();

            case 3 :    CustomerDepature_Q2();

            default :    exit( -1 );

        }

   }
   printf( "Average Time: %f ", ( float )TotalTime/CustomerNum );
   return  0;

}

        


        
      


        


[ 本帖最后由 杨亚勤 于 2010-2-12 22:48 编辑 ]
搜索更多相关主题的帖子: 模拟 语言 银行业务 蔚敏 
2010-02-12 00:12
heartnheart
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:335
专家分:1096
注 册:2009-7-10
收藏
得分:0 
楼主是C语言还是C++?
2010-02-15 19:10
heartnheart
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:335
专家分:1096
注 册:2009-7-10
收藏
得分:0 
typedef    struct
{

    int    time;                                                /*    type=1 入列1, type=2 出列1, type=3 出列3     */
    int    type;

}Event;                                                  /*    事件类型    */










typedef    struct    LNode
{

    Event   data;
    struct  LNode   *next;

}LNode, *ListPtr;                                            /*    结点类型,  指针类型    */













typedef    struct
{

    ListPtr    head;

}LinkList;                                                       /*    链表类型, 链表有头结点   */











typedef    struct
{

    int    ArriveTime;
    int    ServiceTime;
    int    Cash;

}Customer;                                                         /*   顾客类型    */








typedef    struct    QNode
{

    Customer    data;
    struct  QNode    * next;

}QNode,  *QueuePtr;                                                 /*    结点和指针    */










typedef    struct
{

    QueuePtr    front;
    QueuePtr    rear;
    int    length;
                                                                      /*    队列类型    */
}LinkQueue;






#if !defined(NULL)
#define NULL (0)
#endif
#include <stdlib.h>
#include <time.h>
#include <iostream>


Event   event;
LinkList    eventlist;
Customer    customer;
LinkQueue   q[2];
int    TotalTime,  CustomerNum;
int    TotalCash=10000;
int    CloseTime=600;
                                                                         /*     全局变量    */








/*    以下是链表函数实现    */




void    InitList( LinkList  &L )                                             /*    初始化链表   */
{
    L.head=( ListPtr )malloc( sizeof( LNode ) );
      
    if( !L.head )     exit( -1 );
     system("pause");
    L.head->next= NULL;

}













void    OrderInsert( LinkList  &L, Event  e )                                /*    根据事件发生的时间把事件插入事件表   */
{

    ListPtr  p,q,pre;
    p=( ListPtr )malloc( sizeof( LNode ) );
    if( !p )    exit( -1 );
    p->data=e;
    q=L.head->next;
    while( q!=NULL && ( q->data ).time<  ( p->data ).time )
    {

        pre=q;
        q=q->next;

    }
    p->next=q;
    pre->next=p;


}















void    DelFirst( LinkList  &L, Event  &e )                          /*    把正发生事件从事件表中删除   */
{

    ListPtr  p;
    p=L.head->next;
    if( p==NULL )    exit( -1 );
    L.head->next=p->next;
    e=p->data;
    free( p );

}















/*    以下是队列函数的实现    */








                                                                               /*   初始化队列  */
void    InitQueue( LinkQueue  &Q)
{

    Q.front=Q.rear=( QueuePtr )malloc( sizeof( QNode ) );
    if( !Q.front )    exit( -1 );
    Q.front->next=NULL;
    Q.length=0;


}















void    EnQueue( LinkQueue  &Q,  Customer  e )                              /*    插入队列  */
{

    QueuePtr  p;
    p=( QueuePtr )malloc( sizeof( QNode ) );
    if( !p )    exit( -1 );
    p->data=e;
    p->next=NULL;
    Q.rear->next=p;
    Q.rear=p;
    Q.length++;


}















void    DeQueue( LinkQueue  &Q,  Customer  &e )                          /*    元素出列    */
{

    QueuePtr  p;
    if( Q.length==0 )    exit( -1 );
    p=Q.front->next;
    Q.front->next=p->next;
    Q.length--;
    e=p->data;
    if( p==Q.rear )   Q.rear=Q.front;
    free( p );


}














void    GetHead( LinkQueue  &Q,  Customer  &e )                          /*    取头元素    */
{

    QueuePtr  p;
    if( Q.length==0 )   exit( -1 );
    p=Q.front->next;
    e=p->data;


}


















void    OpenForDay()                                                    /*    银行模拟初始化    */
{

    int  i;
    TotalTime=0;
    CustomerNum=0;
    event.time=0;
    event.type=1;

    InitList( eventlist );
    OrderInsert( eventlist,  event );
    for( i=1; i<=4; i++ )
    {

        InitQueue( q[i] );

    }


}














void    CustomerArrived()                                                            /*    客户入队    */
{

    int  servicetime,  intertime,  cash;
    int  t;
    Customer  e;

    ++CustomerNum;

    srand( time( 0 ) );
    servicetime = 3 + rand()%7;
    intertime = 5 + rand()%10;
    cash = -5000 + rand()%10000;

    EnQueue( q[0], (Customer){ event.time,  servicetime,  cash });
    if( q[0].length==1 )
    {

        if( TotalCash + cash >= 0 )
        {

            OrderInsert( eventlist,  ( Event){ event.time + servicetime,  2 } );
        }
        else
        {

            DeQueue( q[0], e );
            EnQueue( q[1], e );

        }
    }

    t=event.time + intertime;
    if( t< CloseTime )
    {
        OrderInsert( eventlist, (Event) { t,  1 } );

    }


}















void    CustomerDepature_Q1()                                                            /*     从队列1中删除   */
{

    int  TempCash;
    int  t;
    int  count;
    Customer  e,  next_customer;

    DeQueue( q[0],  customer );
    TotalTime += ( event.time - customer.ArriveTime );
    TempCash = TotalCash;
    TotalCash += customer.Cash;
    t=event.time;

    if( customer.Cash > 0 )                                                        /*   有人注资, 检查队列2    */
    {

        count=1;
        while( TotalCash > TempCash && count <= q[1].length )
        {

            GetHead( q[1], e );
            if( TotalCash + e.Cash >= 0 )
            {

                TotalCash += e.Cash;
                srand( time( 0 ) );
                e. ServiceTime = 3 + rand()%7;
                t += e. ServiceTime;
                OrderInsert( eventlist, (Event){ t, 3 } );

            }
            else
            {

                DeQueue( q[1], e );
                EnQueue( q[1], e );

            }
            count++;

       }
    }

    if( q[0].length != 0 )
    {

        GetHead( q[0], next_customer );
        if( TotalCash + next_customer.Cash >=0 )
        {

            OrderInsert( eventlist,  ( Event){ t + next_customer.ServiceTime,  2 } );

        }
        else
        {

            DeQueue( q[0], next_customer );
            EnQueue( q[1], next_customer );

        }

    }



}






void    CustomerDepature_Q2()                                                          /*     从队列2中删除   */
{

    Customer  customer;

    DeQueue( q[1],  customer );
    TotalTime += ( event.time - customer.ArriveTime );
    TotalCash += customer.Cash;

}
















int    main()
{

    OpenForDay();
    system("pause");
    while( eventlist.head->next != NULL )
    {

        DelFirst( eventlist,  event );
        switch ( event.type )
        {

            case 1 :    CustomerArrived();

            case 2 :    CustomerDepature_Q1();

            case 3 :    CustomerDepature_Q2();

            default :    exit( -1 );

        }

   }
   printf( "Average Time: %f ", ( float )TotalTime/CustomerNum );
   system("pause");
   return  0;

}

        

能编译通过了,但是会发生运行时错误
2010-02-15 19:43
快速回复:银行业务模拟课设 严蔚敏版C 语言
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023567 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved