2015-05-29 4 views
-1

Моя программа не скомпилируется правильно. Это дает неопределенные ошибки. Может ли кто-нибудь помочь мне решить это? Это говоритundefined ошибки ссылки снова

C: \ Users \ Milan_2 \ AppData \ Local \ Temp \ ccQt3lVs.o В функции 'orderOnConveyer': 90 C: \ Users \ Milan_2 \ Desktop \ Untitled2.c неопределенной ссылки на «вкладыш '

C: \ Users \ Milan_2 \ AppData \ Local \ Temp \ ccQt3lVs.o В функции 'WTandTAT': 115 C: \ Users \ Milan_2 \ Desktop \ 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

Смежные вопросы