0% found this document useful (0 votes)
17 views2 pages

COC2071 - Lab Manual 04 (Classes, Constructors)

The document outlines a lab plan for Object Oriented Programming (COC2071) focusing on classes, constructors, and copy constructors. It includes tasks for creating classes such as Person, Room, Quadratic, Student, and Friend, with specific functionalities and methods to implement. The lab aims to reinforce understanding of OOP concepts through practical programming exercises.

Uploaded by

ahassan7695
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

COC2071 - Lab Manual 04 (Classes, Constructors)

The document outlines a lab plan for Object Oriented Programming (COC2071) focusing on classes, constructors, and copy constructors. It includes tasks for creating classes such as Person, Room, Quadratic, Student, and Friend, with specific functionalities and methods to implement. The lab aims to reinforce understanding of OOP concepts through practical programming exercises.

Uploaded by

ahassan7695
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Object Oriented Programming – COC2071

Lab Plan 04 (Classes, Constructors, and Copy Constructors)

Objective: In this hands-on lab, you will learn the fundamental concepts of classes, constructors, and
copy constructors in Object-Oriented Programming (OOP). You will create a simple program in a
programming language of your choice to reinforce your understanding of these concepts through
practical implementation.

Task 1:

1) Create a new class named Person with attributes such as name, age, and gender. Define the
class methods to set and get the values of these attributes. Instantiate an object of the Person
class and print out its attributes.
2) Modify the Person class to include constructors. Create a parameterized constructor to initialize
the attributes when an object is created. Create default constructors (constructors without
parameters) that set default values for the attributes. Instantiate objects using both
constructors and print out their attributes.
3) Create a copy constructor for the Person class that takes another Person object as a parameter
and creates a new object with the same attributes. Instantiate a new Person object using the
copy constructor. Modify the attributes of the original object and ensure that the copied object
remains unaffected.
4) Create multiple Person objects using different constructors. Test the copy constructor by
creating a copy of an existing Person object and modifying the original object afterward. Print
out the attributes of all objects to validate the changes.
5) Implement input validation for the attributes (e.g., age cannot be negative). Create a method
within the Person class to display a formatted string containing the person's information. Create
a subclass of Person with additional attributes and methods.

Task 2:

1) Create a class Room with the fields room number, room type, and AC installed or not.
2) Take the values of 10 rooms from the user and print these values through properties.

Task 3:

1) Create a class Quadratic which should have the following methods:


2) InputData: Takes the inputs of the constants i.e., a, b, and c from the user.
3) CalculateEquation: Solves the quadratic equation and returns the roots.
4) CheckForImaginary: Returns true if a solution exists for the given inputs otherwise returns false.
5) Print: Display positive and negative roots, if the solution exists.

1/1
Object Oriented Programming – COC2071
Lab Plan 04 (Classes, Constructors, and Copy Constructors)

Task 4:

1) Create a class Student with registration number, name, cgpa, and discipline fields. Provide the
followings:
2) Create an array of 5 Student objects.
3) Input registration number, name, cgpa, and discipline from the user through relevant
properties.
4) Print the student’s data through PrintInfo method.
5) Print the record of the student who is the top of the class through Topper method.

Task 5:

1) Create a class Friend with name, mobile number, and email as data fields. The class should have
the following functionalities:
2) The class should be able to add record in the friend’s directory and print message “Directory is
filled, no more contacts can be added!!!!” if the directory has filled i.e., out of memory. The
directory should allow a maximum of 10 friends to store.
3) The class should be allowed to print all the records from the directory in tabular form.
4) The class should allow to search the friend data by asking friend’s name and print the record of
the friend, if directory contains the specified friend else "No friend with given name" message
should be printed.

2/1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy