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

Requirement Write pseudocode and translate it to ONE C-program for the following

ID: 3710552 • Letter: R

Question

Requirement Write pseudocode and translate it to ONE C-program for the following problem. In your pseudocode and C-program, use only what you have learned in this class so far 1. In this problem, you will create and maintain a virtual line for a service. Your program will display a menu with the following items 0. Call a customer 1. Add a customer 2. Quit Please input your command (0-2): When 0 is selected, if there is no customer in the line, give some warning such as there is no customer for now. Otherwise, print the name of the first customer in the line and remove it from the line. When 1 is selected, ask the name of the customer and put the customer to the end of the line. When 2 is selected, your program exits. You must use linked lists in your pseudocode and C-program. No standard library function is allowed to delete or insert a node to the linked list. The data structure of the linked list can be defined in the Data section of your pseudocode.

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>

struct Node
{
char data[100];
struct Node *next;
};

void printMenu() {
printf("0. Call a customer ");
printf("1. Add a customer ");
printf("2. Quit ");
printf("Please input your command (0-2): ");
  
}

int main()
{
struct Node* head = NULL;
struct Node* tail = NULL;
int shouldBreak = 0;
while(1) {
printMenu();
int choice;
scanf("%d", &choice);
if (choice == 0) {
if (head == NULL) {
printf("There is no customer for now! ");
}
else {
printf("%s ", head->data);
struct Node* temp = head;
free(temp);
head = head->next;
}
}
else if (choice == 1) {
struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
printf("Enter name of customer: ");
scanf("%s", temp->data);
temp->next = NULL;
if (head == NULL) {
head = temp;
tail = temp;
}
else {
tail->next = temp;
tail = tail->next;
}
}
else if (choice == 2) {
break;
}
else {
printf("Please enter a valid choice! ");
}
}
return 0;
}

Sample run:

0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 0
There is no customer for now!
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 1
Enter name of customer: Head
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 1
Enter name of customer: Tail
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 0
Head
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 0
Tail
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 0
There is no customer for now!
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 1
Enter name of customer: Head
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 0
Head
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 3
Please enter a valid choice!
0. Call a customer
1. Add a customer
2. Quit
Please input your command (0-2): 2

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