Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Program 1 : Class Design / Operator Overloads Purpose This programming assignment will provide exercises in designing classes with proper abstraction and encapsulation. Encapsulation and
Program : Class Design Operator Overloads
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.
Problem : The Vending Bank
Design do not implement a class which models the coinoperated bank part of a vending
machine which sells snacks. You only need to design the contract h file and not the
implementation cpp file Here is a start of vendingbank.h with one function already defined.
The data member id is a unique identifier for the vending bank.
vendingbank.h:
#ifndef VENDINGBANKH
#define VENDINGBANKH
#include
class VendingBank
public:
VendingBank;
VendingBankint id;
getterssetters
int id const;
FILL IN FURTHER PUBLIC FUNCTIONS HERE
private:
id is a unique identifier for the VendingBank
much like a serial number
int id ;
FILL IN FURTHER DATA MEMBERS HERE
#endif
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 when stored; number of minutes
should be between and when stored. That is a user can create a TimeSpan object of
seconds, but it should be stored as minute, seconds. See example below.
You do not need to worry about integer overflow for very big TimeSpan objects.
Accessor functions required
The TimeSpan class should implement the following member functions:
int hours const; return the number of hours as an int
int minutes const; return the number of minutes as an int
int seconds const: return the number of Seconds as an int
void settimeint hours, int minutes, int seconds: set the number of hours, minutes,
seconds.
Constructors
The class should define constructors that receive various primitive types specifically
int, float, and double and store them as integers. The constructor should take one, two or
three arguments. If only one parameter is passed during initialization assume it is seconds. If
there are two assume minutes and seconds in that order
Perform appropriate rounding to maintain as much accuracy as possible down to the
second as the smallest granularity. You should not keep fraction of seconds.
Here are some examples:
TimeSpan represents hour, minutes, seconds.
TimeSpan represents minutes, seconds.
TimeSpan represents minutes, seconds.
TimeSpan represents hour, minutes.
Operators
The class must overload and implement the following math operators: addition,
subtraction, and Unary Negation.
The class must overload and implement the following comparison operators:
The class must implement and assignment statements as well.
Stream IO
The class will also implement the input output operators: and :
Input:
Take as input three values: hour, minutes, seconds and create appropriate class. Assume
that these will be integers.
Output:
Output the values in the following format: Hours: value, Minutes: value, Seconds: value
As an example, this code:
TimeSpan duration;
std::cout duration;
Will output:
Hours: Minutes: Seconds:
Please use this EXACT format.
Turn In
A zip file which contains:
timespan.h
timespan.cpp
A file containing your Unit Tests utilized during TDD
o These should be comprehensive.
o These can come in any form depending on the Unit Test Framework you
utilize; or they can take the form of the tests below.
o These test cases will not be executed by the grader; we will inspect these
manually to see if they are comprehensive.
vendingbank.h
Please make sure to spell the getter and setter functions exactly as I have them above. Also,
your overloads should follow appropriate signatures of they will not compile appropriately
for the grader.
NOTE: We will test your program on the Linux Lab Systems
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started