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

Classes & Objects lab

Uploaded by

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

Classes & Objects lab

Uploaded by

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

OBJECT ORIENTED PROGRAMMING

LAB MODULE ASSIGNMENT QUESTIONS


TOPIC: Objects & Classes

DEPARTMENT OF CS, FCIT, IIUI


FALL-2024, CLASS BSIT A & B
Lecturer: Mr. Jahanzaib Niazi
Lab Tasks

1. Create a Rectangle Class


Implement a Rectangle class that includes:
o Private member variables for length and width.
o A default constructor that initializes the rectangle to default values
(e.g., length and width set to 0).
o A parameterized constructor that accepts values for length and width.
o Implement a method to calculate and display the area of the rectangle.
2. Demonstrate Constructor Overloading
Extend the Rectangle class to include:
o Constructor overloading with multiple constructors that initialize the
rectangle differently (e.g., one with default values and another with
specific values).
o Provide examples in a main program demonstrating how to create
Rectangle objects using different constructors.
3. Use of Setter and Getter Methods
o Implement setter and getter methods in the Rectangle class for
length and width.
o Write a main program that creates a Rectangle object, modifies its
dimensions using setters, and displays the updated area using getters.
4. Initialize Using Initializer Lists
o Modify the Rectangle class to use initializer lists in the constructors.
o Show an example in the main program where an object is initialized
using the initializer list.
5. Array of Rectangle Objects
o Write a program that creates an array of Rectangle objects.
o Initialize the array with different lengths and widths using
constructors.
o Iterate through the array and display the area of each rectangle using a
simple for loop.
6. Default Constructor and Parameterized Constructor
o Discuss what happens when both default and parameterized
constructors are defined.
o Create a simple example illustrating the usage of both in a single
program.
7. Default Constructor with Default Arguments
o Implement a default constructor that includes default arguments for
length and width.
o Create instances of the Rectangle class to demonstrate the use of
default arguments.
8. Understanding the Purpose of Access Specifiers
o Create a class that illustrates the use of public, private, and
protected access specifiers.
o Write methods that demonstrate how each access specifier affects
accessibility of member variables.
9. Implement Basic Input Validation
o Add basic input validation in the setter methods of the Rectangle
class to ensure that negative values for dimensions are not accepted.
o Modify the main program to handle these validations gracefully.
10.Simple Text-Based Menu System
o Create a simple text-based menu in the main program that allows
users to:
 Create a rectangle.
 Display the area of the rectangle.
 Modify dimensions using setters.
 Exit the program.
o Use a loop to keep the program running until the user chooses to exit.

*************************THE END**************************

You might also like