Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall queueADT structure which had the following queue.h interface: /* queue.h */ #ifndef _queue_h #define _queue_h #include genlib.h typedef void *queueElementT; typedef struct queueCDT *queueADT;

Recall queueADT structure which had the following queue.h interface:

/* queue.h */

#ifndef _queue_h

#define _queue_h

#include "genlib.h

typedef void *queueElementT;

typedef struct queueCDT *queueADT;

queueADT NewQueue(void);

void FreeQueue(queueADT queue);

void Enqueue(queueADT queue, queueElementT element);

queueElementT Dequeue(queueADT queue);

bool QueueIsEmpty(queueADT queue);

bool QueueIsFull(queueADT queue);

int QueueLength(queueADT queue);

queueElementT GetQueueElement(queueADT queue, int index);

#endif

Suppose its implementation is available as queue.o, so you can use all the functions in

queue.h, but you cannot change their implementation.

Now you are asked to complete the driver/application program in the next page by using the

above queue.h interface and implementing the necessary piece of codes needed for your

driver/application as defined below.

The driver/application simply reads all the double numbers from a file whose name is given

as a command line argument (this part is already done for you) and inserts (Enqueue) them

into the queue (you will do this part). Please note that queueElementT is defined to be

void *. So you cannot directly enqueue the double numbers into the queue. In this case,

remember you should allocate memory for your double numbers and then enqueue their

addresses in the queue!

Then you are asked to find and print the sum of the double values in the queue, but do not

dequeue or remove the numbers from the queue. So the queue still contains all the values.

Finally, before exiting from the program, make sure all the dynamically allocated memory

spaces and structures are released/freed.

/* driver.c */ /* assume all the necessary standard C libraries and booklibs are included here too */

#include "queue.h"

int main(int argc, char *argv[])

{

FILE *fp;

queueADT myQ;

double value, *ptr, sum;

int i;

if(argc!=2 || (fp=fopen(argv[1],"r")) == NULL){

printf("not enough argument or file cannot be opened "); exit(0);

}

myQ = NewQueue();

// [8pt] get each double value from the file, insert it into myQ

while(fscanf(fp, "%lf", &value) == 1){

}

// [7pt] find/print the sum of the values in myQ.

// but do not dequeue or remove the numbers from myQ.

// [5pt] release/free all the dynamically allocated memory spaces

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

Students also viewed these Databases questions

Question

Q.1. Taxonomic classification of peafowl, Tiger and cow ?

Answered: 1 week ago

Question

Q .1. Different ways of testing the present adulterants ?

Answered: 1 week ago