You are on page 1of 5

Scenario Problem

Manaswi
20BPS1019

Question
1. Assume that a set of N number of medicines are arrived on a pharmacy store. There
are three category of rack in the pharmacy for three category of medicine such as
tablets, liquids and pastes. Every medicine is associated with a name, price and the
category.

Implement a program to get the N number of medicines to be kept in the rack(requires one
data structure). According to the category arrange the medicines in the respective three
rack’s (requires three data structure). Display the medicines in the racks and the sum of the
price of all the medicines. (Use either stack or queue data structure)

Algorithm
Start
Create a stack to hold the information about the medicined
Get input from user which includes: name, category, price
Store this information in stack

Create 3 stacks to store the medicine in different rack depending in the category i.e. tablets,
liquids or pastes

Find the sum of the medicines in each stack

Find the sum of all the medicined together

Print the medicines in each rack

The price of medicines in each rack

Ans the total price of all the medicines

end
CODE
#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#define MAX 50

int top=-1, top1=-1, top2=-1, top3=-1;

char m[MAX][MAX], t[MAX][MAX], l[MAX][MAX], p[MAX][MAX];

int a,s=0, s1=0, s2=0, s3=0;

void push(char total[10])

top=top+1;

strcpy(m[top], total);

void pop()

top=top-1;

void dis(int top,char r[], char m[MAX][MAX])

if(top==-1){

printf("%s EMPTY\n",r);

else{

printf("The avaible medicines in %s rack are:\n",r);

for(int i=0;i<top+1; i++){

printf("%s\n", m[i]);

}
}

int main()

char n[50],c[50],pr[50];

printf("the no. of medicines:");

scanf("%d",&a);

char q1[]="tablet";

char q2[]="liquid";

char q3[]="paste";

for(int i=0;i<a;i++)

printf("Enter name %d :",i+1);

scanf("%s", n);

push(n);

printf("Enter category %d:",i+1);

scanf("%s", c);

push(c);

printf("Enter price %d:",i+1);

scanf("%s", pr);

push(pr);

for(int i=top;i>=0;i=i-3)

strcpy(n,m[i]);

strcpy(pr,m[i-1]);

strcpy(c,m[i-2]);

int cost = atoi(pr);

s=s+cost;

if (strcmp(c,q1)==0){

top1=top1+1;
strcpy(t[top1],n);

s1=s1+ cost;

pop();

pop();

pop();

else if(strcmp(c,q2)==0){

top2=top2+1;

strcpy(l[top2],n);

s2=s2+ cost;

pop();

pop();

pop();

else if(strcmp(c,q3)==0){

top3=top3+1;

strcpy(p[top3],n);

s3=s3+cost;

pop();

pop();

pop();

dis(top1,q1,t);

dis(top2,q2,l);

dis(top3,q3,p);

printf("Total price of tablets: %d\n",s1);

printf("Total price of liquids: %d\n",s2);

printf("Total price of pastes: %d\n",s3);


printf("Total price: %d\n",s);

OUTPUT

You might also like