C++ Programming:
So I received help with a code that takes a diabetics name, age, food consumed, and the blood
sugar (before and after) using linked lists and then copies the information to a file. How would I
make this so that the Person class only holds name and age, but then an inherited class Diabetic
takes the reigns and has name+age from Person and then adds the food, and blood sugar results?
Is that even possible with linked lists? And how would I create an option on whether user would
like to copy to a file instead of automatically copying it?
code:
Program code:
#include
#include
#include
using namespace std;
struct Record
{
string name;
int age;
string food;
int after;
int before;
Record *next;
}*head;
class People {
public:
int count=0;
Record* create_node(string,int,string,int,int);
void insert();
void display();
People()
{
head = NULL;
}
};
int main()
{
cout << \"patient details\" << endl << endl;
head = NULL;
People p;
p.insert();
p.insert();
p.display();
return 0;
}
Record *People::create_node(string nam,int a,string foo,int af,int bef)
{
struct Record *newRecord, *s;
newRecord = new Record;
if (newRecord == NULL)
{
cout<<\"Memory not allocated \"< name = nam;
newRecord -> age = a;
newRecord -> food = foo;
newRecord -> after = af;
newRecord -> before = bef;
newRecord -> next = NULL;
return newRecord;
}
}
void People::insert()
{
string s_name;
int s_age;
string s_food;
int s_after;
int s_before;
Record *Record_ptr,*newRecord;
ofstream outfile;
outfile.open(\"Patient.txt\");
cout<<\"Enter patient details\";
cin>>s_name>>s_age>>s_food>>s_after>>s_before;
outfile<next = NULL;
}
else
{
Record_ptr = head;
while(Record_ptr -> next)
Record_ptr = Record_ptr -> next;
Record_ptr -> next = newRecord;
}
outfile.close();
}
void People::display()
{
Record *Display_ptr;
Display_ptr = head;
while(Display_ptr != NULL)
{
cout << Display_ptr -> name << endl;
cout << Display_ptr -> age << endl;
cout << Display_ptr -> food << endl;
cout << Display_ptr -> after << endl;
cout << Display_ptr -> before << endl;
Display_ptr = Display_ptr -> next;
cout << endl;
}
cout<<\"\ Number of patient in file:\"<
Solution
#include
#include
#include
#include
#include
#include
class patient
{
public:
char name[20];
char blood_group[5];
int pat_id;
long int phn;
int a;
void patientdata();
void showdata();
};
void patient::patientdata()
{
cout<<\"
*****************************************************************************
**\ \";
cout<<\" \ \ \\t\\t\\tCreate New Patient Database \";
cout<<\"
*****************************************************************************
**\ \";
cout<<\"\ Enter Patient ID : \";
cin>>pat_id;
cout<<\"\ Enter Patient Name : \";
cin>>name;
cout<<\"\ Enter Patient Blood Group : \";
cin>>blood_group;
fflush(stdin);
cout<<\"\ Enter Patient Phone : \";
cin>>phn;
}
void patient::showdata()
{
cout<<\"\ Patient ID\\t: \"<>a;
char x;
switch (a)
{
case 1:
clrscr();
fstream f;
f.open(\"patient\",ios::in|ios::out|ios::ate|ios::app|ios::binary);
char an.
C++ ProgrammingSo I received help with a code that takes a diabet.pdf
1. C++ Programming:
So I received help with a code that takes a diabetics name, age, food consumed, and the blood
sugar (before and after) using linked lists and then copies the information to a file. How would I
make this so that the Person class only holds name and age, but then an inherited class Diabetic
takes the reigns and has name+age from Person and then adds the food, and blood sugar results?
Is that even possible with linked lists? And how would I create an option on whether user would
like to copy to a file instead of automatically copying it?
code:
Program code:
#include
#include
#include
using namespace std;
struct Record
{
string name;
int age;
string food;
int after;
int before;
Record *next;
}*head;
class People {
public:
int count=0;
Record* create_node(string,int,string,int,int);
void insert();
void display();
People()
{
head = NULL;
}
};
int main()
2. {
cout << "patient details" << endl << endl;
head = NULL;
People p;
p.insert();
p.insert();
p.display();
return 0;
}
Record *People::create_node(string nam,int a,string foo,int af,int bef)
{
struct Record *newRecord, *s;
newRecord = new Record;
if (newRecord == NULL)
{
cout<<"Memory not allocated "< name = nam;
newRecord -> age = a;
newRecord -> food = foo;
newRecord -> after = af;
newRecord -> before = bef;
newRecord -> next = NULL;
return newRecord;
}
}
void People::insert()
{
string s_name;
int s_age;
string s_food;
int s_after;
int s_before;
Record *Record_ptr,*newRecord;
ofstream outfile;
outfile.open("Patient.txt");