Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ and don't copy from other chegg answers please, thanks! Problem: TimeSpan Design and implement a TimeSpan class which represents a duration of time

Use C++ and don't copy from other chegg answers please, thanks!

image text in transcribed

Problem: TimeSpan Design and implement a TimeSpan class which represents a duration of time in hours, minutes, and seconds. The order hours, minutes, and seconds should be respected in the constructor As an example TimeSpan duration(1, 2, 3); is a duration of time of 1 hour, 2 minutes and 3 seconds. In the instances of the TimeSpan class you should store the values as integers in a normalized way. The number of seconds should be between -60 and 60; number of minutes should be between -60 and 60. You do not need to worry about integer overflow for very big TimeSpans. Accessor/Mutator functions required The TimeSpan class should implement the following member functions: int getHours() const; int getMinutes() const; int getSeconds() const: return the number of hours as an int return the number of minutes as an int return the number of Seconds as an int bool setTime(int hours, int minutes, int seconds): set the number of hours, minutes seconds and return true if successful. onstructo The class should define constructor(s) that receive various primitive types (specifically int, float, and double) and converts them to Int. Do appropriate rounding to maintain as much accuracy as possible. TimeSpan(1.5,4,-10) represents 1 hour, 33 minutes, 50 seconds If only one parameter is passed during initialization assume it is a second. If there are two assume minutes and seconds (in that order). Round the answer to the nearest second (for example, 50.9 seconds should be rounded to 51 seconds) TimeSpan(7, 3) represents 7 minutes, 3 seconds. Operators The class must overload and implement the following math operators: addition, subtraction, Unary Negation. The class must overload and implement the following comparisons:-, The class must implemenandassignment statements as well Stream /O The class must implement the> operators to work on streams: Input Take as input three values: hour, minutes, seconds and create appropriate class. If the inputs are double or float, convert them to integers. Output For formatting the following: TimeSpan duration1(1,2,3) std::cout

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions