2015-05-29 82 views
-1

我的程序无法正确编译。它给出了未定义的错误。有人可以帮我解决这个问题吗?它说未定义的引用错误再次

C:\用户\ Milan_2 \应用程序数据\本地的\ Temp \ ccQt3lVs.o在功能 'orderOnConveyer':90 C:\用户\ Milan_2 \桌面\ Untitled2.c未定义 参考“插入'

C:\用户\ Milan_2 \应用程序数据\本地\ TEMP \ ccQt3lVs.o在函数 'WTandTAT': 115 C:\用户\ Milan_2 \桌面\ Untitled2.c未定义参照 '的isEmpty' C: \ Users \ Milan_2 \ AppData \ Local \ Temp \ ccQt3lVs.o 函数'main':

#include <stdio.h> 
#include <conio.h> 
#include <malloc.h> 
#define MAX1 30 
#define MAX2 30 
#define TRUE 1 
#define FALSE 0 

struct cake{ 
    char cake; 
    int preperation_time; 
    int baking_time; 
    int waiting_time; 
    int turnaround_time; 
}; 
struct Queue{ 
    int front; 
    int rear; 
    int count; 
    struct cake items[MAX1]; 
}; 
struct Stack{ 
    int top; 
    struct cake items[MAX2]; 
}; 

struct cake ChocolateCake(); 
struct cake SpongeCake(); 
struct cake MeringueCake(); 
struct cake RedVelvetCake(); 

void orderOnConveyer(struct Queue *, int); 
void WTandTAT(struct Queue *,struct Queue *, int); 
int longestBakingTime(struct Queue *q); 
void orderOnStorageConveyer(struct Queue *, struct Stack *); 
void averageWaitingTime_and_averageTurnaroundTime(struct Queue *, struct Queue *); 

void init(struct Queue *); 
int isFull(struct Queue *); 
void insert(struct Queue *, struct cake); 


void push(struct Stack *, struct cake); 

struct cake pop(struct Stack *); 

struct cake ChocolateCake(){ 
    struct cake c; 
    c.cake='C'; 
    c.preperation_time=25;   
    c.baking_time=40;    
    c.waiting_time=0; 
    c.turnaround_time=0; 
    return c; 
} 
struct cake SpongeCake(){ 
    struct cake c; 
    c.cake='S'; 
    c.preperation_time=30; 
    c.baking_time=20;   
    c.waiting_time=0; 
    c.turnaround_time=0; 
    return c; 
} 
struct cake MeringueCake(){ 
    struct cake c; 
    c.cake='M'; 
    c.preperation_time=45; 
    c.baking_time=75;   
    c.waiting_time=0; 
    c.turnaround_time=0; 
    return c; 
} 
struct cake RedVelvetCake(){ 
    struct cake c; 
    c.cake='R'; 
    c.preperation_time=60; 
    c.baking_time=30;   
    c.waiting_time=0; 
    c.turnaround_time=0; 
    return c; 
} 

void orderOnConveyer(struct Queue *q, int minute){ 
    int i; 
    printf("\n\n\n\n----------Conveyer Order----------\n\n\n"); 
    for(i=1;i<=minute;i++){ 
     if(i%25==0){ 
      printf("\nChocolate Cake"); 
      insert(q, ChocolateCake()); 
     } 
     if(i%30==0){ 
      printf("\nSponge Cake"); 
      insert(q, SpongeCake()); 
     } 
     if(i%45==0){ 
      printf("\nMeringue Cake"); 
      insert(q, MeringueCake()); 
     } 
     if(i%60==0){ 
      printf("\nRedVelvet Cake"); 
      insert(q, RedVelvetCake()); 
     } 
    }  
} 


void WTandTAT(struct Queue *q, struct Queue *q1, int minute){ 
     struct cake temp; 
     int i,temp1=0,temp2=0,temp3=0,temp4=0; 

     printf("\n\n\n------- Waiting Time & Turnaround Time for each cake -------\n\n"); 
     printf("Cake\tWaiting Time\tTurnaround Time"); 

     while(!isEmpty(q)){ 


     if(temp.preperation_time==25){ 

       for(i=temp.preperation_time+temp1;i<minute;i++){ 
        temp.waiting_time++; 
     } 
       temp1=temp1+temp.preperation_time; 
       temp.turnaround_time=temp.baking_time+temp.waiting_time; 
       insert(q1, temp); 
     } 

     else if(temp.preperation_time==30){ 

       for(i=temp.preperation_time+temp2;i<minute;i++){ 
        temp.waiting_time++;  
       } 

       temp2=temp2+temp.preperation_time; 
       temp.turnaround_time=temp.baking_time+temp.waiting_time; 

       insert(q1, temp); 

     } 
     else if(temp.preperation_time==45){ 

       for(i=temp.preperation_time+temp3;i<minute;i++){ 
        temp.waiting_time++; 
       } 

       temp3=temp3+temp.preperation_time; 
       temp.turnaround_time=temp.baking_time+temp.waiting_time; 

       insert(q1, temp); 

     } 
     else if(temp.preperation_time==60){ 

       for(i=temp.preperation_time+temp4;i<minute;i++){ 
        temp.waiting_time++; 
      } 

       temp4=temp4+temp.preperation_time; 
       temp.turnaround_time=temp.baking_time+temp.waiting_time; 

       insert(q1, temp); 

     } 
     } 

} 


void averageWaitingTime_and_averageTurnaroundTime(struct Queue *q, struct Queue *q1) 
{ 
     struct cake temp; 
     int Total_waiting_time=0, count=q->count, Total_turnaround_time=0; 
     float avgWT=0, avgTAT=0; 
     while(!isEmpty(q)){ 



      Total_waiting_time=Total_waiting_time+temp.waiting_time; 
      avgWT=(Total_waiting_time/count); 

      Total_turnaround_time=Total_turnaround_time+temp.turnaround_time; 
      avgTAT=(Total_turnaround_time/count); 
      insert(q1,temp); 
     } 
     printf("\n\n------------------------------------------------------------------------");   
     printf("\n\nAvarage Waiting Time = %f min",avgWT); 
     printf("\n\nAvarage Turnaround Time = %f min",avgTAT);    
} 


main(){ 
    struct Queue q; 
    struct Queue q1; 
    struct Stack s; 
    struct cake temp; 
    int minute, i=0; 

    s.top=-1; 
    init(&q); 
    init(&q1); 

    printf("*******************Welcome Bakery Simulation*******************"); 
    printf("\n\t\t  Author : Milan Udayanga()"); 
    printf("\n--------------------------------------------------------------------------------"); 

    printf("\n\nEnter the duration(minute) for check the process in the bakery:"); 
    scanf("%d",&minute); 



    orderOnConveyer(&q, minute); 

    WTandTAT(&q, &q1, minute); 

    while(!isEmpty(&q1)){ 

     printf("\n%c\t%d\t\t%d", temp.cake, temp.waiting_time, temp.turnaround_time); 
     insert(&q,temp); 
    } 

    averageWaitingTime_and_averageTurnaroundTime(&q, &q1); 

    orderOnStorageConveyer(&q1, &s); 

    while(!isEmpty(&s)){ 
     temp= pop(&s); 
     printf("\n%c",temp.cake); 

    } 
    getch(); 
    return 0; 
} 
+0

除了错误,我还得到5 *警告*你需要注意。 – usr2564301

+0

我只是想执行该程序。这至少不会执行。 – Kingsman

+0

它不会*编译*,这是别的。编译器告诉你为什么它不能编译你的代码,因为这些错误显然对你没有任何意义,所以对它们进行了更详细的解释。除此之外,我们也无法帮助你。 – usr2564301

回答

1

在你的代码,

  1. 对于insert()功能,你只有声明功能(作为原型)。你没有这里定义的功能。你需要有一个函数定义。

  2. 对于isEmpty(),您既没有声明也没有定义。编译器不知道该怎么做。所以,它说,“未定义的参考”

+1

'isEmpty'也应该给出一个警告,说明函数没有被声明。所以OP可能有早期的错误/警告信息被忽略。 –

+0

@MattMcNabb我也这么认为。 OP发布的错误日志结束_unexpectedly_。 –

+0

它应该如何? 。举个例子 ? – Kingsman