Lab 13
Lab 13
Signature: ____________________________
Objective
The objective of this lab is to observe the basic knowledge of programming in C++.
Equipment and Component
Component Value Quantity
Description
Computer Available in lab 1
Conduct of Lab
1. Students are required to perform this experiment individually.
2. In case the lab experiment is not understood, the students are advised to seek help from
the course instructor, lab engineers, assigned teaching assistants (TA) and lab
attendants.
In languages such as C++ or C#, you can overload operators within a structure to define custom behavior
for those operators. This means that you can define how operators like +, -, *, /, etc., work when used
with instances of your structure.
Lab Task
Part A [Marks: 5]
Part B: Implementation of Structure with Pointers & with Arrays (DMA) [Marks:
35]
Create a structure called Rectangle to represent rectangles in a 2D plane. The Rectangle
structure should have the following properties: length, width, and area.
Implement operator overloading for the Rectangle structure to support the following
operations:
Addition (+): Add two rectangles to create a new rectangle with a combined area.
Subtraction (-): Subtract the area of one rectangle from another rectangle to obtain
a new rectangle with the remaining area.
Multiplication (*): Multiply a rectangle by a scalar value to scale its area.
Division (/): Divide the area of a rectangle by a scalar value to reduce its area.
Write a C++ program that demonstrates the usage of the Rectangle structure and its
overloaded operators. Your program should perform the following tasks:
Create two instances of the Rectangle structure, representing two rectangles with
different dimensions.
Display the original rectangles, the result of each operation, and their respective areas.