I'm trying to write a program that runs through a 24 hour day using a counter variable clock. I'm pretty lost...as usual. C++ is just not for me! But, I need the class, so here I am. The program needs to print an hourly table of medications to take at certain times. So far, this is what I have written....
What I'm trying to do is print a table that tells a patient when to take their medications. So for example, I need to print (relay to the patient) that an ironpill needs to be taken at 0800, 1200, and 1800. There are four medications like this that need to be taken at various times. So I need to use a clock to go through the 24 hour day, and at certain points, print such and such medication to be consumed. I'm looking at the Chrono info page you provided, can I use "time_point" to provide the meds be taken at a specific time? I'm just not sure of the best way to write this kind of program :(
Well, honestly I'm kind of confused about what my professor wants. I think the assignment wants me to print the table at once, but if that's the case I'm not sure why he would want me to use a counter variable clock...I think that may be my big confusion as a newbie. Also, I'm running DEVC++ and it doesn't even support chrono so I can't compile and run to seek for errors.....any suggestions on a full featured IDE for a new kid on the block?
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 on the following prescriptions.
I may be wrong but it reads like he wants you to use a counter (in a variable) for hours and minutes, then cycle through that and if the time (in your counter) reaches a time stored in your patients data it would list that patients data.
So say 4 patients needed to take some tablets at 4:00, the function would list those 4 patients and what medication they need to take.
#include <iostream> //as usual basic i/o objects
#include <chrono> //for C++11 time like the seconds() line 32
#include <ctime> //C time functions--useful
#include <thread> //for the sleep function line 32
usingnamespace std;
usingnamespace std::chrono; //the C++11 time library namespace
int main() {
time_t st=time(nullptr); //set programme startup time
tm* startTime{localtime(&st)}; //setup a tm structure(for time information based on st(ie: startup time))
tm timeObj;
unsigned hr=0,min=0;
cout<<"Enter prescribed hour(24hr clock): ";
cin>>hr; //user enters hour 0 - 23
cout<<"\nEnter prescribed minute: ";
cin>>min; //user enters minute 0 - 60
if((hr>=0)&&(hr<=23)&&(min>=0)&&(min<=60)) { //check
timeObj=*startTime; //assign timeObj the startup time
timeObj.tm_hour=hr; //set the hour aspect of the startup time to the user defined one
timeObj.tm_min=min; //set the minute aspect of the startup time to the user defined one
//time difference in seconds between user defined time and startup time
double timeDiff=difftime(mktime(&timeObj),st);
if(timeDiff<0.0) {
cout<<"Time passed!!!"; //tell the user to be careful
}
else {
this_thread::sleep_for(seconds((int)timeDiff)); //wait for truncated-to-int "time difference" seconds
//this ensures(not effectively) the user is informed on the time
//the drug must be taken
cout<<"\a\a\a\a\a\n\nHey!!! Take your drugs NOW!!!\a\a\a\a\a"; //inform
}
}
delete startTime; //clear stuff
return 0;
}
I think the counter variable statement would point to a variable or variables to just simulate going through time and list those that fall at the given time for medication... otherwise the professor is going to have a long wait for testing the code <g>
So a variable for hours, and minutes and cycle through them. I did notice it also states "hourly" so do you really need to check minutes.. just cycle hours and have it check each hour if someone needs to take medication.
Again, could be wrong but it certainly looks that way.
Thanks a million for the code Aceix, it definitely helps me understand chrono. I am just so new to all this, and I learn by reading/seeing! I think yall are right, though, that I don't even need chrono...so here's the code I've written so far:
#include <iostream>
usingnamespace std;
//Function Prototypes
void prescriptionSchedule()
{
int i = 0; //Variable assignment to begin counter as time at 0.
#define WIDTH 10
#define HEIGHT 5
int prescription [5][10]; //Define array dimensions.
int ironPill[] = {'\t','\t',800,'\t',1200,'\t',1800};
int antibiotic = 0;
int aspirin = 0;
int decongestant = 0;
int n,m;
int ironPillTime;
//Request user initiate program.
cout << "To view prescription schedule press any key: " << endl;
cout << "Take prescription when hour is marked with 'X'" <<endl;
cout << "\t\t\t0400\t0800\t1100\t1200\t1600\t1800\t2000\t2100\t2400" << endl;
int main ();
{
if (n,m = 0) {
cout << "\t"; }
if (n = 1) {
cout << "Iron Pill"; }
if (n = 2) {
cout << "Antibiotic"; }
if (n = 3){
cout << "Aspirin"; }
if (n = 4) {
cout << "Decongestant"; }
if (m = 1) {
cout << "\t0400"; }
if (m = 2) {
cout << "\t\t0800"; }
if (m = 3){
cout << "\t\t\t1100"; }
if (m = 4) {
cout << "\t\t\t\t1200"; }
if (m = 5) {
cout << "\t\t\t\t\t1600"; }
if (m = 6) {
cout << "\t\t\t\t\t\t1800"; }
if (m = 7) {
cout << "\t\t\t\t\t\t\t2000"; }
if (m = 8) {
cout << "\t\t\t\t\t\t\t\t2100"; }
if (m = 9) {
cout << "\t\t\t\t\t\t\t\t\t2400"; }
}
prescriptionSchedule();
for(int time = 0000; time < 2400; time += 100)
{
for(i = 0; i < ironPillTime; i++)
if(time = ironPill[i])
cout << "X" << '\t';
cout << endl;
}
int main ();
{
cout << "Prescription Schedule" << endl;
prescriptionSchedule();
return;
}
}
But, I'm getting this error
collect2.exe: error: ld returned 1 exit status
. I have written the code only to include the first set of meds to see if it works before I write it out for the other three meds. Thank yall again for all the help!