Saad Elahi Lab Manual
Saad Elahi Lab Manual
CC1021L
Source Code:
2
Output:
Task 2:
Write a class to input the name of student and marks of three subjects. Calculate the
total marks & average marks. Each subject has a maximum of 100 marks.
Source Code:
3
Output:
Task 3:
Write a code to create a calculator which takes two values from user and apply
operation on user demand.
Source Code:
4
Output:
Task 1:
Create a class named 'Programming'. While creating an object of the class, if
nothing is passed to it, then the message "I love programming languages" should be
printed. If some String is passed to it, then in place of "programming languages" the
name of that String variable should be printed.
Source Code:
Output:
5
Task 2:
Write a program to print the name of student by creating a Student class. If no name
is passed while creating an object of Student class, then the name should be
"Unknown", otherwise the name should be equal to the string value passed while
creating object of Student class.
Source Code:
Output:
Task 3:
Create a class named 'Rectangle' with two data members- length and breadth and
a method to calculate the area which is length*breadth. The class has three
constructors.
6
Source Code:
Output:
7
Task 4:
Create a class of triangle having two constructors one is default or parametrized (it
depends on you) and the other one is shallow copy constructor you have to update
the value of base and height in copy constructor and print the area using both
constructors the formula used to calculate area is 1/2 (base*height). And also create a
deep copy constructor by taking height as a pointer. And repeat the same updation
with it.
Source Code:
Output:
8
Lab 5 (Encapsulation)
Task 1:
Write a code to that take 3 values from user and calculate the average of these 3
values. The variables in which the values are stored are declared in class under
public access modifier and the average function is also present in the class.
Source Code:
Output:
Task 2:
Write a code to calculate the area of the circle. The variable that stores the radius of
the circle is declared in class under private access modifier. And the functions that
are use to set and get the values are declared under public access modifier.
Source code:
9
Output:
Task 3:
Write a code to get the details of the student i.e name, id and age. The variables are
declared under the protected access modifier and is present in the base class while
the display function is present in derived class.
Source Code:
Output:
10
Lab 6 (Friend Functions and Friend Classes)
Task 1:
Write a program that takes length and breath from user in two different classes and then
by using friend function calculate its area.
Source Code:
11
Output:
Task 2:
Write a program that takes 2 numbers from user in a class and you have to find the
factorial of both numbers in friend class and at the last you have to add both factorials and
then print the addition.
Source code:
12
Output:
Task 3:
Write a program that print the area of the circle (∏ r2). In this program the user
enters the user of r in one class and the area is calculated in other friend class.
Source Code:
13
Output:
Source Code:
14
Output:
Task 2:
Write a code in which user take a number from user in one class as private member and
then declare a friend class in this class. In friend class you have to print the entered
number in reverse order.
Source Code:
15
Output:
Task 3:
Write a program to save the details of the employee. The members of the class are
employee_id, employee_name, employee_salary. Ask user to enter how many times he
wants to save the data. Then call the setdata() function according to user demand.
Source Code:
16
Output:
Task 4:
Use const keyword with pointer and then apply use basic arithmetic operations on a
variable and then assigned the variable to the const pointer and then display the const
pointer.
Source Code:
Output:
17