Answered step by step
Verified Expert Solution
Link Copied!

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 1: 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 1: The Vending Bank
Design (do not implement) a class which models the coin-operated 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 vending_bank.h with one function already defined.
The data member id_ is a unique identifier for the vending bank.
vending_bank.h:
#ifndef VENDING_BANK_H_
#define VENDING_BANK_H_
#include
class VendingBank
{
public:
VendingBank();
VendingBank(int id);
//getters-setters
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 2: 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 when stored; number of minutes
should be between -60 and 60 when stored. That is, a user can create a TimeSpan object of 90
seconds, but it should be stored as 1 minute, 30 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 set_time(int hours, int minutes, int seconds): set the number of hours, minutes,
seconds.
Constructors
The class should define constructor(s) 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(1.5,4,-10) represents 1 hour, 33 minutes, 50 seconds.
TimeSpan(7,-3) represents 6 minutes, 57 seconds.
TimeSpan(-190) represents -3 minutes, -10 seconds.
TimeSpan(3,-90,120) represents 1 hour, 32 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 I/O
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 duration1(1,2,3);
std::cout << duration1;
Will output:
Hours: 1, Minutes: 2, Seconds: 3
Please use this EXACT format.
Turn In
A .zip file which contains:
time_span.h
time_span.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.
vending_bank.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

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Define indirect financial compensation (employee benefits).

Answered: 1 week ago

Question

Describe the selection decision.

Answered: 1 week ago