(C++) Patients required to take many kinds of medication often
have difficulty in remembering when to take their medicine. Given
the following set of medications, write a function that prints an
hourly table indicating what medication to take at any given hour.
Use a counter variable clock to go through a 24-hour day. Print the
table based on the following prescriptions:
Medication Frequency
Iron pill 0800, 1200, 1800
Antibiotic Every 4 hours starting at 0400
Aspirin 0800, 2100
Decongestant 1100, 2000
Here You Goooo....
#include <ctime>
#include<cstdio>
#include <iostream>
#include <string>
using namespace std;
void printTotalTable(void);
int getPresentHour() // to get the present hour
{
time_t now = time(0);
// convert now to string form
char* dt = ctime(&now);//gives total date and time. but we need only present hour
string presentTime=dt;
int i=0;
// extracting the hour from the whole date and time
while(presentTime[i]!=':')
{
i++;
}
char temp[3];
temp[0]=presentTime[i-2];
temp[1]=presentTime[i-1];
int t = (temp[0]-'0')*10+(temp[1]-'0');//here we are
return t;
}
struct table
{
string medicine;//name of the medicine
int frequency[24];// which which ours it has to taken.may be some medicines have to take per every hour that's why 24;
};
struct table tb[3];// as of now I'm taking predefined medicines and hours
void initializeTable(void)
{
tb[0].medicine="paracetamol";
tb[0].frequency[0]=10;
tb[0].frequency[1]=13;
tb[1].medicine="Aspirin";
tb[1].frequency[0]=11;
tb[1].frequency[1]=12;
tb[2].medicine="Antibiotic";
tb[2].frequency[0]=10;
tb[2].frequency[1]=19;
}
void printTotalTable(void) // to see the total table and it's timings
{
int i=0,j=0;
cout<<"Medication\t\t"<<"Frequency"<<endl<<endl;
for (i=0;i<3;i++)
{
cout<<tb[i].medicine<<"\t\t";
j=0;
for (j=0;tb[i].frequency[j];j++)
{
cout<<tb[i].frequency[j]<<":00,";
}
cout<<endl;
}
cout<<endl<<endl;
}
void check()// to see which medicine has to take at present hour
{
//cout<<getPresentHour();
int ph = getPresentHour(),i=0,j=0;
cout<<"Medication\t\t"<<"Frequency"<<endl<<endl;
for (i=0;i<3;i++)
{
j=0;
for (j=0;tb[i].frequency[j];j++)
{
if (tb[i].frequency[j]==ph)//if the medicine's hour is matched to present hour then -->
{
cout<<tb[i].medicine<<"\t\t"<<tb[i].frequency[j]<<":00";
break;
}
}
cout<<endl;
}
cout<<endl<<endl;
}
void menu()
{
cout<<"1.Print Total Table\n2.Print Present Medication\n3.Exit"<<endl;
}
int main()
{
initializeTable();//initializing the medicines and which hours they has to taken , predefining
int opt;
do
{
menu();
cout<<"Choose Your Option : ";
cin>>opt;
switch(opt)
{
case 1:
printTotalTable();
break;
case 2:
check();
break;
case 3:
break;
default :
cout<<"invalid Option!";
break;
}
}
while(opt!=3);
return 0;
}
(C++) Patients required to take many kinds of medication often have difficulty in remembering when to...