Starting from:

$35

CSE030-Lab 7 Classes Solved

(Exercise 1)  
This exercise is exactly the same as Exercise 1 of Lab 6.  Instead of creating a Time structure you will create a Time class.  The output from your program should be exactly the same as the one for Lab 6, but you will be using a class rather than a structure.  In order to receive full credit for this part of the lab, you must create:

 

•       two files for your class, a Time.h file with your class declaration and a Time.cpp file with your class definition.

•       a main.cpp file for your main, getTimeFromUser, and print24Hour functions.

•       a total of 3 private variables in Time class: hours, minutes,  and seconds.

•       a total of 9 public functions in Time class:

o   Default Constructor (Time()): initializes the three variables to 0

o   Extra Constructor (Time(parameters)): takes three parameters and initializes the hours, minutes, and seconds based on them.

o   Destructor (~Time()): does nothing.

o   3 “Accessor” functions:  each one returns the current value for the hours, minutes, and seconds respectively.

o   3 “Mutator” functions: each one takes a parameter and sets it as the current value for the hours, minutes, or seconds.  Inside the getTimeFromUser function, you no longer can set the hours by typing start_time.hours=h

because hours is set to be private now.  You have to use these mutator functions to set the time.

   

This is an excerpt of the relevant part of Lab 6 Exercise 1:

 

The program sets a start and end time for a lecture at the University.  It will ask the user to enter the start time for the lecture, using the 24 hour format (HH:MM:SS).   You need to check that the input produces a valid time:

 

1.   Check if the string contains the right characters (i.e. two characters [0-9], a colon, etc.)

2.   Check if the time entered makes sense (i.e. HR is 0-23, etc. ... for instance, 33:79:99 does NOT make sense).  

3.   If the time is incorrect, output an error message and exit the program.  

 

Follow the same procedure for the end time. Once the user has entered two valid times, your program will output the start and end time in a 24 hour format.   

 

Example 1:  

Enter the start time for the lecture (format is HH:MM:SS): 12:22PM  The start time entered is invalid!  

  

Example 2:  

Enter the start time for the lecture (format is HH:MM:SS): 23:59:59 Enter the end time for the lecture (format is HH:MM:SS): 23:85:00 The end time entered is invalid!  

  

Example 3:  

Enter the start time for the lecture (format is HH:MM:SS): 09:05:00 

Enter the end time for the lecture (format is HH:MM:SS): 10:15:00 

The lecture starts at 09:05:00 and ends at 10:15:00 

  

Example 4:  

Enter the start time for the lecture (format is HH:MM:SS): 13:00:00 

Enter the end time for the lecture (format is HH:MM:SS): 13:15:30 

The lecture starts at 13:00:00 and ends at 13:15:30 

 

More products