Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can anyone help me include displaytime() in this . That way, the user can enter the time and test it into 12 hour format and

Can anyone help me include displaytime() in this .

That way, the user can enter the time and test it into 12 hour format and 24 hour format .

YOu need to input void displayTime( hr, min); and you need to ask the user to "Please enter the current time and let me calculate it into 12 hour format and 24 hour format.

Thank you

//Time.h

#pragma once #include #include using namespace std;

class Time { //private data members int hours; int minutes; public: //default constructor Time(); Time(int hr, int min); void setTime(int hr, int min); void increaseTimeByMinutes(int min); void print_12_hr_format(); void print_24_hr_format(); };

========================

//Time.cpp

#include"Time.h"

Time::Time() { //default time set to 00:00 , ie 12: 00 am in 12-Hr format hours = 0; minutes = 0; } Time::Time(int hr, int min) { hours = hr; minutes = min; } void Time::setTime(int hr, int min) { hours = hr; if ( min >= 60) { hours += (minutes+min) / 60; minutes = (min) % 60; } else { minutes = min; } if (hours>= 24) { hours = hours%24; } } void Time::increaseTimeByMinutes(int min) { if (minutes + min >= 60) { hours += (minutes + min) / 60; minutes = (minutes + min) % 60; } else { minutes += min; } if (hours >= 24) { hours = hours % 24; } } void Time::print_12_hr_format() { cout << setfill('0'); cout << "12 hours format: "; if (hours >= 12) { if ((hours - 12) == 0) { cout << setw(2)<<"12" << ":" << setw(2)<

================================

//Main.cpp

#include #include"Time.h" using namespace std;

int main() { //test defaulyt constructor Time time1; //show default time time1.print_12_hr_format(); time1.print_24_hr_format(); //test overloaded constructor Time time2(11, 59); time2.print_12_hr_format(); time2.print_24_hr_format();

//increament time time2.increaseTimeByMinutes(20); time2.print_12_hr_format(); time2.print_24_hr_format(); //test time function time1.setTime(13, 70); time1.print_12_hr_format(); time1.print_24_hr_format(); time1.setTime(23, 20); //increamet time beyond 24 hrs and see results cout << "Increament time beyond 24 hrs and output is : " << endl; time1.increaseTimeByMinutes(70); time1.print_12_hr_format(); time1.print_24_hr_format(); cout << "Set time to 23:59" << endl; time1.setTime(23, 59); time1.print_12_hr_format(); time1.print_24_hr_format(); }

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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions