CS301 ASSIGNMENT 2 SOLUTION FALL 2021
Total Marks: 20
Due Date: 21 Dec 2021
Uploading Instruction
Submit the assignment in .cpp format only
Files Must be submitted in a single file.
C++ code file (file name should be your VUID) example bc210200000.cpp
Assignment Overview
Made Patient Information System Program in C++ with according to age wise queue system if patient age is higher than you given higher priority.
CODE SOLUTION:
// Provide by VU Answer
// if you newly assignment freely WhatsApp us 03162965677
// We will help you perfectly
#include <iostream>
using namespace std;
class node // using node for class declaration
{
public:
int age;
node *next;
};
class Priority_Queue // priority queue in class declaration
{
private:
node *f;
public:
Priority_Queue()
{
f = NULL;
}
void insert(int p) // insert nodes in decreasing order
{
node *t, *q;
t = new node;
t->age = p;
if (f == NULL || p > f->age)
{
t->next = f;
f = t;
}
else
{
q = f;
while (q->next != NULL && q->next->age >= p)
q = q->next;
t->next = q->next;
q->next = t;
}
}
void delet()
{
node *t;
if (f == NULL) // if queue is null
cout << "Queue Underflow\n";
else
{
t = f;
cout << "Deleted item is: " << t->age << endl;
f = f->next;
delete(t);
}
}
void show() //print queue
{
node *ptr;
ptr = f;
if (f == NULL)
cout << "Queue is empty"<<endl;
else
{
cout << "Queue is : "<<endl;
while (ptr != NULL)
{
cout << ptr->age << endl;
ptr = ptr->next;
}
}
}
};
int main()
{
int c, p;
Priority_Queue pq;
cout<<""<<endl;
cout << "---Welcome to Patient Information System---" <<endl;
cout<<"Enter your choice of the activity"<<endl;
do
{
cout<<""<<endl;
cout << "1.Insert"<<endl;
cout << "2.Delete"<<endl;
cout << "3.Display"<<endl;
cout << "4.Exit"<<endl;
cout<<""<<endl;
cout << "Enter your choice : ";
cin >> c;
switch (c)
{
case 1:
cout << "Input the item value to be added in the queue : ";
cin >> p;
pq.insert(p);
break;
case 2:
pq.delet();
break;
case 3:
pq.show();
break;
case 4:
break;
default:
cout << "Wrong choice"<<endl;
}
} while (c != 4);
cout << endl;
return 0;
}
SEE OUTPUT ACCORDING TO ASSIGNMENT
Important Materials Check Also:
CS301 Solved Midterm Papers by Moaaz
PLEASE NOTE:
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before submitting copy-paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an assignment check your assignment requirement file.
If you need some help and question about files and solutions share them with us.
1 Comments
thanks for required material
ReplyDelete