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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#include <iostream>
#include <string>
#include <fstream>
/*Modify the example program (below) that implemented the Class Time to:
1) Create the UML notation for the Class Time. Submit it as doc or text file.
2) Create a menu as follow:
Press #1 to enter hours [1-12] with PM and AM, minutes and seconds.
Press #2 to display the time in military mode.
Press #3 to display the time in standard mode.
Press #4 to exit.
Any other entry different than 1, 2, 3 or 4 will be rejected and will display the whole menu again. */
using namespace std;
class Time
{
public:
Time();
void settime(float hr, float m, float s);
void gettime(float hr,float m,float s);
void setmidday(char am, char pm);
void setmode(char standard, char military);
private:
float hour;
float minute;
float second;
};
void Time::setmidday(char am, char pm)
{
pm=(hour>=12);
am=(hour<12);
}
void Time::setmode(char standard, char military)
{
standard=12;
military=24;
}
Time::Time()
{
hour = 00;
minute = 00;
second = 00;
}
void Time::settime(float hr, float m, float s)
{
hour = hr;
minute = m;
second = s;
}
void Time::gettime(float hr,float m, float s)
{
cout << "hours: " << hour <<" "<< "minute: " << minute <<" "<< "second: " << second <<" " << endl;
}
int main()
{
int num, ok=0;
Time t;
int hr,m,s;
while(true)
{
cout<<"Press #1 to enter hours [1-24], minutes and seconds.\n";
cout<<"Press #2 to display the time in military mode.\n";
cout<<"Press #3 to display the time in standard mode.\n";
cout<<"Press #4 to exit.\n";
cin>>num;
if (num == 1){
t.settime(hr, m, s);
}else if (num == 2){
t.gettime(hr,m,s);
}else if (num == 3){
t.gettime(hr,m,s);
}else if (num == 4){
{
cout<<"bye!bye!\n";
exit;
break;
}
}
}
}
void settime(float hr, float m, float s)
{
int ok=0;
do
{
{
cout<<"Enter hours [1-24], minutes and seconds.\n";
cin >> hr >> m >> s ;
}while (ok==0);
if (hr>=12)
{
(hr=hr-12);
cout << hr <<":"<< m << s <<" "<< "pm\n";
ok=1;
}
else if (hr<12)
{
cout << hr << ":" << m << s << " " << "am\n";
ok=1;
}
}while (ok==0);
}
void gettime(float hr,float m,float s)
{
int ok=0, num1;
do
{
cout << "Enter '24' for Military time or '12' for Standard time.\n";
cin >> num1;
}while (ok==0);
do
if (num1==24)
{
cout<<"Military time: "<< hr <<":"<< m << s;
ok=1;
}while (ok==0);
if (num1==12)
{
cout <<"standard time: "<< hr<<":"<< m << s;
ok=1;
}while (ok==0);
}
|