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

Please use this format #include <iostream> #include <string> using namespace std

ID: 3648642 • Letter: P

Question

Please use this format


#include <iostream>

#include <string>


using namespace std;


int main(){

}



bool ok(const Time & time); This function does no I/O, it just returns a bool. It returns true if the data in time is valid, otherwise false. This might be used to help debug a program. For instance, ok({7, false, 7, 30}) would return false (invalid day of the week) For instance, ok({0, true, 0, 30}) would return false (invalid hour) For instance, ok({3, false, 12, 60}) would return false (invalid minute) For instance, ok({0, true, 12, 0)} would return true (noon on Sunday is a perfectly fine time) (The above examples aren't legal C++; you're not allowed to have curly braces in an argument list like that. I'm just trying to show what data would be in the Time object.)

Explanation / Answer

please rate - thanks

you didn't explain the data in the struct, so I guessed

#include <iostream>
#include <string>
using namespace std;
struct Time
{int day;
bool pm;
int hour;
int min;
};
void getInput(Time& );
bool ok(const Time&);
int main(){
int i,n;
Time t;
cout<<"how many sets of data do you have? ";
cin>>n;
for(i=0;i<n;i++)
    { getInput(t);
     if(ok(t))
          cout<<"Your data is a correct time: ";
     else
         cout<<"Your data is not a correct time: ";  
     }
system("pause");
return 0;
}
void getInput(Time& t )
{int temp;
cout<<"Enter day of week(0-6): ";
cin>>t.day;
cout<<"Enter 1 for AM, 2 for PM: ";
cin>>temp;
if(temp==1)
    t.pm=false;
else
    t.pm=true;
cout<<"Enter hour(1-12): ";
cin>>t.hour;
cout<<"Enter minute(0-59): ";
cin>>t.min;
}
bool ok(const Time& t)
{if(t.day<0||t.day>6)
       return false;
if(t.hour<1||t.hour>12)
       return false;
if(t.min<0||t.min>59)
       return false;
return true;
}