A time class

Ukończone Opublikowano Dec 2, 2001 Płatność przy odbiorze
Ukończone Płatność przy odbiorze

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";

[url removed, login to view](); cout << endl;

[url removed, login to view](); cout << endl;

[url removed, login to view](); cout << endl;

[url removed, login to view](); cout << endl;

[url removed, login to view](10,50);

[url removed, login to view](10,50);

[url removed, login to view](10,50);

[url removed, login to view](); cout << endl;

[url removed, login to view](); cout << endl;

[url removed, login to view](); cout << endl;

// correct the intentional error above [url removed, login to view]("11:45 PM");

Time alarm("12:05 AM");

cout << endl << "Starting Timer ... " << endl;

while ( ![url removed, login to view](alarm) )

{

[url removed, login to view]();

[url removed, login to view](); 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.

Programowanie C Inżynieria MySQL PHP Architektura oprogramowania Testowanie oprogramowania

Numer ID Projektu: #2833257

O projekcie

13 ofert Zdalny projekt Aktywny Dec 2, 2001

Przyznany użytkownikowi:

sammyleong

See private message.

$25.5 USD w ciągu 14 dni
(79 ocen)
5.2

13 freelancerów złożyło ofertę za $27 w tym projekcie

geminivw

See private message.

$25.5 USD w ciągu 14 dni
(38 Oceny)
5.7
cinterosystems

See private message.

$21.25 USD w ciągu 14 dni
(139 Oceny)
5.6
vw181638vw

See private message.

$51 USD w ciągu 14 dni
(44 Oceny)
5.4
vw139994vw

See private message.

$29.75 USD w ciągu 14 dni
(60 Oceny)
4.5
asadsufi

See private message.

$42.5 USD w ciągu 14 dni
(38 Oceny)
4.1
ashishjaiswalvw

See private message.

$42.5 USD w ciągu 14 dni
(8 Oceny)
3.1
coolbeanzco

See private message.

$17 USD w ciągu 14 dni
(12 Oceny)
2.1
gutinsoft

See private message.

$21.25 USD w ciągu 14 dni
(5 Oceny)
1.8
axp

See private message.

$11.05 USD w ciągu 14 dni
(2 Oceny)
0.2
brunonadeau

See private message.

$12.75 USD w ciągu 14 dni
(1 Ocena)
0.0
stankirilov

See private message.

$21.25 USD w ciągu 14 dni
(0 Oceny)
0.0
anatprogeu

See private message.

$25.5 USD w ciągu 14 dni
(3 Oceny)
0.2
webdesignguruvw

See private message.

$21.25 USD w ciągu 14 dni
(0 Oceny)
0.0