Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Here's the base code for the driver, header, and implementation files: DRIVER #include #include Clock.h #include using namespace std; int main() { Clock

In C++

image text in transcribed

Here's the base code for the driver, header, and implementation files:

DRIVER

#include  #include "Clock.h" #include  using namespace std; int main() {  Clock c1;   cout   cout   cout   cout   c1.setHour(5);  c1.setMinute(9);  c1.setSecond(23);  c1.printTime(false);  // 17:09:23  c1.tick();  c1.printTime(false);  for (int i = 0; i   c1.tick();  c1.printTime(false);  Sleep(1000);  system("cls");  }  return 0; } 

HEADER

#ifndef CLOCK_H #define CLOCK_H class Clock { private:  int hour, minute, second;  bool isMorning; public:  Clock(int h = 12, int m = 0, int s = 0, bool isM = true);  void setHour(int h);  void setMinute(int m);  void setSecond(int s);  void setIsMorning(bool isM);  int getHour();  int getMinute();  int getSecond();  bool getIsMorning();  void printTime(bool twelveHourFormat);  void tick(); #endif };

IMPLEMENTATION

#include "Clock.h" #include  using namespace std; Clock::Clock(int h, int m, int s, bool isM) {  setHour(h);  setMinute(m);  setSecond(s);  setIsMorning(isM); } void Clock::setHour(int h) {  if (h   h = 1;  if (h >= 13)  h = 12;  hour = h; } void Clock::setMinute(int m) {  if (m   m = 0;  if (m >= 60)  m = 59;  minute = m; } void Clock::setSecond(int s) {  if (s   s = 0;  if (s >= 60)  s = 59;  second = s; } void Clock::setIsMorning(bool isM) {  isMorning = isM; } int Clock::getHour() {  return hour; } int Clock::getMinute() {  return minute; } int Clock::getSecond() {  return second; } bool Clock::getIsMorning() {  return isMorning; }
void Clock::printTime(bool twelveHourFormat) {  // Insert code here  cout  } void Clock::tick() {  // Insert code here  setSecond(second + 1); }  

Please provide complete code for implementation file and any other changes for the other two files.

Implement a class called Clock with fields hour, minute, second of type int and isMorning of type bool. Include a constructor to initialize the Clock along with appropriate getters and setters for the fields. The constructor should have default parameters values of 12, 0,0 and true, respectively, for the parameters corresponding to hour, minute, second and isMorning. Also include a void method tick that advances the clock by one second. Of course the clock should eventually roll back around to to 12:00:00 AM. Finally, include a method printTime() that outputs the current time e.g. 12:34:56AM. printTime should take a parameter twelveHourFormat of type bool. (If called with true then 12 hour format will be used, otherwise 24 hour format will be used.) Code Clock.h, Clock.cpp and a driver to test your code. Be sure your driver calls all of the methods at least once

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_2

Step: 3

blur-text-image_step3

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

Discuss the history of U.S. labor unions.

Answered: 1 week ago