Question & Answer: 2 inde TIME 3 define TIE 4 finclude…..

C++. Can anyone help me write the program. It should look like the one on #3 (bottom of the page)

2 inde TIME 3 define TIE 4 finclude <string Source 6 E class Time 「 7 public: Tine )i void setTime (int, int, int) std; : string toPSTZone() std::string tocSTZone const: std: :string toMSTZone ) const std: :string toESTZone() const: 10-1 const; 12 13 15 private: 16 unsigned int hour; / 0·2.3 unsigned int minute unsigned int second: 18 20 Windows (CRL WINDOWS-936 Une 10, Colurmn 1 Read wite delault insert S Fontrag xomth Ioos Tooit Ppugins DoyBlocks Settrings Heip Fie Enit ye Seapen Project Bund Debug 9 041Tiee.cp 44, Projects Symbols Fles mbels 30 31 Estring Time::toPSTZone() const 32 ostringstream output output <((hour Es Sources hour-12) ? 12 hour 12) <: setw(2) << minute :< setwl2) < setfil1o) 34 35 36 37 38 39 string Time::toCSTzone() const ex09 04cpp Timecpp second <s (hour < 12? AM: P) return output.stro 41 42 43 ostringstream output: int hr -hour + 1 output << ((hr 0 11 hr-12) ? 12 : hr % 12) << : setfill)setw(2) <s minute < H: Ss setw(2) second ss (hr 12?AMPM) return output.str 46 47 48 Estring Time::toMSTZone() const 49 ostringstream output Windows (CR L WINDOWS-936 Lire 3t. Coiumo T 3. Here is a sample output: CASCITACS321 Answers bin Debug Time904.exe The PST time zone is 6:56:28 AM The CST time zone is 7:56:28 AM The MST time zone is 8:56:28 AM The EST time zone is 9:56:28 AM

2 inde TIME 3 define TIE 4 finclude

Expert Answer

 

#include <cstdlib>
#include <iostream>
#include <string>
class clockType
{
public:
void setTime(int, int, int);
void getTime(int&, int&, int&) const;
void printTime() const;
void incrementSeconds();
void incrementMinutes();
void incrementHours();
bool equalTime(const clockType&) const;
clockType(int, int, int);
clockType();

private:
int hr;
int min;
int sec;
};

class zoneClockType: public clockType
{
public:
void setTimeZone(int, int, int, string);
void getTimeZone(int&, int&, int&, string, int&) const;
bool equalTime(const zoneClockType&) const;
void printTimeAndZone() const;
zoneClockType(int=0, int=0, int=0, string, string=”PST”);
zoneClockType();

private:
string timeZone;
int zoneVal;
};

using namespace std;
int main(int argc, char *argv[])
{
int hours, minutes, seconds;
string…=”PST”

clockType clock1;
clockType clock2( 23, 13, 75 );

clock1.setTime( 6, 59, 39 );
cout << “clock1: “;
clock1.printTimeAndZone();
cout << endl;

clock2.printTimeAndZone();
cout << endl;

clock1.incrementMinutes();
clock1.printTimeAndZone();
cout << endl;

clock1.setTime( 0, 13, 0 );

cout << “clock2: “;
clock2.printTime();
cout << endl;
clock2.setTime(5,45,16);

cout << “After setting, clock2: “;
clock2.printTime();
cout << endl;

if (clock1.equalTime(clock2))
cout << “Both times are equal.”
<< endl;
else
cout << “The two times are different.” << endl;

system(“PAUSE”);
return EXIT_SUCCESS;
}
void clockType::setTime(int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;

if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;

if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
void clockType::getTime(int& hours, int& minutes, int& seconds) const
{
hours = hr;
minutes = min;
seconds = sec;
}
void clockType::printTime() const
{
if (hr < 10)
cout << “0”;
cout << hr << “:”;

if (min < 10)
cout << “0”;
cout << min << “:”;

if (sec < 10)
cout << “0”;
cout << sec;
}
void clockType::incrementSeconds()
{
sec++;
if (sec > 59)
{
sec = 0;
incrementMinutes();
}
}

bool clockType::equalTime(const clockType& otherClock) const
{
return (hr == otherClock.hr
&& min == otherClock.min
&& sec == otherClock.sec);
}
clockType::clockType(int hours, int minutes, int seconds)
{
setTime(hours, minutes, seconds);
}
clockType::clockType()
{
hr = 0;
min = 0;
sec = 0;
}
void zoneClockType::getTimeZone()
{
hours=hr;
minutes=min;
seconds=sec;

if(timeZone=”EST”)
zoneVal=3
if(timeZone=”CST”)
zoneVal=2
if(timeZone=”MST”)
zoneVal=1
if(timeZone=”PST”)
zoneVal=0
}
void zoneClockType::printTimeAndZone()
{
clockType.printTime();
getTimeZone();
}
bool zoneClockType::equalTimeZone(const zoneClockType&) const
{
int h1, h2, m1, m2, s1, s2, v1, v2;
string z1, z2;
.
.
getTime(h1, m1, s1, z1, v1);
otherClock.getTime(h2, m2, s2, z2, v2);

if((m1==m2)&&(s1==s2))
if((h1-h2)-(v1-v2)==0)
return true;
else
return false;
else
return false;
zoneClockType::zoneClockType()
{
clockType();
setTimeZone(false);
}
zoneClockType::zoneClockType(int h, int m, int s)
{
setTime( h, m, s );
setTimeZone(true);
}

Still stressed from student homework?
Get quality assistance from academic writers!