1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#ifndef TIME12_H
#define TIME12_H
#include <iostream>
#include "d_time24.h"
using namespace std;
//12 Hour clock time units
enum timeUnit {AM = 0, PM};
class time12 // Time 12 class
{
private:
time24 t; //Creation of a time24 "object". Purpose: To store time in a 24 hour format.
time24 convert12To24(int h, int m, timeUnit tunit); //build t from standard time
public:
time12(int h, int m, timeUnit tunit);
//Initialize time24 data member.
void addTime(int m);
// add m minutes to update current time
void readTime();
void writeTime();
// I/O member functions use format HH:MM AM(PM)
};
#endif
//****************************************************************************
//Class member function implementation.
//****************************************************************************
time12::time12(int h, int m, timeUnit tunit) //set h, m, time
{ h = 12, m = 0 , tunit = AM;}
time24 time12::convert12To24(int h, int m, timeUnit when) //time24 is type; time12 is class; convert 12 To 24 is method.
{
if (h < 12 && when == 0)
{h = h; return (h,m,when);}
else if (h >= 12 && when == 1)
{h = h= + 12; return (h, m, when);}
}
void time12::addTime(int m)//addTime is method.
{t.addTime(m);}
void time12::readTime() {t.readTime();}; //Is this correct?
void time12::writeTime(){t.writeTime(); if (t.getHour() < 12) {cout <<"AM"<<endl;}else if (t.getHour() >= 12) {cout<< "PM"<<endl;}};
|