A time class

Concluído Postado Dec 2, 2001 Pago na entrega
Concluído Pago na entrega

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.

Programação C Engenharia MySQL PHP Arquitetura de software Teste de Software

ID do Projeto: #2833257

Sobre o projeto

13 propostas Projeto remoto Ativo em Dec 2, 2001

Concedido a:

sammyleong

See private message.

$25.5 USD em 14 dias
(79 Comentários)
5.2

13 freelancers estão ofertando em média $27 nesse trabalho

geminivw

See private message.

$25.5 USD in 14 dias
(38 Comentários)
5.7
cinterosystems

See private message.

$21.25 USD in 14 dias
(139 Comentários)
5.6
vw181638vw

See private message.

$51 USD in 14 dias
(44 Comentários)
5.4
vw139994vw

See private message.

$29.75 USD in 14 dias
(60 Comentários)
4.5
asadsufi

See private message.

$42.5 USD in 14 dias
(38 Comentários)
4.1
ashishjaiswalvw

See private message.

$42.5 USD in 14 dias
(8 Comentários)
3.1
coolbeanzco

See private message.

$17 USD in 14 dias
(12 Comentários)
2.1
gutinsoft

See private message.

$21.25 USD in 14 dias
(5 Comentários)
1.8
axp

See private message.

$11.05 USD in 14 dias
(2 Comentários)
0.2
brunonadeau

See private message.

$12.75 USD in 14 dias
(1 Comentário)
0.0
stankirilov

See private message.

$21.25 USD in 14 dias
(0 Comentários)
0.0
anatprogeu

See private message.

$25.5 USD in 14 dias
(3 Comentários)
0.2
webdesignguruvw

See private message.

$21.25 USD in 14 dias
(0 Comentários)
0.0