Assignment 01
Assignment 01
Fundamentals
Assignment 01 Page 1 of 4
CC-211 Object Oriented Programming FALL 2023
Fundamentals
Objectives:
This assignment will provide experience with Class, Constructors, Destructors, Member
Functions, Operator Overloading
Prerequisite Skills:
Understanding of Class design
Understanding of Constructor / Destructor
Understanding of Operator Overloading
Task 01
Problem Statement:
Instructions:
Design a class called NumDays. The class’s purpose is to store a value that represents a number of
work hours and convert it to a number of days. For example, 8 hours would be converted to 1 day,
12 hours would be converted to 1.5 days, and 18 hours would be converted to 2.25 days.
1) The class should have a constructor that accepts a number of hours, as well as member
functions for storing and retrieving the hours and days.
2) The class should also have the following overloaded operators:
a. Addition operator (+): When two NumDays objects are added together, the overloaded +
operator should return the sum of the two objects’ hours members.
b. Subtraction operator (–): When one NumDays object is subtracted from another, the
overloaded – operator should return the difference of the two objects’ hours members.
c. Prefix and postfix increment operators (++): These operators should increment the
number of hours stored in the object. When incremented, the number of days should be
automatically recalculated.
d. Prefix and postfix decrement operators (--): These operators should decrement the
number of hours stored in the object. When decremented, the number of days should be
automatically recalculated.
Design another class named TimeOff. The purpose of the class is to track an employee’s sick leave,
vacation, and unpaid time off.
Input Validation:
Assignment 01 Page 2 of 4
CC-211 Object Oriented Programming FALL 2023
Fundamentals
Company policy states that an employee may not accumulate more than 240 hours of paid vacation.
The class should not allow the maxVacation object to store a value greater than this amount.
Driver Program:
Write a program that uses an instance of the TimeOff class you designed above and perform the
following:
1) The program should ask the user to enter the number of months an employee has worked for the
company.
2) It should then use the TimeOff object to calculate and display the employee’s maximum number
of sick leave and vacation days.
Task 02
Problem Statement:
Instructions:
Create a class IntegerSet for which each object can hold integers in the range 0 through Size – 1. A
set is represented internally as an array of ones and zeros.
Array element a[ i ] is 1 if integer i is in the set. Array element a[ i ] is 0 if integer i is not in the set.
For Example: the following set contains values 0, 1, 3, 4, 7 and 9.
0 1 2 3 4 5 6 7 8 9
1 1 0 1 1 0 0 1 0 1
1) An integer pointer that holds a reference of an array created dynamically according to the
specified size.
2) A constant integer to hold the maximum size of the array.
1) A constructor which accepts an integer that represents the size of a set and initializes it to the
so-called "empty set," i.e., a set whose array representation contains all zeroes.
2) A copy constructor to initialize a set object with already existing object.
3) A destructor to free any memory resources occupied by the set object.
1) insertElement that inserts a new integer k (passed as argument) into a set by setting a[ k ] to 1.
2) deleteElement that deletes an integer k (passed as argument) by setting a[ k ] to 0.
3) unionOfSets that creates a third set that is the set-theoretic union of two existing sets (i.e., an
element of the third set's array is set to 1 if that element is 1 in either or both of the existing sets,
and an element of the third set's array is set to 0 if that element is 0 in each of the existing sets).
The union is only possible if both the sets have same sizes.
4) intersectionOfSets which creates a third set which is the set-theoretic intersection of two
existing sets (i.e., an element of the third set's array is set to 0 if that element is 0 in either or
Assignment 01 Page 3 of 4
CC-211 Object Oriented Programming FALL 2023
Fundamentals
both of the existing sets, and an element of the third set's array is set to 1 if that element is 1 in
each of the existing sets). The intersection is only possible if both the sets have same sizes.
5) findElement that searches an integer key (passed as argument) in a set and return true if the key
exists in the set, false otherwise.
6) isNullSet returns true if the set is an “empty-set” (a set whose array representation contains all
zeroes), false otherwise.
Overload following operators:
1) Stream insertion (<<) prints a set as a list of numbers separated by spaces. Print only those
elements that are present in the set (i.e., their position in the array has a value of 1). Print - - -
for an empty set.
2) Assignment (=) which copies the data of one object to another. The copy should only be done if
both the objects have same sizes (avoid self-assignment).
3) Equal (==) that determines whether two sets are equal or not. The operator should returns true
if both the sets are equal, false otherwise.
4) Logical NOT (!) create and return a new set which contains the reverse of left hand side
object, i.e. all the 1s exist in the set converted to 0s and vice versa.
5) Subscript ([]) for both lvalue and rvalue of non-const objects.
6) Subscript ([]) for rvalue of const objects
7) Unary minus (-) return true if all the elements of a collection are non-zeroes, false otherwise.
8) Unary Not (!) assigns zero to all the elements of the object i.e. convert the collection into its
“empty” form. 10.
9) Function (()) receives two parameters as argument start_index and end_index and return the
new sub collection which contains all the values exist in the left hand side object from
start_index to end_index both inclusive, if possible.
Driver Program:
Test the functionality of your created class by creating some of its objects. Also make calls to all the
member functions of the class to test their functionality.
File(s) to be submitted:
Submit .cpp files named RollNo_Task1.cpp and RollNo_Task2.cpp.
Assignment 01 Page 4 of 4