100% found this document useful (1 vote)
24 views5 pages

Lab 02

The document outlines a lab assignment for Object Oriented Programming at the University of Central Punjab, focusing on classes in C++, access specifiers, methods, and constructors. It includes specific tasks for students to create classes such as Triangle, Student, and Car, each with defined attributes and methods, along with coding instructions and naming conventions. The tasks require students to implement various functionalities including getters, setters, and calculations related to the classes, with strict guidelines for code formatting and submission.

Uploaded by

asifhuzaifa123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
24 views5 pages

Lab 02

The document outlines a lab assignment for Object Oriented Programming at the University of Central Punjab, focusing on classes in C++, access specifiers, methods, and constructors. It includes specific tasks for students to create classes such as Triangle, Student, and Car, each with defined attributes and methods, along with coding instructions and naming conventions. The tasks require students to implement various functionalities including getters, setters, and calculations related to the classes, with strict guidelines for code formatting and submission.

Uploaded by

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

University of Central Punjab

Faculty of Information Technology

Object Oriented Programming


Lab 2024
Lab 02
Topic  Classes in C++, access specifiers and methods
 getter(accessors) and setters(mutators)
 Default and parameterized constructors and destructor

Making students familiarize with classes and their implementations in C++ ,


Objective
methods and access Specifiers and class constructor.

Instructions:
• Indent your code.
• Comment your code.
• Use meaningful variable names.
• Plan your code carefully on a piece of paper before you implement it.
• Name of the program should be same as the task name. i.e. the first program should be
Task_1.cpp
• In each file of your task either it is .cpp file or .h file Your name and roll no must be mention in the
start of your file as comment. For example, //L1F22BSCS1234 – Ali Rehman
• void main() is not allowed. Use int main()
• You are not allowed to use any built-in functions
• You are required to follow the naming conventions as follow:
o Variables: firstName; (no underscores allowed)
o Function: getName(); (no underscores allowed)
o ClassName: BankAccount (no underscores allowed)

Understanding of the question is part of the evaluation.


Mobile phone is strictly prohibited during the lab either lab is graded or
not.

Students are required to complete the following tasks in lab timings. Submission of each task
in prescribed timing is mandatory.
Tasks
Task 01: Time: 20 minutes
Perform this task in single source file.

Create a class named as Triangle having following private attributes:


 base (double)
 height(double)

Now write the following for the above-mentioned class:

a) The program should include functions to assign user defined values to the above-mentioned
variable and a display function to show the values.
b) Write a non-returning display function to print the attributes of the class.
c) Write a function calculateArea which calculates the area of the triangle and returns it.
d) Write a program to create five objects of Triangle with different data. Display the attributes of
the triangle through display function having greatest area.

Task 2: Time: 20 minutes


Perform this task in single source file.
A Student is an object in a university management System. Analyse the concept and identify the data
members that a student class should have. Also analyse the behaviour of student in a university
management System and identify the methods that should be included in Student class.

Create a class named as Student having the data members which you have identified above.

 The program should include functions to assign user defined values to the above-mentioned
variable and a display function to show the values. // void setvalue()
 Write a non-returning display function to print the attributes of the class in the format given
below. //display()
 Write a main program to create five objects of Student with different data. And then
display all of the object’s data
Perform Task 3 and Task 4 in separate source, header and main driver file.
Task 3: Time: 20 minutes

Create a class named as Car having following private attributes:

 carModel(integer)
 carName(string)
 carPrice(integer)
 carOwner(string)

Now write the following for the above-mentioned class:

 The program should include functions to assign user defined values to the above-mentioned
variable and a display function to show the values.// use getter and setter
 Write a non-returning display function to print the attributes of the class in the format given
below.
 Write a main program to create five objects of Car with different data. And then display all of
the object’s data.

A Student is an object in a
university management
System. Analyze the
concept and
identify the data
members that a
Student class should
have. Also analyze the
behavior of student in
a university
management System and
identify the methods
that should be included in
Student class.
Task 4: Time: 20 minutes

Create a class named as Student having the following private data members.
 rollNo(integer)
 name(string)
 address(string)
 cgpa(float)
 fee(double)
 semester(integer)
Now write the following for the above-mentioned class:
a) Write a non-returning input() function to input the attributes of the class.
b) Write a non-returning display() function to print the attributes of the class..
c) Write a function increaseFee() which accepts the student fee and increase the fee by 7.5%.
This function should tell the student about the raise in fee and new fee.
d) Create 5 object of class Student and test your code. All inputs will be taken from user.
Notes: Validate the values in the above function

Task 5: Time: 20 minutes

Extend the Task 4


a) Write separate setter and getter function which should receive parameter and initialize all
the attributes with the respective values received in the parameters.
b) Write appropriate default constructor for the class Student.
c) Write a non-returning input() function to input the attributes of the class by calling
appropriate setter functions.
d) Write a non-returning display() function to print the attributes of the class by calling
appropriate getter functions.
e) Write a function increaseFee() which accepts the student fee and increase the fee by 7.5%.
This function should tell the student about the raise in fee and new fee.

Notes: Validate the values in the above function

Task 6: Time: 30 minutes

Write a Circle class that has the following private member variables:
 radius: a double
 pi: a double initialized with the value 3.14159
The class should have the following public member functions:
a) Write the default constructor which that sets radius to 0.0.
b) Write the parameterized constructor which Accepts the radius of the circle as an argument.
c) Define setRadius a mutator function for the radius variable.
d) Define getRadius a accessor function for the radius variable.
e) Define getArea returns the area of the circle, which is calculated as area = pi * radius *
radius
f) Define getDiameter returns the diameter of the circle, which is calculated as
diameter = radius * 2
g) Define getCircumference. Returns the circumference of the circle, which is calculated as
circumference = 2 * pi * radius.

Write a program that demonstrates the Circle class by asking the user for the circle’s radius,
creating a Circle object, and then displaying the circle’s area, diameter, and circumference.

You might also like