Question

Write In C program

Bart Simpson is a pharmacist and likes to handle his customers request as soon as possible. The customer who comes first getnter a choice. nter customers name and choice: Angie Lipitor he order has been added to the queue. nter a choice. nter custo

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define FULL 10
#include<string.h>
#include<conio.h>
int c=0;
struct node
{
char name[50];
char medication[50];
struct node *next;
};
typedef struct node node;

struct queue
{
int count;
node *front;
node *rear;
};
typedef struct queue queue;

void initialize(queue *q)
{
q->count = 0;
q->front = NULL;
q->rear = NULL;
}

int isempty(queue *q)
{
return (q->rear == NULL);
}

void enqueue(queue *q)
{
   char name[50],medication[50];
if (q->count < FULL)
{   fflush(stdin);
   printf("\nEnter Name");
   gets(name);
   fflush(stdin);
  
   printf("\n Enter medication");
   gets(medication);
node *tmp;
tmp =(struct node*) malloc(sizeof(node));
strcpy(tmp->name,name);
strcpy(tmp->medication,medication);
  
  
tmp->next = NULL;
if(!isempty(q))
{
q->rear->next = tmp;
q->rear = tmp;
}
else
{
q->front = q->rear = tmp;
}
q->count++;
}
else
{
printf("List is full\n");
}
}

void dequeue(queue *q)
{
node *tmp;
//int n = q->front->data;
tmp = q->front;
q->front = q->front->next;
q->count--;
free(tmp);
// return(n);
}

void display(node *head)
{
if(head == NULL)
{
printf("NULL\n");
}
else
{
  
printf("\n%s\t%s", head -> name,head -> medication);
  
display(head->next);
  
}
  
  
  
}

int main()
{
   char name[50];
   char a;
   int ch;
   char medication[50];
queue *q;
a='y';
q = malloc(sizeof(queue));
initialize(q);

while (a=='y')
{
  
   printf("\n 0)Exit Program");
   printf("\n 1)Clear Screen");
   printf("\n 2)Display All Orders");
   printf("\n 3)Enqueue Order ");
   printf("\n 4)Dequeue Order ");
   printf("\nEnter Choice");
   scanf("%d",&ch);
   switch(ch)
   {
       case 0:
           exit(0);
           break;
       case 1:
           {
           //   clrscr();// it will not work in DEV C please don't uncomment it in DEV C compiler
               }
           case 2:
               {
                   printf("\nName\tChoice\n");
               display(q->front);  
                   printf("Total Orders %d",q->count);
                   break;
               }
           case 3:
               {
                  
                   enqueue(q);
                   break;
                  
               }
           case 4:
               {
                   dequeue(q);
                   break;
                  
               }
           default:
               {
                   printf("\nInvalid Choice");
                   break;
               }
              
       }
  
  
       printf("\nDo you want to continue...(y/n)")   ;
       a=getch();      
              
          
          
       }   
       return 0;
  
  
   }   
  
  
  

- cExecutingl - Dev-C++5.11 CAUsers dell\Documentsiqq.exe Enter nedicationlipitor u want to continue. <y/n> TDM-GCC 4.9.2 32-

Add a comment
Know the answer?
Add Answer to:
Write In C program Bart Simpson is a pharmacist and likes to handle his customers' request...
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
  • Using the below files, Write a program that reads a document containing endnotes indicated in this...

    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...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • Assignment 1. You are to write a simple program using Netbeans Java IDE  that consists of two...

    Assignment 1. You are to write a simple program using Netbeans Java IDE  that consists of two classes. The program will allow the user to place an order for a Tesla Model X car. 2. Present the user with a menu selection for each option on the site. We will use JOptionPane to generate different options for the user. See the examples posted for how to use JOPtionPane. 3. Each menu will have multiple items each item will be in the...

  • C Language Program. PLEASE USE DYNAMIC MEMORY AND FOLLOW DIRECTIONS GIVEN. USE FUNCTIONS GIVEN ALSO. Thank...

    C Language Program. PLEASE USE DYNAMIC MEMORY AND FOLLOW DIRECTIONS GIVEN. USE FUNCTIONS GIVEN ALSO. Thank you. NO FFLUSH. Problem 5 (40 points)-Write a program Submit orders.c (Note: you wil be dynamically allocating memory for this problem. The second argument on the command line will let you know how much memory you will be allocating. O points if you do not dynamically allocate) Chef Bartolomeo owns a very busy Italian restaurant. He has recently started accepting orders online and every...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • Please write c++ (windows) in simple way and show all the steps with the required output

    please write c++ (windows) in simple way and show all the steps with the required output Write a C++ program that simulates the operation of a simple online banking system The program starts by displaying its main menu as shown in Figure1 splay Account nformatson verity Your credit Card elect vour choice Figure 1 Main menu of the program The menu is composed of the following choices 1. When choice 1 is selected (Display Account information), the program should display...

  • Use c-strings for the following project: Write a C++ program that declares an array containing up...

    Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...

  • Can you help us!! Thank you! C++ Write a program that can be used by a...

    Can you help us!! Thank you! C++ Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...

  • Write a C++ program that uses a structure to store the following inventory information in a...

    Write a C++ program that uses a structure to store the following inventory information in a file: ⦁   Item description, Quantity on hand, Wholesale cost, Retail cost, and Date added to inventory. ⦁   Use a char array for item description and date. ⦁   The program should have a menu that allows the user to perform the following tasks: i.   Add a new record at the end of the file. ii.   Display any record in the file. iii.   Change any record...

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