Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Bahria University, Lahore Campus

Department of Computer Science


Lab Journal 04
(Spring 2021)

Course: Object Oriented Programming - Lab Date: _______________


Course Code: CSL-210 Max Marks: 15
Faculty’s Name: Ms. Iqra Ashraf

Name: _____________________ Enroll No: ___________________ Class:


______________

Objective(s):
Upon completion of this lab session, learners will be able to:
 Array of Objects
 Passing Objects as Arguments

Lab Tasks:
Task 1:
Create 10 objects array and access the index of 3,5,7,9
ANS:
#include <iostream>
int main(){

using namespace std;

int n[10]; /* declaring n as an array of 10 integers */


int i,j;

/* initializing elements of array n */


for ( i = 0; i<10; i++ )
{
cout << "Enter value of n[" << i << "]"<< endl;
cin >> n[i];
}

/* printing the values of elements of array */


for (j = 0; j < 10; j++ )
{
cout << "n[" << j << "] = " << n[j] << endl;
}

return 0;
}
%
Enrollment Number: ____________________________

Task 2:
Define a Class COPY with the following specifications:
Data Members:
copyNo
copyTitle
price
Member Functions:
take_data( ) A function to input copyNo,
copyTitle, price.
purchase_info( ) A function to ask the user to input the
number of copies to be
purchased of a copy. Then multiply it
with price of the copy.
[Note: User can search the copy using
its copyNo]
Write a menu driven program. Get data for five copy from user.

ANS:

#include<iostream>
using namespace std;

class Point
{
private:
int x, y;
public:
Point(int x1, int y1) { x = x1; y = y1; }

// Copy constructor
Point(const Point &p1) {x = p1.x; y = p1.y; }

int getX() { return x; }


int getY() { return y; }
};

int main()
{
Point p1(10, 15); // Normal constructor is called here
Page 2 of 4
%
Enrollment Number: ____________________________

Point p2 = p1; // Copy constructor is called here

// Let us access values assigned by constructors


cout << "p1.x = " << p1.getX() << ", p1.y = " << p1.getY();
cout << "\np2.x = " << p2.getX() << ", p2.y = " << p2.getY();

return 0;
}

Task3:
Implement the given class diagram.
Empolyee
-id:int
-name:string
+setdata(int,string):void
+getdata(Employee t[]):void

Task 4:
Write a program with a class that contains following data
members
Id
name
marks
Create an array of objects of size 10. Create a function read()
to take input from user. Create a function to calculate
percentage of each student and a function that displays the id
and name of the student that have the lowest percentage.

Lab Grading Sheet :


Task Max Obtained Comments(if any)
Mark Marks
Page 3 of 4
%
Enrollment Number: ____________________________

s
1. 05
2. 2.5
3. 2.5
4. 05
Total 15 Signature

Note : Attempt all tasks and get them checked by your Lab Instructor.

Page 4 of 4

You might also like