# CS301 Assignment 2 Solution Fall 2021 - Data Structures Solution

Proper Accurate Complete CS301 Assignment 2 Solution Fall 2021. Easy to Prepare Correct CS301 Assignment No 2 Solution Fall 2021 and Download Solution CPP, Word, PDF File Given Below.

## CS301 ASSIGNMENT 2 SOLUTION FALL 2021

Total Marks: 20

Due Date: 21 Dec 2021

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:

// if you newly assignment freely WhatsApp us 03162965677

#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 Midterm Past Papers

CS301 Solved Midterm Papers by Moaaz

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.