Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

WordProcessorInterface: For this question, you are going to build a simple word

ID: 3531077 • Letter: W

Question


WordProcessorInterface:

For this question, you are going to build a simple word processor that takes input from the user (words), "remembers" them up, monitors for user command for undoing certain words, and monitors for user command for printing the stored words into a file. For the time being, we want to keep the program simple by taking the user out of the problem, so that your task is to build the core functionality of the word processor for this question only. Doing this will also facilitate testing. For the bonus part though, you can add the user back into the problem and make sure the rest of your code still works. You are given an interface WordProcessorlnterface that specifies the methods needed for a basic word processor. Make sure you read the comments so you implement the methods according to the specifications. Implement this interface in a class called WordProcessor. The data structure you will implement to remember the words that a user types is called a StackQueue, which has both Stack and Queue functionality. To make this work, you must implement the data structure as a doubly-linked list, where each node stores a single word and the necessary pointers. In this way, each word that gets entered will be queued up by your word processor. Likewise, each undo will pop the most recently entered word. When the program is done, it will dequeue the structure and the words will show up in the correct order. To store a node, you will need to create a node class, with basic mutator, accessor and toString methods. Basic Interface for a Word Processor. The Data structure is to be a doubly-linked list, with both queue and stack behaviours. public interface WordProcessorlnterface Add a word to the processor. "Enqueue/Push". #param word New word that has been typed. return Return true if successfully added to the word processor public boolean type(String word) Remove a word from the processor. "Pop". return Return true if successfully removed from the word processor public boolean undo(); Print a word from the processor. "Dequeue". return The first word to be printed. public String print(); Boolean method to determine if a word processor is empty. return True if empty, false otherwise. public boolean isEmpty();

Explanation / Answer

 #include<stdio.h>
#include<stdlib.h>
/*Queue has five properties. capacity stands for the maximum number of elements Queue can hold.
Size stands for the current size of the Queue and elements is the array of elements. front is the
index of first element (the index at which we remove the element) and rear is the index of last element
(the index at which we insert the element) */

typedef struct Queue
{
int capacity;
int size;
int front;
int rear;
int *elements;
}Queue;
/* crateQueue function takes argument the maximum number of elements the Queue can hold, creates
a Queue according to it and returns a pointer to the Queue. */

Queue * createQueue(int maxElements)
{
/* Create a Queue */
Queue *Q;
Q = (Queue *)malloc(sizeof(Queue));
/* Initialise its properties */
Q->elements = (int *)malloc(sizeof(int)*maxElements);
Q->size = 0;
Q->capacity = maxElements;
Q->front = 0;
Q->rear = -1;
/* Return the pointer */
return Q;
}
void Dequeue(Queue *Q)
{
/* If Queue size is zero then it is empty. So we cannot pop */
if(Q->size==0)
{
printf("Queue is Empty ");
return;
}
/* Removing an element is equivalent to incrementing index of front by one */
else
{
Q->size--;
Q->front++;
/* As we fill elements in circular fashion */
if(Q->front==Q->capacity)
{
Q->front=0;
}
}
return;
}
int front(Queue *Q)
{
if(Q->size==0)
{
printf("Queue is Empty ");
exit(0);
}
/* Return the element which is at the front*/
return Q->elements[Q->front];
}
void Enqueue(Queue *Q,int element)
{
/* If the Queue is full, we cannot push an element into it as there is no space for it.*/
if(Q->size == Q->capacity)
{
printf("Queue is Full ");
}
else
{
Q->size++;
Q->rear = Q->rear + 1;
/* As we fill the queue in circular fashion */
if(Q->rear == Q->capacity)
{
Q->rear = 0;
}
/* Insert the element in its rear side */
Q->elements[Q->rear] = element;
}
return;
}
int main()
{
Queue *Q = createQueue(5);
Enqueue(Q,1);
Enqueue(Q,2);
Enqueue(Q,3);
Enqueue(Q,4);
printf("Front element is %d ",front(Q));
Enqueue(Q,5);
Dequeue(Q);
Enqueue(Q,6);
printf("Front element is %d ",front(Q));
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote