Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need some help with some c++ homework The code below implements the Time ADT, without using a class. It produces the following output: 8:30:59PM has

Need some help with some c++ homework

The code below implements the Time ADT, without using a class. It produces the following output:

8:30:59PM has passed 8:0:0AM 11:59:59PM 0:0:0AM 8:0:0AM

what I have to do:

(1) Create a class called Time for the ADT. Convert the code by using the Time class.

Your code must produce identical output as mine. Your code must replace my set function with a constructor. It must also have a default constructor that sets the time to 0.

(2) List out all constructor(s), observer(s), transformer(s) in your new Time class.

given code:

//#include "stdafx.h" #include using namespace std;

typedef long Time; // time of day represented in seconds

const int DAY_IN_SECONDS = 24 * 60 * 60; const int HOUR_IN_SECONDS = 60 * 60; const int MINUTE_IN_SECONDS = 60;

bool Equal(Time t1, Time t2) { return t1 == t2; }

// set hours, minutes, seconds to Time t void set(Time & t, int hours, int minutes, int seconds) { t = hours*HOUR_IN_SECONDS + minutes*MINUTE_IN_SECONDS + seconds; }

// output t in 24 hour format (hours:minutes:seconds) void Write24(Time t) { int hour = t / HOUR_IN_SECONDS; int minute = t%HOUR_IN_SECONDS / MINUTE_IN_SECONDS; int second = t%MINUTE_IN_SECONDS; cout << hour << ":" << minute << ":" << second; }

// increment t by 1 second // reset t to 0 when reaching midnight void tick(Time & t) { t = t + 1; if (t == DAY_IN_SECONDS) t = 0; }

int main() { Time eight; Time current;

set(eight, 8, 0, 0);

set(current, 20, 30, 59);

if (!Equal(eight, current)) { Write24(current); cout << " has passed "; Write24(eight); cout << endl; }

Time t;

set(t, 23, 59, 59); Write24(t); cout << endl; tick(t); // midnight (0:0:0) Write24(t); cout << endl;

// advance to 8 AM int i = 0; while (i<8 * HOUR_IN_SECONDS) { tick(t); i++; } if (Equal(t, eight)) { Write24(t); cout << endl; } cin.ignore(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

Identify and describe a suggested outline of a business plan.

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago