(Exercise 1) Create-timelnput.cpp In this part of the lab, you will be creating
ID: 3675363 • Letter: #
Question
(Exercise 1) Create-timelnput.cpp In this part of the lab, you will be creating your own Time structure to keep track of various times of the day. Your Time structure should contain 3 integer variables: . one for the hour . one for the minutes one for the seconds Your program will setup a start & end time for a lecture at the University. It will ask the user to enter the start time and the end time for the lecture, using the 24 hour format (HH:MM:Ss). You need to check that the input produces a valid time: check if the string contains the right characters (i.e. two characters [0-9], a colon, etc.) check if the time entered makes sense (i.e. HR is 0-23, etc. . for instance, 33:79:99 does NOT make sense). .If the time is incorrect, output an error message and exit the program. Once the user has entered two valid times, your program will output the start and end times in a 24 hour format. For those who are unfamiliar with 24 hour format, please see http://en.wikipedia.org/wiki/12-hour_clock. Note: in order to receive full credit for this part of the lab, you MUST create a main program that defined the Time structure and the following two functions: getTimeFromUser: takes in a Time structure variable as a parameter, reads a string from user, checks to see if it is a valid 24 hour format, stores it inside the Time structure variable, and return true or Talse depending on whether or not the time is valid. Since the Time structure is not returned at the end of this function, you need to pass the reference (&) of the Time structure instead of the identifier (name) as the parameter. This way, the contents of the Time structure will be updated after the function is executed and goes back to the main function. . Write a pseudocode of getTimeFromUser function before writing it in C++ code. o print24Hour: takes in a Time structure variable as a parameter and prints the time using the 24 hour format. Hints: see the following examples for the output structure use getline with cin for all of the user input i.e. getline(cin, my_line) instead of cin > my_line in order to read symbols(:") from user you will need to read the entire string for the time (i.e. 12:30:00), and process it to extract the numbers. You should extract the numbers one by one, convert them to integers, and store them in your structure. The string functions substr and find will be especially usefulExplanation / Answer
#include #include #include using namespace std; struct Interval { int start; int end; Interval() : start(0), end(0) {} Interval(int s, int e) : start(s), end(e) {} }; struct StartOrder { bool operator() (const Interval &a, const Interval &b) { return a.startRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.