Lab 02
Lab 02
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)
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.
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.
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
carModel(integer)
carName(string)
carPrice(integer)
carOwner(string)
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
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.