Hi, I need some help with the "Your solution should allow the user to exit the program as well as add one hour, minute, or second to both clocks from a user menu" requirement of my C++ program. So far, my code will print the local time in a 12hr and 24hr format, I just need some help with implimenting the user input to add an hour, minute, or second. Thanks Below is my current code, 3 C++ files one of which is a header file: ClockTime.cpp #include "ClockTime.h" //default Constructor ClockTime::ClockTime() {     time_t now = time(0); //gets current Time     tm *ltm = localtime(&now); //converts current Time to struct tm type     this->hour = ltm->tm_hour;     this->minute = ltm->tm_min;     this->second = ltm->tm_sec; } // parameter constructor ClockTime::ClockTime(int hour, int min, int sec) {     this->hour = hour;     this->minute = min;     this->second = sec; } void ClockTime::addHour(int hour = 1) {     this->hour = (this->hour + hour) % 24; } void ClockTime::addMinute(int min = 1) {     if (min == 59){         this->addHour();     }     this->minute = (this->minute + min) % 60; } void ClockTime::addSecond(int sec = 1) {     if (this->second == 59){         this->addMinute();     }     this->second = (this->second + sec) % 60; } // function return AM/PM respect to hour of time string ClockTime::getAM_PM() {     return this->hour >= 12 ? "PM" : "AM"; } // function returns integer used in 12 hour format int ClockTime::gethour_12() {     return (this->hour == 0 || this->hour == 12) ? 12 : this->hour % 12; } // function displays 12 hour formatClock void ClockTime::display_12_HourTime() {     cout.fill('0');     cout << setw(2) << this->gethour_12()<< ":" << setw(2) << this->minute << ":" << setw(2) << this->second          << " " << this->getAM_PM(); } // function displays 24 hour formatClock void ClockTime::display_24_HourTime() {     cout.fill('0');     cout << setw(2) << this->hour << ":" << setw(2) << this->minute << ":" << setw(2) << this->second; } // Function Displays Both Clocks void ClockTime::displayClock() {     cout << "**************************" << "     " << "**************************\n";     cout << "*      12-Hour Clock     *" << "     " << "*      24-Hour Clock     *\n";     cout << "*      "; this->display_12_HourTime();     cout << "       *     *        ";     this->display_24_HourTime(); cout << "        *\n";     cout << "**************************" << "     " << "**************************\n"; } _____________________________________________________________ mainDrive.cpp #include"ClockTime.h" int main() {     ClockTime t;     t.displayClock();     return 0; } _____________________________________________________________ ClockTime.h #pragma once #ifndef CLOCK_TIME_H #define CLOCK_TIME_H #define _CRT_SECURE_NO_WARNINGS #include #include #include #include using namespace std; class ClockTime { private:     int hour;     int minute;     int second;     void display_12_HourTime();     void display_24_HourTime(); public:     ClockTime();     ClockTime(int , int, int );     void addSecond(int );     void addMinute(int );     void addHour(int );     string getAM_PM();     int gethour_12();     void displayClock(); }; #endif

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hi, I need some help with the "Your solution should allow the user to exit the program as well as add one hour, minute, or second to both clocks from a user menu" requirement of my C++ program.

So far, my code will print the local time in a 12hr and 24hr format, I just need some help with implimenting the user input to add an hour, minute, or second. Thanks

Below is my current code, 3 C++ files one of which is a header file:

ClockTime.cpp

#include "ClockTime.h"

//default Constructor
ClockTime::ClockTime()
{
    time_t now = time(0); //gets current Time
    tm *ltm = localtime(&now); //converts current Time to struct tm type

    this->hour = ltm->tm_hour;
    this->minute = ltm->tm_min;
    this->second = ltm->tm_sec;
}

// parameter constructor
ClockTime::ClockTime(int hour, int min, int sec)
{
    this->hour = hour;
    this->minute = min;
    this->second = sec;
}

void ClockTime::addHour(int hour = 1)
{
    this->hour = (this->hour + hour) % 24;
}

void ClockTime::addMinute(int min = 1)
{
    if (min == 59){
        this->addHour();
    }
    this->minute = (this->minute + min) % 60;
}

void ClockTime::addSecond(int sec = 1)
{
    if (this->second == 59){
        this->addMinute();
    }
    this->second = (this->second + sec) % 60;
}

// function return AM/PM respect to hour of time
string ClockTime::getAM_PM()
{
    return this->hour >= 12 ? "PM" : "AM";
}


// function returns integer used in 12 hour format
int ClockTime::gethour_12()
{
    return (this->hour == 0 || this->hour == 12) ? 12 : this->hour % 12;
}


// function displays 12 hour formatClock
void ClockTime::display_12_HourTime()
{
    cout.fill('0');
    cout << setw(2) << this->gethour_12()<< ":" << setw(2) << this->minute << ":" << setw(2) << this->second 
        << " " << this->getAM_PM();
}

// function displays 24 hour formatClock
void ClockTime::display_24_HourTime()
{
    cout.fill('0');
    cout << setw(2) << this->hour << ":" << setw(2) << this->minute << ":" << setw(2) << this->second;
}

// Function Displays Both Clocks
void ClockTime::displayClock()
{
    cout << "**************************" << "     " << "**************************\n";
    cout << "*      12-Hour Clock     *" << "     " << "*      24-Hour Clock     *\n";
    cout << "*      "; this->display_12_HourTime();
    cout << "       *     *        ";
    this->display_24_HourTime(); cout << "        *\n";
    cout << "**************************" << "     " << "**************************\n";
}

_____________________________________________________________

mainDrive.cpp

#include"ClockTime.h"

int main()
{
    ClockTime t;
    t.displayClock();
    return 0;
}

_____________________________________________________________

ClockTime.h

#pragma once
#ifndef CLOCK_TIME_H
#define CLOCK_TIME_H
#define _CRT_SECURE_NO_WARNINGS

#include<string>
#include<iostream>
#include <ctime>
#include <iomanip>

using namespace std;

class ClockTime
{
private:
    int hour;
    int minute;
    int second;

    void display_12_HourTime();
    void display_24_HourTime();
public:

    ClockTime();
    ClockTime(int , int, int );

    void addSecond(int );
    void addMinute(int );
    void addHour(int );

    string getAM_PM();
    int gethour_12();

    void displayClock();
};

#endif

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY