Coffee Order Queue Management Program
Coffee Order Queue Management Program
8
05
05
05
0
01
01
01
01
15
15
15
15
Name: Gopika V Scan to verify results
24
24
24
24
Email: 241501058@[Link]
Roll no: 241501058
Phone: 6380725844
Branch: REC
Department: I AIML AD
Batch: 2028
Degree: B.E - AI & ML
8
58
58
8
05
05
10
0
NeoColab_REC_CS23231_DATA STRUCTURES
01
01
01
0
15
15
15
15
24
24
24
24
REC_DS using C_Week 4_COD_Question 1
Attempt : 1
Total Mark : 10
Marks Obtained : 10
Section 1 : Coding
1. Problem Statement
58
58
8
05
05
0
Imagine a bustling coffee shop, where customers are placing their orders
01
01
01
01
15
15
15
for their favorite coffee drinks. The cafe owner Sheeren wants to efficiently 15
24
24
24
24
manage the queue of coffee orders using a digital system. She needs a
program to handle this queue of orders.
You are tasked with creating a program that implements a queue for
coffee orders. Each character in the queue represents a customer's coffee
order, with 'L' indicating a latte, 'E' indicating an espresso, 'M' indicating a
macchiato, 'O' indicating an iced coffee, and 'N' indicating a nabob.
Customers can place orders and enjoy their delicious coffee drinks.
8
8
05
05
05
05
Input Format
01
01
01
01
15
15
15
15
24
24
24
24
The input consists of integers corresponding to the operation that needs to be
58
8
05
05
05
performed:
0
01
01
01
01
15
15
15
15
Choice 1: Enqueue the coffee order into the queue. If the choice is 1, the
24
24
24
24
following input is a space-separated character ('L', 'E', 'M', 'O', 'N').
58
58
8
05
05
10
0
queue:
01
01
01
0
15
15
15
15
24
24
24
24
If the choice is 1:
1. Insert the given order into the queue and display "Order for [order] is
enqueued." where [order] is the coffee order that is inserted.
2. If the queue is full, print "Queue is full. Cannot enqueue more orders."
If the choice is 2:
58
58
8
05
05
0
1. Dequeue a character from the queue and display "Dequeued Order: " followed
01
01
01
01
by the corresponding order that is dequeued.
15
15
15
15
24
24
24
24
2. If the queue is empty without any orders, print "No orders in the queue."
If the choice is 3:
1. The output prints "Orders in the queue are: " followed by the space-separated
orders present in the queue.
2. If there are no orders in the queue, print "Queue is empty. No orders available."
If the choice is 4:
8
05
05
05
05
01
01
01
01
15
15
15
24
24
24
24
58
8
05
05
05
0
01
01
01
01
15
15
15
15
24
24
24
24
Refer to the sample output for the exact text and format.
Sample Test Case
Input: 1 L
1E
1M
1O
1N
1O
3
8
58
58
8
05
05
10
0
2
01
01
01
0
3
15
15
15
15
24
24
24
24
4
Output: Order for L is enqueued.
Order for E is enqueued.
Order for M is enqueued.
Order for O is enqueued.
Order for N is enqueued.
Queue is full. Cannot enqueue more orders.
Orders in the queue are: L E M O N
Dequeued Order: L
Orders in the queue are: E M O N
Exiting program
58
58
8
05
05
0
0
01
01
01
01
Answer
15
15
15
15
24
24
24
24
#include <stdio.h>
#define MAX_SIZE 5
char orders[MAX_SIZE];
int front = -1;
int rear = -1;
void initializeQueue() {
front = -1;
rear = -1;
}
8
8
05
05
05
05
01
01
01
01
15
15
15
24
24
24
24
int isEmpty() {
58
8
05
05
05
return(front==-1 || front>rear);
0
01
01
01
01
}
15
15
15
15
24
24
24
24
int isFull() {
return(rear==MAX_SIZE-1);
}
58
58
8
05
05
front=0;
10
0
01
01
01
0
}
15
15
15
15
rear++;
24
24
24
24
orders[rear]=order;
printf("Order for %c is enqueued.\n",order);
return 1;
}
int dequeue() {
if(isEmpty()){
printf("No orders in the queue.\n");
return 0;
}
58
58
8
05
05
printf("Dequeued order: %c\n",orders[front]);
0
0
01
01
01
01
front++;
15
15
15
if(front>rear){ 15
24
24
24
24
front=rear=-1;
}
return 1;
}
void display() {
if(isEmpty()){
printf("Queue is empty. No orders available.\n");
return;
}
8
8
05
05
05
05
01
01
01
for(int i=front;i<=rear;i++){
15
15
15
15
24
24
24
24
printf("%c",orders[i]);
58
8
05
05
05
}
0
01
01
01
01
printf("\n");
15
15
15
15
}
24
24
24
24
int main() {
char order;
int option;
initializeQueue();
while (1) {
if (scanf("%d", &option) != 1) {
break;
}
switch (option) {
8
58
58
8
case 1:
05
05
10
0
01
01
01
if (scanf(" %c", &order) != 1) {
0
15
15
15
15
break;
24
24
24
24
}
if (enqueue(order)) {
}
break;
case 2:
dequeue();
break;
case 3:
display();
break;
58
58
8
case 4:
05
05
0
0
01
01
01
01
printf("Exiting program");
15
15
15
return 0;
15
24
24
24
24
default:
printf("Invalid option.\n");
break;
}
}
return 0;
}
8
05
05
05
05
01
01
01
01
15
15
15
15
24
24
24
24
58 Rajalakshmi Engineering College
8
05
05
05
0
01
01
01
01
15
15
15
15
Name: Gopika V Scan to verify results
24
24
24
24
Email: 241501058@[Link]
Roll no: 241501058
Phone: 6380725844
Branch: REC
Department: I AIML AD
Batch: 2028
Degree: B.E - AI & ML
8
58
58
8
05
05
10
0
NeoColab_REC_CS23231_DATA STRUCTURES
01
01
01
0
15
15
15
15
24
24
24
24
REC_DS using C_Week 4_COD_Question 2
Attempt : 1
Total Mark : 10
Marks Obtained : 10
Section 1 : Coding
1. Problem Statement
58
58
8
05
05
0
01
01
01
15
15
15
24
24
24
providing quality support.
8
05
05
05
05
ticket from the front of the queue. The program will display the ticket ID of
01
01
01
01
the processed [Link] Queue: Display the ticket IDs of all the
15
15
15
15
24
24
24
24
helpdesk tickets currently in the queue.
58
8
05
05
05
0
01
01
01
01
Input Format
15
15
15
15
24
24
24
24
The input consists of integers corresponding to the operation that needs to be
performed:
Choice 1: Enqueue the ticket ID into the queue. If the choice is 1, the following
input is a space-separated integer, representing the ticket ID to be enqueued into
the queue.
58
58
8
05
05
10
0
Choice 4: Exit the program.
01
01
01
0
15
15
15
15
Output Format
24
24
24
24
The output displays messages according to the choice and the status of the
queue:
If the choice is 1:
1. Insert the given ticket ID into the queue and display "Helpdesk Ticket ID [id] is
enqueued." where [id] is the ticket ID that is inserted.
2. If the queue is full, print "Queue is full. Cannot enqueue."
If the choice is 2:
58
58
8
05
05
0
0
01
01
01
01
1. Dequeue a ticket ID from the queue and display "Dequeued Helpdesk Ticket
15
15
15
15
24
24
24
24
ID: " followed by the corresponding ID that is dequeued.
2. If the queue is empty without any elements, print "Queue is empty."
If the choice is 3:
1. The output prints "Helpdesk Ticket IDs in the queue are: " followed by the
space-separated ticket IDs present in the queue.
2. If there are no elements in the queue, print "Queue is empty."
If the choice is 4:
8
8
05
05
05
05
01
01
01
15
15
15
15
24
24
24
24
If any other choice is entered, print "Invalid option."
58
8
05
05
05
0
01
01
01
01
15
15
15
15
24
24
24
24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 1 101
1 202
1 203
1 204
1 205
1 206
8
58
58
8
05
05
10
0
3
01
01
01
0
2
15
15
15
15
24
24
24
24
3
4
Output: Helpdesk Ticket ID 101 is enqueued.
Helpdesk Ticket ID 202 is enqueued.
Helpdesk Ticket ID 203 is enqueued.
Helpdesk Ticket ID 204 is enqueued.
Helpdesk Ticket ID 205 is enqueued.
Queue is full. Cannot enqueue.
Helpdesk Ticket IDs in the queue are: 101 202 203 204 205
Dequeued Helpdesk Ticket ID: 101
Helpdesk Ticket IDs in the queue are: 202 203 204 205
58
58
8
05
05
0
01
01
01
15
15
15
Answer 15
24
24
24
24
#include <stdio.h>
#define MAX_SIZE 5
int ticketIDs[MAX_SIZE];
int front = -1;
int rear = -1;
int lastDequeued;
void initializeQueue() {
front = -1;
8
8
05
05
05
05
rear = -1;
01
01
01
01
15
15
15
15
}
24
24
24
24
// You are using GCC
58
8
05
05
05
int isEmpty() {
0
01
01
01
01
//type your code here
15
15
15
15
return front==-1;
24
24
24
24
}
int isFull() {
//type your code here
return rear==MAX_SIZE-1;
}
58
58
8
05
05
printf("Queue is full. Cannot enqueue.\n");
10
0
01
01
01
0
}
15
15
15
15
else{
24
24
24
24
rear++;
ticketIDs[rear]=ticketID;
printf("Helpdesk Ticket ID %d is enqueued.\n",ticketIDs[rear]);
}
if(front==-1){
front++;
}
}
int dequeue() {
58
58
8
05
05
//type your code here
0
0
01
01
01
01
if(isEmpty()){
15
15
15
return 0; 15
24
24
24
24
}
else{
lastDequeued=ticketIDs[front];
if(front==rear){
front=-1;
rear=-1;
}
else{
front++;
}
8
8
05
05
05
05
return 1;
01
01
01
01
}
15
15
15
15
24
24
24
24
}
58
8
05
05
05
0
01
01
01
01
void display() {
15
15
15
15
//type your code here
24
24
24
24
int k=front;
if(k==-1){
printf("Queue is empty.\n");
}
else{
printf("Helpdesk Ticket IDs in the queue are: ");
while(k<=rear){
printf("%d ",ticketIDs[k]);
k++;
}
8
58
58
8
05
05
printf("\n");
10
0
01
01
01
0
}
15
15
15
15
}
24
24
24
24
int main() {
int ticketID;
int option;
initializeQueue();
while (1) {
if (scanf("%d", &option) == EOF) {
break;
}
switch (option) {
58
58
8
case 1:
05
05
0
0
01
01
01
01
if (scanf("%d", &ticketID) == EOF) {
15
15
15
break;
15
24
24
24
24
}
enqueue(ticketID);
break;
case 2:
if (dequeue()) {
printf("Dequeued Helpdesk Ticket ID: %d\n", lastDequeued);
} else {
printf("Queue is empty.\n");
}
break;
8
case 3:
05
05
05
05
01
01
01
01
display();
15
15
15
15
break;
24
24
24
24
24 24 24 24
15 15 15 15
}
01 01 01 01
}
05 0 05 0
}
8 58 8 58
return 0;
case 4:
default:
break;
Status : Correct
return 0;
24 24 24 24
15 15 15 15
01 01 0 10 01
05 05 05
8 8 58 8
printf("Invalid option.\n");
printf("Exiting the program\n");
24 24 24 24
15 15 15 15
01 01 01 01
05 0 0 05
8 58 58 8
24 24 24 24
15 15 15 15
Marks : 10/10
01 01 01 01
05 05 05 05
8 8 8 8
58 Rajalakshmi Engineering College
8
05
05
05
0
01
01
01
01
15
15
15
15
Name: Gopika V Scan to verify results
24
24
24
24
Email: 241501058@[Link]
Roll no: 241501058
Phone: 6380725844
Branch: REC
Department: I AIML AD
Batch: 2028
Degree: B.E - AI & ML
8
58
58
8
05
05
10
0
NeoColab_REC_CS23231_DATA STRUCTURES
01
01
01
0
15
15
15
15
24
24
24
24
REC_DS using C_Week 4_COD_Question 3
Attempt : 1
Total Mark : 10
Marks Obtained : 10
Section 1 : Coding
1. Problem Statement
58
58
8
05
05
0
01
01
01
15
15
15
24
24
24
Input Format
8
8
05
05
05
05
01
01
01
15
15
15
15
24
24
24
24
58
8
05
05
05
0
01
01
01
01
15
15
15
15
Option 1: Insert an element into the queue followed by an integer representing
24
24
24
24
the element to be inserted, separated by a space.
58
58
8
05
05
10
0
successfully inserted.
01
01
01
0
2. "Queue is full." if the queue is already full and cannot accept more elements.
15
15
15
15
24
24
24
24
For option 2 (deletion):-
1. The program outputs: "Elements in the queue are: <element1> <element2> ...
<elementN>" where <element1>, <element2>, ..., <elementN> represent the
58
58
8
05
05
0
01
01
01
2. "Queue is empty." if the queue is empty no elements can be displayed.
15
15
15
15
24
24
24
24
05
05
05
01
01
01
01
Input: 1 10
15
15
15
15
24
24
24
24
3
58
8
05
05
05
5
0
01
01
01
01
Output: 10 is inserted in the queue.
15
15
15
15
24
24
24
24
Elements in the queue are: 10
Invalid option.
Answer
#include <stdio.h>
#include <stdlib.h>
#define max 5
int queue[max];
int front = -1, rear = -1;
8
58
58
8
05
05
10
0
01
01
01
// You are using GCC
0
15
15
15
15
int insertq(int *data)
24
24
24
24
{
if(rear==max-1){
return 0;
}
else{
rear++;
queue[rear]=*data;
if(front==-1){
front++;
}
58
58
8
return 1;
05
05
0
0
01
01
01
01
}
15
15
15
} 15
24
24
24
24
void delq()
{
if(front==-1){
printf("Queue is empty.\n");
}
else{
int k=queue[front];
printf("Deleted number is: %d\n",k);
if(front==rear){
8
front=-1;
05
05
05
05
01
01
01
01
rear=-1;
15
15
15
15
24
24
24
24
}
58
8
05
05
05
else{
0
01
01
01
01
front++;
15
15
15
15
}
24
24
24
24
}
//Type your code here
}
void display()
{
//Type your code here
int k=front;
if(k==-1){
printf("Queue is empty.\n");
8
58
58
8
05
05
}
10
0
01
01
01
0
else{
15
15
15
15
printf("Elements in the queue are: ");
24
24
24
24
while(k<=rear){
printf("%d ",queue[k]);
k++;
}
printf("\n");
}
}
int main()
{
58
58
8
int data, reply, option;
05
05
0
0
01
01
01
01
while (1)
15
15
15
{
15
24
24
24
24
if (scanf("%d", &option) != 1)
break;
switch (option)
{
case 1:
if (scanf("%d", &data) != 1)
break;
reply = insertq(&data);
if (reply == 0)
printf("Queue is full.\n");
8
else
05
05
05
05
01
01
01
01
15
15
15
break;
24
24
24
24
case 2:
58
8
05
05
05
delq(); // Called without arguments
0
01
01
01
01
break;
15
15
15
15
case 3:
24
24
24
24
display();
break;
default:
printf("Invalid option.\n");
break;
}
}
return 0;
}
8
58
58
8
05
05
Status : Correct Marks : 10/10
10
0
01
01
01
0
15
15
15
15
24
24
24
24
58
58
8
05
05
0
0
01
01
01
01
15
15
15
15
24
24
24
24
8
8
05
05
05
05
01
01
01
01
15
15
15
15
24
24
24
24
58 Rajalakshmi Engineering College
8
05
05
05
0
01
01
01
01
15
15
15
15
Name: Gopika V Scan to verify results
24
24
24
24
Email: 241501058@[Link]
Roll no: 241501058
Phone: 6380725844
Branch: REC
Department: I AIML AD
Batch: 2028
Degree: B.E - AI & ML
8
58
58
8
05
05
10
0
NeoColab_REC_CS23231_DATA STRUCTURES
01
01
01
0
15
15
15
15
24
24
24
24
REC_DS using C_Week 4_COD_Question 4
Attempt : 1
Total Mark : 10
Marks Obtained : 10
Section 1 : Coding
1. Problem Statement
58
58
8
05
05
0
01
01
01
15
15
15
handle and process print jobs. The system is implemented using a queue 15
24
24
24
24
data structure with an array.
8
05
05
05
05
Input Format
01
01
01
01
15
15
15
15
24
24
24
24
The input consists of integers corresponding to the operation that needs to be
58
8
05
05
05
performed:
0
01
01
01
01
15
15
15
15
Choice 1: Enqueue the print job into the queue. If the choice is 1, the following
24
24
24
24
input is a space-separated integer, representing the pages to be enqueued into
the queue.
58
58
8
05
05
10
0
The output displays messages according to the choice and the status of the
01
01
01
0
queue:
15
15
15
15
24
24
24
24
If the choice is 1:
1. Insert the given page into the queue and display "Print job with [page] pages is
enqueued." where [page] is the number of pages that are inserted.
2. If the queue is full, print "Queue is full. Cannot enqueue."
If the choice is 2:
58
58
8
05
05
0
0
01
01
01
01
1. Dequeue a page from the queue and display "Processing print job: [page]
15
15
15
15
24
24
24
24
pages" where [page] is the corresponding page that is dequeued.
2. If the queue is empty without any elements, print "Queue is empty."
If the choice is 3:
1. The output prints "Print jobs in the queue: " followed by the space-separated
pages present in the queue.
2. If there are no elements in the queue, print "Queue is empty."
If the choice is 4:
8
8
05
05
05
05
01
01
01
15
15
15
15
24
24
24
24
If any other choice is entered, the output prints "Invalid option."
58
8
05
05
05
0
01
01
01
01
15
15
15
15
24
24
24
24
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: 1
10
1
20
1
30
8
58
58
8
05
05
10
0
1
01
01
01
0
40
15
15
15
15
24
24
24
24
1
50
1
60
3
2
3
4
Output: Print job with 10 pages is enqueued.
Print job with 20 pages is enqueued.
Print job with 30 pages is enqueued.
58
58
8
05
05
0
01
01
01
15
15
15
15
Print job with 50 pages is enqueued.
24
24
24
24
Queue is full. Cannot enqueue.
Print jobs in the queue: 10 20 30 40 50
Processing print job: 10 pages
Print jobs in the queue: 20 30 40 50
Exiting program
Answer
// You are using GCC
#include<stdio.h>
#define MAX_SIZE 5
int queue[MAX_SIZE];
8
8
05
05
05
05
int front=-1,rear=-1;
01
01
01
01
15
15
15
15
24
24
24
if(rear==MAX_SIZE-1){
58
8
05
05
05
printf("Queue is [Link] enqueue.\n");
0
01
01
01
01
}
15
15
15
15
else{
24
24
24
24
rear++;
queue[rear]=data;
printf("Print job with %d pages is enqueued.\n",data);
if(front==-1){
front+=1;
}
}
}
void dequeue(){
8
58
58
8
05
05
if(front==-1){
10
0
01
01
01
0
printf("Queue is empty.\n");
15
15
15
15
}
24
24
24
24
else{
int popped=queue[front];
printf("Processing print job: %d pages\n",popped);
if(front==rear){
front=-1;
rear=-1;
}
else{
front+=1;
}
58
58
8
05
05
}
0
0
01
01
01
01
}
15
15
15
void display(){ 15
24
24
24
24
if(front==-1){
printf("Queue is empty.\n");
}
else{
int k=front;
printf("Print jobs in the queue: ");
while(k<=rear){
printf("%d ",queue[k]);
k++;
}
8
8
05
05
05
05
printf("\n");
01
01
01
01
}
15
15
15
15
24
24
24
24
}
58
8
05
05
05
int main(){
0
01
01
01
01
int n,data;
15
15
15
15
do{
24
24
24
24
scanf("%d",&n);
switch(n){
case 1:
scanf("%d",&data);
enqueue(data);
break;
case 2:
dequeue();
break;
case 3:
8
58
58
8
05
05
display();
10
0
01
01
01
0
break;
15
15
15
15
case 4:
24
24
24
24
printf("Exiting program");
break;
default:
printf("Invalid option.");
}
}while(n!=4);
}
58
58
8
05
05
0
0
01
01
01
01
15
15
15
15
24
24
24
24
8
05
05
05
05
01
01
01
01
15
15
15
15
24
24
24
24
58 Rajalakshmi Engineering College
8
05
05
05
0
01
01
01
01
15
15
15
15
Name: Gopika V Scan to verify results
24
24
24
24
Email: 241501058@[Link]
Roll no: 241501058
Phone: 6380725844
Branch: REC
Department: I AIML AD
Batch: 2028
Degree: B.E - AI & ML
8
58
58
8
05
05
10
0
NeoColab_REC_CS23231_DATA STRUCTURES
01
01
01
0
15
15
15
15
24
24
24
24
REC_DS using C_Week 4_COD_Question 5
Attempt : 1
Total Mark : 10
Marks Obtained : 10
Section 1 : Coding
1. Problem Statement
58
58
8
05
05
0
01
01
01
15
15
15
24
24
24
05
05
05
01
01
01
01
15
15
15
24
24
24
24
58
8
05
05
05
The second line consists of N space-separated integers, representing the queue
0
01
01
01
01
elements.
15
15
15
15
24
24
24
24
Output Format
The first line prints "Front: X, Rear: Y" where X is the front and Y is the rear
elements of the queue.
The second line prints the message indicating that the dequeue operation (front
element removed) is performed: "Performing Dequeue Operation:".
The last line prints "Front: M, Rear: N" where M is the front and N is the rear
elements after the dequeue operation.
8
58
58
8
05
05
10
0
01
01
01
0
15
15
15
15
24
24
24
24
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: 5
12 56 87 23 45
Output: Front: 12, Rear: 45
Performing Dequeue Operation:
Front: 56, Rear: 45
Answer
58
58
8
05
05
0
#include <stdio.h>
01
01
01
01
15
15
15
15
#include <stdlib.h>
24
24
24
24
struct Node {
int data;
struct Node* next;
};
8
05
05
05
05
01
01
01
if(rear==NULL){
15
15
15
15
24
24
24
24
newnode->data=d;
58
8
05
05
05
newnode->next=NULL;
0
01
01
01
01
front=newnode;
15
15
15
15
rear=newnode;
24
24
24
24
}else{
newnode->data=d;
newnode->next=NULL;
rear->next=newnode;
rear=newnode;
}
}
void printFrontRear() {
8
58
58
8
05
05
printf("Front: %d,Rear: %d\n",front->data,rear->data);
10
0
01
01
01
0
}
15
15
15
15
24
24
24
24
void dequeue() {
if(front==NULL){
printf("Queue is empty.\n");
}
else{
struct Node* temp=front;
if(front==rear){
front=NULL;
rear=NULL;
}
58
58
8
05
05
else{
0
0
01
01
01
01
front=front->next;
15
15
15
} 15
24
24
24
24
free(temp);
}
}
int main() {
int n, data;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &data);
enqueue(data);
8
}
05
05
05
05
01
01
01
01
printFrontRear();
15
15
15
15
24
24
24
24 24 24 24
15 15 15 15
}
01 01 01 01
05 0 05 0
8 58 8 58
return 0;
dequeue();
Status : Correct
printFrontRear();
24 24 24 24
15 15 15 15
01 01 0 10 01
05 05 05
8 8 58 8
24 24 24 24
15 15 15 15
01 01 01 01
05 0 0 05
8 58 58 8
24 24 24 24
15 15 15 15
Marks : 10/10
01 01 01 01
05 05 05 05
8 8 8 8