Question: Purpose This programming assignment will provide exercises in designing classes with proper abstraction and encapsulation. Encapsulation and abstraction are key components of the C +
Purpose
This programming assignment will provide exercises in designing classes with proper
abstraction and encapsulation. Encapsulation and abstraction are key components of the C
programming language as well as OOP in general. In addition, the programming assignment will
require understanding of operator overloading and some use of the friend concept.
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;
is a duration of time of hour, minutes and 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 and ; number of minutes should be
between and You do not need to worry about integer overflow for very big TimeSpans.
AccessorMutator functions required
The TimeSpan class should implement the following member functions:
int getHours const; return the number of hours as an int
int getMinutes const; return the number of minutes as an int
int getSeconds const: return the number of Seconds as an int
bool setTimeint hours, int minutes, int seconds: set the number of hours, minutes,
seconds and return true if successful.
Constructors
The class should define constructors 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. A few examples:
TimeSpan represents hour, minutes, seconds.
TimeSpan represents hour, minutes, seconds.
TimeSpan represents hour, minutes, 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, seconds should be rounded to seconds Make sure to include also a default
instructor with no input parameters instantiating a TimeSpan object with
TimeSpan represents minutes, 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 implement and assignment statements as well.
Stream IO
The class must implement the and 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 duration
std::cout duration;
Should output:
Hours: Minutes: Seconds:
Please use this EXACT format.
Turn In
A zip file which constains:
TimeSpan.h
TimeSpan.cpp
TimeMachine.cpp your driver
An executable TimeMachine
Please make sure to spell the getter and
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
