Description:
Create a class that holds times: 4:15 AM, 12:03 PM, 7:59 AM, etc.
Each object should hold the hour, minute and meridian of a single
time. Private data, then, would be:
long hr, min;
char meridian[5];
Meridian would hold either "AM" or "PM" (don't use lower case).
hr would hold a number from 0-11 (although users would use 12 for
12 o'clock, not 0, and your functions should convert internally),
min would hold a value from 0-59.
Any member functions that set times or compute times should
check for valid values of hr and min and, if they are illegal
or out of range, issue an error statement and set the time
to 12:00 AM.
Member Functions:
void Set(long h, long m, char mer[]);
void Set(char string_time[]);
Two functions to set the times.
The first Set() two ints, h and m, and after checking that
the values are in range, it sets the private data.
The second Set() takes a string like "10:32 AM"
or " 4:05 PM" and uses it to set the time by:
1) confirming the correct general format
length of string_time should be 8 string_time[2] should be a ':'
string_time[7] should be a 'M'
if not, it prints an error message and returns
2) isolating the hour string, minute string and meridian into their own local string objects
3) converting the hour and minute string to numeric ints
4) checking that hour and minute are within legal range (and printing an error and returning if not)
5) setting the time using the non-string method.
Deliverables: Constructor:
Time(long h = 12, long m = 0, char mer[] = "AM");
Time(char string_time[]);
These work like Set(). Be efficient in the design of these
two functions.
void Add( long hour, long minute );
Adds the hour/minute to the current time. It must properly
handle carries of minutes to hours, and AM to PM.
void Tick();
Adds a minute to the time, handling carries correctly.
bool Equals(Time t);
Returns true or false, depending on whether t == the time or not.
void Show();
Prints out the time.
Here is a sample main() and output that you can use to test your class, but hand in a sample main that is not exactly
the same as this.
int main()
{
Time t1, t2 =" 5:05 PM", t3(12,12,"AM"), t4 = "2:03 AM";
t1.Show(); cout << endl;
t2.Show(); cout << endl;
t3.Show(); cout << endl;
t4.Show(); cout << endl;
t1.Add(10,50);
t2.Add(10,50);
t3.Add(10,50);
t1.Show(); cout << endl;
t2.Show(); cout << endl;
t3.Show(); cout << endl;
// correct the intentional error above
t4.Set("11:45 PM");
Time alarm("12:05 AM");
cout << endl << "Starting Timer ... " << endl;
while ( !t4.Equals(alarm) )
{
t4.Tick();
t4.Show(); cout << endl;
}
return 0;
}
/* ------------------- SAMPLE RUN ---------------
Illegal time in Set()
12:00 AM
5:05 PM
12:12 AM
12:00 AM
10:50 AM
3:55 AM
11:02 AM
Starting Timer ...
11:46 PM
11:47 PM
11:48 PM
11:49 PM
11:50 PM
11:51 PM
11:52 PM
11:53 PM
11:54 PM
11:55 PM
11:56 PM
11:57 PM
11:58 PM
11:59 PM
12:00 AM
12:01 AM
12:02 AM
12:03 AM
12:04 AM
12:05 AM
---------------------------------------------- */
Complete and fully-functional working program(s) in executable form as well as complete source code of all work done. Complete copyrights to all work purchased.
Remember that contacting the other party outside of the site (by email, phone, etc.) on all business projects < $500 (before the buyer's money is escrowed) is a violation of both the software buyer and seller agreements.
We monitor all site activity for such violations and can instantly expel transgressers on the spot, so we thank you in advance for your cooperation.
If you notice a violation, you can report it to: abuse@rentacoder.com.
|