Object Oriented Programming
Fall 2024
                                            Lab 07
Instructions:
   1. Comment your code.
   2. Use meaningful variable names.
   3. Plan your code carefully on a piece of paper before you implement it.
   4. Name of the program should be same as the task name. i.e., the first program should be
      Task_1.cpp
   5. Complete each task in 3 files.
   6. You are not allowed to use any built-in functions
   7. You are required to follow the naming conventions as follow:
          a. Variables: firstName; (no underscores allowed)
          b. Function: getName(); (no underscores allowed)
          c. ClassName: BankAccount (no underscores allowed)
Students are required to complete the following tasks in lab timings.
Task 1:
Problem Statement: Rectangle Class Design and Operations
You are tasked with designing and implementing a Rectangle class in C++ to represent a
rectangle's dimensions and perform various operations on it. The class should encapsulate the
rectangle's properties and provide functionality for comparison, copying, validation, and
calculations.
Requirements:
   1. Attributes:
         o The class should include the following attributes:
                  int length: Represents the length of the rectangle.
                  int width: Represents the width of the rectangle.
   2. Copy Constructor:
         o Implement a copy constructor to create a new Rectangle object as a copy of an
             existing Rectangle object.
   3. Destructor:
         o Implement a destructor to handle cleanup operations, ensuring the program
             remains robust (even if no dynamic memory is used).
   4. Overloaded Constructor with Default Values:
         o Provide a constructor to initialize the Rectangle object with:
                  Default values (length = 1, width = 1).
                  Specific values provided by the user, ensuring dimensions are valid.
   5. Validation:
         o Ensure that rectangle dimensions are always valid:
                     length > 0
                     width > 0
           o Throw appropriate exceptions for invalid dimensions.
   6. Getter Functions:
         o Provide getter functions (getLength and getWidth) to retrieve the dimensions of
             the rectangle. Setters are not required.
   7. Operator Overloading:
         o Implement the following comparison operators to compare the areas of two
             rectangles:
                  operator==: Check if the areas of two rectangles are equal.
                  operator!=: Check if the areas of two rectangles are not equal.
                     operator>: Check if the area of one rectangle is greater than the other.
                     operator<: Check if the area of one rectangle is smaller than the other.
                     operator<=: Check if the area of one rectangle is smaller than or equal to
                      the other.
                     operator>=:   Check if the area of one rectangle is greater than or equal to
                 the other.
   8. Member Functions:
           o   calculateArea(): Compute and return the area of the rectangle.
           o   calculatePerimeter(): Compute and return the perimeter of the       rectangle.
   9. Display Function:
         o Include a member function to display the rectangle's details (length, width, area,
             and perimeter).
Extended Task 1:
Design a class Rectangle to represent a rectangle's dimensions and perform operations on it.
The class should include the following attributes:
      Attributes:
           o   int* length
           o   int* width
Requirements:
   1. Copy Constructor:
          o Implement a copy constructor to create a new Rectangle object as a copy of
              another Rectangle object.
   2. Destructor:
          o Ensure dynamic memory for length and width is properly deallocated.
   3. Overloaded Constructor with Default Values:
          o Provide a constructor to initialize the Rectangle object with default values (e.g.,
              length = 1 and width = 1) or specific values provided by the user.
   4. Getter for Each Attribute:
          o Implement getter functions for length and width. Setters are NOT required.
   5. Operator Overloading: Implement the following overloaded operators to compare the
      areas of two rectangles:
          o operator == (Check if the areas of two rectangles are equal)
          o operator > (Check if the area of one rectangle is greater than the other)
          o operator != (Check if the areas of two rectangles are not equal)
          o operator < (Check if the area of one rectangle is smaller than the other)
          o operator <= (Check if the area of one rectangle is smaller than or equal to the
              other)
          o operator >= (Check if the area of one rectangle is greater than or equal to the
              other)
   6. Validation: Ensure that the dimensions remain valid:
           o   length > 0
             o   width > 0
Stretch Goal:
Add a member function calculatePerimeter() to return the perimeter of the rectangle and
another function calculateArea() to return its area.
Task 2:
Let’s create a class Time to work with a 12-hour formatted time having the
following attributes:
int* hours
int* minutes
int* seconds
Provide the following functions:
1 Copy Constructor
2 Destructor
3 Overloaded constructor with default values
4 Getter of each attribute (setters are NOT required)
5 operator ==
6 operator >
7 operator !=
8 operator <
9 operator <=
10 operator >=
Make sure to check that the time remains valid in all the functions that are:
A. 1 <= hours <=12
B. 0 <= minutes < 60
C. 0 <= seconds < 60
Task 3:
Let’s create a class Date to store a date having the following attributes:
       int* day
       int* month
       int* year
Provide the following functions:
   1. According to the rule of three:
          i.  Copy Constructor
         ii.  operator =
        iii.  Destructor
   2. Overloaded constructor with default values
   3. Getter of each attribute (setters are NOT required)
   4. operator ==
   5. operator >
   6. Only using operator == and operator >, provide implementation of:
          i.  operator !=
         ii.  operator <
        iii.  operator <=
        iv.   operator >=
   7. operator <<              //Output example: 30-2-1985
   8. operator >>
   9. operator +               //to add certain days to the date
   10. operator -              //to subtract days from the date
   11. operator ++
          i.  post-increment
         ii.  pre-increment
   12. operator --
          i.  post-increment
         ii.  pre-increment
Important Instructions:
Make sure:
   1. to check that the time remains valid in all the functions:
          a. 1 <= day <= 31
          b. 0 <= month <= 12
          c. 0 <= year <= n where n is a positive integer
   2. Valid days are saved in each month:
          a. February has 28 days
          b. March, May, July, August, October, and December have 31 days
          c. April, June, September, and November have 30 days
   3. No need to check leap years (in which February has 29 days)
   4. After addition or subtraction, make sure the answers are valid. For example:
              i.       30-3-1985 + 6 days will return date as 5-4-1985
              ii.      11-12-2021 + 22 days will return date as 2-1-2022
              iii.     20-3-1985 - 155 days will return date as 16-10-1984