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

this is the code so far , i got this answer but it has some errors and also it h

ID: 672647 • Letter: T

Question

this is the code so far , i got this answer but it has some errors and also it has 3 parts missing

1) Display total number of smoker( this part shows an error where it is declared in case 6 and Also in other place where it said "count")

2) Search for patient with highest point(these parts are missing

3) Move the patient with highest point to the end(missing)

4)delete the patient by the name(this current program deleting all the patient without asking the name)

kindly help me out


#include <iostream>
#include <string>
using namespace std;
struct Node
{
string name;
int id;
int age;
string smoker;
string hbp;
string hfd;
int points;
Node *ptr;
};

Node *startPtr = NULL;

void getInfo()
{
Node *p, *p2;
p = new Node;
int agePoints;
int smkPoints;
int hbpPoints;
int hfdPoints;
int count=0;

cout << "   Please enter the name of the patient : ";
cin >> p->name;
cout << "Please enter the ID";
cin >> p->id;
cout << "   Please enter the age of the patient : ";
cin >> p->age;
cout << "   Is he/she a smoker (y/n) : ";
cin >> p->smoker;
cout << "   Does he/she have high blood pressure? (y/n) : ";
cin >> p->hbp;
cout << "   Does he/she have a high fat diet? (y/n) : ";
cin >> p->hfd;
cout << endl;
p->ptr = NULL;
if (p-> smoker =="Yes")
count++;

if (p-> age < 18)
{
agePoints = 2;
}
else if (p->age > 18 && p->age <30)
{
agePoints = 3;
}
else
{
agePoints = 4;
}

if (p->smoker == "Y" || p->smoker == "y")
{
p->smoker = "Yes";
smkPoints = 4;
}
else
{
p->smoker = "non smoker";
smkPoints = 0;
}

if (p->hbp == "Y" || p->hbp == "y")
{
p->hbp = "High blood pressure";
hbpPoints = 4;
}
else
{
p->hbp = "Normal blood pressure";
hbpPoints = 0;
}

if (p->hfd == "Y" || p->hfd == "y")
{
p->hfd = "High fat diet";
hfdPoints = 1;
}
else
{
p->hfd = "Low fat diet";
hfdPoints = 0;
}

p->points = agePoints + smkPoints + hbpPoints + hfdPoints;

if (startPtr == NULL)
{
startPtr = p;
}
else
{
p2 = startPtr;
while (p2->ptr != NULL)
   p2 = p2->ptr;
p2->ptr = p;
}
}

void delete_start_node()
{
Node *p;
p = startPtr;
startPtr = startPtr->ptr;
delete p;
}

void delete_end_node()
{
Node *p1, *p2;
if (startPtr == NULL)
cout << "The List is empty! ";
else
{
p1 = startPtr;
if (p1->ptr == NULL)
{
   delete p1;
   startPtr = NULL;
}
else
{
   while (p1->ptr != NULL)
   {
    p2 = p1;
    p1 = p1->ptr;
   }
   delete p1;
   p1->ptr = NULL;
}
}
}

void dispsmoker()
{
Node *p;
p = startPtr;

if (p == NULL)
cout << "Empty List! ";

while (p != NULL)
{
if (p == NULL)
   cout << "Empty List! ";
else if(p->smoker=="Yes")
{
   cout << "   Name               : " << p->name << endl;
   cout << "   Age                : " << p->age << endl;
   cout << "   Smoker             : " << p->smoker << endl;
   cout << "   Blood Pressure     : " << p->hbp << endl;
   cout << "   Fat Diet           : " << p->hfd << endl;
   cout << "   Points             : " << p->points << endl;
   cout << endl;
}
p = p->ptr;
}
//cout<<" total number of smokers:"<<count;
}

void dispHBP()
{
Node *p;
p = startPtr;

if (p == NULL)
cout << "Empty List! ";

while (p != NULL)
{
if (p == NULL)
   cout << "Empty List! ";
else if(p->hbp=="High blood pressure")
{
   cout << "   Name               : " << p->name << endl;
   cout << "   Age                : " << p->age << endl;
   cout << "   Smoker             : " << p->smoker << endl;
   cout << "   Blood Pressure     : " << p->hbp << endl;

cout << "   Fat Diet           : " << p->hfd << endl;
   cout << "   Points             : " << p->points << endl;
   cout << endl;
}
p = p->ptr;
}
}

void dispHFD()
{
Node *p;
p = startPtr;

if (p == NULL)
cout << "Empty List! ";

while (p != NULL)
{
if (p == NULL)
   cout << "Empty List! ";
else if(p->hfd=="High fat diet")
{
   cout << "   Name               : " << p->name << endl;
   cout << "   Age                : " << p->age << endl;
   cout << "   Smoker             : " << p->smoker << endl;
   cout << "   Blood Pressure     : " << p->hbp << endl;
   cout << "   Fat Diet           : " << p->hfd << endl;
   cout << "   Points             : " << p->points << endl;
   cout << endl;
}
p = p->ptr;
}
}
Node* removeptr(Node* prev)
{
if (prev)
{
if (prev->ptr)
{
   Node* p = prev->ptr;
   prev->ptr = p->ptr;
   return p;
}
}
else if (startPtr)
{
Node* p = startPtr;
startPtr = startPtr->ptr;
return p;
}
return NULL;
}


void sortAge()
{
Node* startPtr2 = NULL;

while (startPtr)
{
Node* prev = NULL;
Node* curr = startPtr;
Node* prevMax = NULL;
int max = startPtr->age;

while (curr)
{
   if (curr->age > max)
   {
    max = curr->age;
    prevMax = prev;
   }
   prev = curr;
   curr = curr->ptr;
}

// Node with the highest age found pass throug the list.
Node* xferNode = removeptr(prevMax);

if (xferNode)
{
   xferNode->ptr = startPtr2;
   startPtr2 = xferNode;
}
}
startPtr = startPtr2;
}

void search()
{
Node *p,*x=NULL;
p = startPtr;

int max=p->points;
while (p != NULL)
{
if(p->points>max)
   x=p;
p = p->ptr;
}
cout << "   Name               : " << x->name << endl;
cout << "   Age                : " << x->age << endl;
cout << "   Smoker             : " << x->smoker << endl;
cout << "   Blood Pressure     : " << x->hbp << endl;
cout << "   Fat Diet           : " << x->hfd << endl;
cout << "   Points             : " << x->points << endl;
cout << endl;
}
int main()
{
Node *p;
p = startPtr;

char selection;
//Node *smokers, *hbp, *hfd = NULL;
do
{
cout << "               Patient Menu ";
cout << "   ============================================= ";
cout << "   1. Insert a new record ";
cout << "   2. List smoker patients "; // smoker patient
cout << "   3. List HBP patients "; // high blood pressure patient
cout << "   4. List HFD patients "; // high fat diet patient
cout << "   5. Delete a patient record by given name ";
cout << "   6. Count of smokers ";
cout << "   7. Search the patient with highest point ";
cout << "   8. Exit the program ";
cout << "   ============================================= ";
cout << "   Enter your selection: ";
cin >> selection;
cout << endl;

switch (selection)
{
case '1':
   getInfo();
   break;

case '2':
   dispsmoker();
   break;

case '3':
   dispHBP();
   break;

case '4':
   dispHFD();
   break;

case '5':
   delete_start_node();
   delete_end_node();
   break;
case '6':
// cout<<" total number of smokers:" <<count;
   break;
case '7':
      search();
case '8':
   cout << "   Goodbye! ";
   return 0;
   break;

default:
   break;
}
}while (selection != 6);

system("pause");
return 0;
}

Explanation / Answer

>Modify your code from here:
case '2':
disp(smokers);
break;
case '3':
disp(hbp);
break;
case '4':
disp(hfd);
break;

>Make the code changes for all the below mentioned to null
Node *smokers, *hbp, *hfd = NULL;

>Mean while in this program keep a separate linked list for each of its type
smoker, hbp, hfd

>And change this in the code:
void disp()
void disp(Node* linkedList)