0% found this document useful (0 votes)
63 views

Assignment 01

The document describes two C++ classes - NumDays for tracking work hours and days, and TimeOff for tracking employee leave. NumDays overloads operators like + and ++. TimeOff contains NumDays objects and tracks maximums and usage. IntegerSet represents sets as arrays, with functions like insertElement and unionOfSets. Operator overloading and testing is also covered.

Uploaded by

nomanbsit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Assignment 01

The document describes two C++ classes - NumDays for tracking work hours and days, and TimeOff for tracking employee leave. NumDays overloads operators like + and ++. TimeOff contains NumDays objects and tracks maximums and usage. IntegerSet represents sets as arrays, with functions like insertElement and unionOfSets. Operator overloading and testing is also covered.

Uploaded by

nomanbsit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CC-211 Object Oriented Programming FALL 2023

Fundamentals

Assignment 01 – Operator Overloading


Average expected estimated time to complete this assignment is 12 hours

 [1 HOUR] software requirement understanding


o reading of the assignment document
o understanding of problem statement
o understanding of software inputs and outputs
 [2 HOURS] software design
o identification of user-software interaction sequences
 software menus
 user inputs and
 software flows
o identification of required variables and data structures to be used
 for input, processing, and output
 identification of storage class specifications of required variables
o modularization of software into required functions
 proper naming of functions
 identification of tasks to be performed into functions
 identification of parameters and return types of functions
o identification of user defined header files
 names and functions to be placed in
o flow sequence of main function and call of various user defined functions from it
 [6 HOURS] software coding
o coding of user defined functions
o placement of user defined functions into header file/s
o coding of main function
 [2 HOURS] software testing
o running software on various inputs
o identification of software error and bugs
o removal of software error and bugs
 [1 HOUR] software documentation
o proper indentation of code
o use of proper naming conventions
o commenting of code

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.

1) It should have, as members, the following instances of the NumDays class:


a. maxSickDays: A NumDays object that records the maximum number of days of sick leave
the employee may take
b. sickTaken: A NumDays object that records the number of days of sick leave the employee
has already taken.
c. maxVacation: A NumDays object that records the maximum number of days of paid
vacation the employee may take.
d. vacTaken: A NumDays object that records the number of days of paid vacation the
employee has already taken.
e. Max Unpaid: A NumDays object that records the maximum number of days of unpaid
vacation the employee may take.
f. unpaidTaken: A NumDays object that records the number of days of unpaid leave the
employee has taken.
Additionally, the class should have members for holding the employee’s name and identification
number. It should have an appropriate constructor and member functions for storing and retrieving
data in any of the member objects.

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

The class should have following two private data members:

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.

Provide the implementation of following constructors and a destructor:

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.

Provide following member functions for the common set operations:

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.

Deadline: March 12, 2023. (11:59pm)

Assignment 01 Page 4 of 4

You might also like