Question

WRITE A C PROGRAM

PLEASE WRITE COMMENTS EXPLAINING THE PROGRAM

THANKS

Qn 1. A gaming company consists of many kind of games and each customer orders online to buy a game. The gaming company will

The program flow is as follows: The games should be saved in a linked list. The list of games ordered by customers should be

hat would you like to do? (1) Display the current stock (linked-1ist) (2) Add a game to stock (linked-list) (3) - Display nex

Qn 1. A gaming company consists of many kind of games and each customer orders online to buy a game. The gaming company will search for the specific game upon customers request in the order of first come first served basis. The gaming company has the following requirements. (10marks) 1. There are many kinds of games available (at least ten). They may have more than one game for each genre The customers list is organised in a Queue as a first come first served basis The gaming company should be able to retrieve the data of the last sold games. 2. 3. Your program should consist of a linked list with the following features a.) Insertion at the head b) Insertion at the tail c.) Deletion from the head d.) Deletion form the tail e.) Deleting specific element from the list The next part should be implementing a Stack inherited from the above linked list with the following features a.) Pop b.) Push c.) Top The next part should be implementing a Queue inherited from the above linked list with the following features a.) Enqueue b.) Dequeue c.) Top
The program flow is as follows: The games should be saved in a linked list. The list of games ordered by customers should be saved in a queue. You should take the order from the beginning of the queue and search for it in the linked list then delete it and put this game name in a stack to be able to retrieve in the last sold game. Sample screenshots of the output follows:
hat would you like to do? (1) Display the current stock (linked-1ist) (2) Add a game to stock (linked-list) (3) - Display next order info (4) Display al1 orders (5)Add order to que (6) Process the next order (7) - Revers last order (8)Display info of last order (9)-Quit Program ame Name: Final Fantasy ame Name: Forza Horizon ame Name: Flight Simulator ame Name: God of War ame Name: Gears of War ame Name: Guitar Hero ame Name: Halo ame Name: Metal Gear Solid ame Name: Minecraft ame Name: Sonic Mania ame Name: Skyrim ame Name: Tekken ame Name: World of Warcraft hat would you like to do? (1) Display the current stock (linked-list) (2) - Add a game to stock (linked-list) (3)Display next order info (4) Display all orders (5) - Add order to que (6)Process the next order (7) - Revers last order (8)- Display info of last order 9) Quit Program The next order is for: The game they ordered is: Andrew Minecraft
0 0
Add a comment Improve this question Transcribed image text
Answer #1

According to the given question we have to write the program in c language and also given certain requirements for the given program.

so here we are written c program as follows:

#include<bits/stdc++.h>
using namespace std;

struct node
{
int data;
struct node *next;
};

struct mystack
{
struct node *top;
};

struct myqueue
{
node *front,*rear;
};

void add_front(node** head);
void add_end(node** head);
void rem_front(node** head);
void rem_end(node** head);
void rem_random(node** head);
void viewnode(struct node *p);

void push(struct mystack*);
void pop(struct mystack*);
node* Top(struct mystack*);
void show(struct mystack*);
struct node* createnode(void);
struct mystack* createmystack(void);

void Enqueue(struct myqueue*);
void Dequeue(struct myqueue*);
node* Top(struct myqueue*);
void show(struct myqueue*);
struct myqueue* createmyqueue(void);

int main()
{
myqueue *q = createmyqueue();
mystack *s = createmystack();
int i;
for(i=1;i<=8;i++) //insert 8 items in queue
Enqueue(q);
show(q); //Display contents of queue
for(i=1;i<=3;i++) //delete 3 items from queue
Dequeue(q);
show(q); //Display contents of queue

for(i=1;i<=8;i++) //insert 8 items in stack
push(s);
show(s); //Display contents of stack
for(i=1;i<=3;i++) //delete 3 items from stack
pop(s);
show(s); //Display contents of stack
return 0;
}

void add_front(node** head)
{
node *new_node=createnode();
if(*head==NULL) //If list is empty
*head=new_node;
else
{
new_node->next=*head;
*head=new_node; //update head pointer to the new node
}
}

void add_end(node** head)
{
node *new_node=createnode();
node *p=*head;
if(*head==NULL) //If list is empty
*head=new_node;
else
{
while(p->next!=NULL) //move till end
p=p->next;
p->next=new_node; //insert new node at end
}
}

void rem_front(node** head)
{
node p = head;
if(p==NULL) //empty list
{
cout<<"List is already empty\n";
}
else
{
node *r=p;
*head=(*head)->next; //update head
delete r;
}
}


void rem_end(node** head)
{
node p = head;
node *prev;
if(p==NULL)
cout<<"List is already empty\n";
else
{
if(p->next==NULL) //Only 1 node in the list
{
*head=NULL; //head will now point to NULL indicating empty list
}
else
{
while(p->next) //move till end
{
prev=p;
p=p->next;
}
prev->next=NULL;
}
delete p;
}
}

void rem_random(node** head)
{
node p = head;
node *prev=NULL;
int key;
cout<<"Enter the value to be deleted: ";
cin>>key;

if(p==NULL)
cout<<"List is already empty\n";
else
{
while(p && p->data!=key) //move till end
{
prev=p;
p=p->next;
}
if(p==NULL)
cout<<"Value to be deleted is not found\n";
else
{
if(prev==NULL) //1st node is to deleted
{
*head=(*head)->next;
}
else
{
prev->next=p->next;
}
delete p;
}
delete p;
}
}

void viewnode(struct node *p)
{
if(p==NULL)
printf("node is empty\n");
else
{
while(p)
{
printf("%d\t",p->data);
p=p->next;
}
}
}

struct node *createnode()
{
struct node *n;
n=new node;
printf("Enter data: ");
scanf("%d",&n->data);
n->next=NULL;
return(n);
}

struct mystack* createmystack()
{
struct mystack *stk;
stk=(struct mystack*)malloc(sizeof(struct mystack));
stk->top=NULL;
return(stk);
}

void push(struct mystack *stk)
{
struct node *p;
p=createnode();
if(stk->top==NULL) //stack is empty
stk->top=p;
else
{
p->next=stk->top;
stk->top=p; //update top of stack
}
}
void pop(struct mystack *stk)
{
struct node *r;
if(stk->top==NULL) //stack is empty
printf("Stack is empty\n");
else
{
r=stk->top;
stk->top=stk->top->next;
free(r); //release memory
}
}
node Top(struct mystack stk)
{
if(stk->top==NULL) //stack is empty
return NULL;
return stk->top;
}

void show(struct mystack *stk)
{
struct node *p;
if(stk->top==NULL) //stack is empty
printf("Stack is empty\n");
else
{
p=stk->top;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
}

struct myqueue* createmyqueue()
{
struct myqueue *q;
q=(struct myqueue*)malloc(sizeof(struct myqueue));
q->front=NULL;
q->rear=NULL;
return(q);
}

void Enqueue(struct myqueue *q)
{
struct node *p;
p=createnode();
if(q->front==NULL) //queue is empty
{
q->front=p;
q->rear=p;
}
else
{
q->rear->next=p; //Append this node at end
q->rear=p; //update rear of queue
}
}

void Dequeue(struct myqueue *q)
{
struct node *r;
if(q->front==NULL) //queue is empty
printf("Queue is empty\n");
else
{
r=q->front;
if(q->front==q->rear) //Only single node was present in the queue which is now deleted
{
q->rear==NULL;
}
q->front=q->front->next;
free(r); //release memory
}
}

node Top(struct myqueue q)
{
if(q->front==NULL) //queue is empty
return NULL;
return q->front;
}

void show(struct myqueue *q)
{
struct node *p;
if(q->front==NULL) //queue is empty
printf("Queue is empty\n");
else
{
p=q->front;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
}

Below is the screenshot of output

CAUsers Prakher 1Documents ctest1.exe Enter data: 10 Enter data: 20 Enter data: 30 Enter data: 40 Enter data: 50 Enter data

Although the main() is not meaningful here but I have added it just to show you that all the functions are working properly You can modify the main() as per your requirement.

Hence we have written c program and also done all the requirements given in the question clearly.

Add a comment
Know the answer?
Add Answer to:
Qn 1. A gaming company consists of many kind of games and each customer orders online to buy a ga...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • ASSIGNMENT DUE DATE GOT PUSHED BACK TO LATE THIS WEEK. PLEASE READ COMMENTS AND CODE BEFORE...

    ASSIGNMENT DUE DATE GOT PUSHED BACK TO LATE THIS WEEK. PLEASE READ COMMENTS AND CODE BEFORE ANSWERING CODING SECTIONS HW07 #Q1-Q5 HW08 #Q1-Q2 // READ BEFORE YOU START: // Please read the given Word document for the project description with an illustrartive diagram. // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, standard, and a linked list of absents. // Please read the instructions...

  • Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games...

    Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games One of the nice things about Java is it is very easy to do fun things with graphics. The start code provided here will display a deck of cards on the screen and shuffle them. Your mission, is to start with this code and build a card game. Blackjack, poker solitaire, what ever your heart desires. Blackjack is the easiest. Obviously any program you...

  • n JAVA, students will create a linked list structure that will be used to support a...

    n JAVA, students will create a linked list structure that will be used to support a role playing game. The linked list will represent the main character inventory. The setting is a main character archeologist that is traveling around the jungle in search of an ancient tomb. The user can add items in inventory by priority as they travel around (pickup, buy, find), drop items when their bag is full, and use items (eat, spend, use), view their inventory as...

  • Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU...

    Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...

  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • in c++ please Page 1 of 3 (PRO) Project Assignment Instructions Last Charged: 6/1/2020 Read and...

    in c++ please Page 1 of 3 (PRO) Project Assignment Instructions Last Charged: 6/1/2020 Read and follow the directions below carefully and perform the steps in the order listed. You will be solving one program as instructed and turning in your work electronically via an uploaded file within Eagle Online/Canvas and copy & paste the program to the Text Entry box as well. Make sure and check your work prior to uploading the assignment (NOTE: For Steps 1 & 2...

  • Customer (CustomerId, CustomerName) Employee (EmployeeId, EmployeeName, Salary, SupervisorId) Product(ProductId, ProductName, ListPrice) Orders (OrderId, OrderDate, CustomerId, EmployeeId,...

    Customer (CustomerId, CustomerName) Employee (EmployeeId, EmployeeName, Salary, SupervisorId) Product(ProductId, ProductName, ListPrice) Orders (OrderId, OrderDate, CustomerId, EmployeeId, Total) OrderedProduct (OrderId, ProductId, Quantity, Price) Write the code to complete the methods in OrderJDBC.java (look for TODO items). <---**IN BOLD** throughout code. /* OrderJDBC.java - A JDBC program for accessing and updating an order database on MySQL. */ import java.io.File; import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.Scanner; /** * An application for...

  • JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question...

    JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question 12 pts Which is a valid constructor for Thread? Thread ( Runnable r, int priority ); Thread ( Runnable r, String name ); Thread ( int priority ); Thread ( Runnable r, ThreadGroup g ); Flag this Question Question 22 pts What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? pause(). sleep(). hang(). kill(). Flag...

  • The following are screen grabs of the provided files Thanks so much for your help, and have a n...

    The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT