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\n"); 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
}
/* 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\n");
exit(0);
}
myQ = NewQueue();
// [8pt] get each double value from the file, insert it into
myQ
while(fscanf(fp, "%lf", &value) == 1){
ptr = (double *)malloc(sizeof(double));
*ptr = value;
Enqueue(myQ, ptr);
}
fclose(fp);
// [7pt] find/print the sum of the values in myQ.
// but do not dequeue or remove the numbers from myQ.
sum = 0;
i = QueueLength(myQ);
while(i > 0){
ptr = GetQueueElement(myQ, i-1);
sum += *ptr;
i--;
}
printf("Sum = %lf\n", sum);
// [5pt] release/free all the dynamically allocated memory
spaces
FreeQueue(myQ);
}
Recall queueADT structure which had the following queue.h interface: /* queue.h */ #ifndef _queue_h #define _queue_h...
Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double data type. 1.) Create a program that produces the following output OUTPUT: Q Quit Enter your choice: e Enter an item: 1.1 E Enqueue D Dequeue s-show queue ← showMenuO function called in main) OQuit // screen clears-.. continue enqueuing.screen clearing with each iteration Enter your choice: e Queue is full. E Enqueue D Dequeue s Show queue 0...
typedef struct queue * Queue;
Queue queueCreate(int maxSize);
void enqueue(Queue q, int item);
int queueFront(Queue q);
int dequeue(Queue q);
int queueSize(Queue q);
void queueDestroy(Queue q)Exercise 1: Writing Assert Based Black Box Unit Tests for a Queue For this exercise you will need a copy of Queue.h, the queue interface for this exercise. You can download it or use the following command to copy it into your current directory cp «dp1091/public_html/2012/tlb/11/Queue.h. And a copy of the testQueue.c, the testing code we...
Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...
Using the below files, Write a program that reads a document containing endnotes indicated in this manner, collects them in a queue, and prints them on the screen. For this lab, you will create a text file called sample.txt and put the following paragraph in it. This part is the beginning. {This part is the footnote.} This part is the end. /* Queue.h contains the declaration of class Queue. Basic operations: Constructor: Constructs an empty queue empty: Checks if a...
Using the provided table interface table.h and the sample linked list code linkedList.c, complete an implementation of the Table ADT. Make sure that you apply the concepts of design by contract (DbC) to your implementation. Once you have fully implemented the table, create a main.c file that implements a testing framework for your table. Your table implementation must ensure that values inserted are unique, and internally sorted within a linked list. table.h #ifndef _TABLE_H #define _TABLE_H //----------------------------------------------------------------------------- // CONSTANTS AND...
Subject: C++ I have created a class called QueueOfIntegers in a file called QueueOfIntegers.h, which is here: #ifndef QueueOfIntegers_H #define QueueOfIntegers_H class QueueOfIntegers { public: int elements[100]; //Array to store integers in the queue int size; // Number of integers in the queue QueueOfIntegers(); // Construct an empty queue bool IsEmpty(); // Returns true if the queue is empty int Peek(); // Returns the integer at the beginning of the Queue without removing it ...
Balment a la medicul Quoc that speciala a circular que has the following private data members and public member functions. The circular que simplemented using an atay. Your submission should consist of four separate files the three source code file header file.implementation file and main program or routine and the program otput. When making the submission, please do not submit it as a file Private data members: int the tray int current size oprema prinete the first met of the...
Objective: In this assignment you will do the following: (1) manipulate pointers, (2) allocate memory dynamically, (3) implement a default constructor, copy constructor and destructor, (4) use only one pointer to add to the back and to dequeue from the front of the queue. Assignment Description: You will implement a doubly-linked circular queue of integers. Consider the following class declarations when implementing BQUEUE. As always, you must comment your declaration and implementation files, "BQUEUE.h" and "BQUEUE.cpp", respectively. class bqnode {...
In c programming The Consumer Submits processing requests to the producer by supplying a file name, its location and a character. It also outputs the contents of the file provided by the producer to the standard output. The Producer Accepts multiple consumer requests and processes each request by creating the following four threads. The reader thread will read an input file, one line at a time. It will pass each line of input to the character thread through a queue...
Study the "Queue as linked list simple example" posted in this module. Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. LListQueue.cpp ///--------------------------------------------------------------- /// File: LListQueue.cpp /// Purpose: Implementation file for a demonstration of a queue /// implemented as an array. Data type: Character /// Programming Language: C++ ///--------------------------------------------------------------- #include "LListQueue.h" ///-------------------------------------------- /// Function: LListQueue() ///...