You are on page 1of 3

Bahria University, Lahore Campus

Department of Computer Sciences


Lab Journal 01
(Spring 2018)

Course: Object Oriented Programming Lab Date:


Course Code: CSL - 210 Max Marks: 40
Faculty’s Name: Aasim Ali Lab Engineer: Shoaib Khan

Name: Mohammad Jasim Waqar Enroll No: 03-135172-055

Task 1:
Read 10 numbers in an array. Each number must be between 10 and 100. As each number is read, print it
only if it is not a duplicate of a number already entered.
ANSWER:
#include<iostream>
#include<string>
using namespace std;
void main(){
int arr[10];
for(int i = 0;i<10;i++){
cout<<"Enter "<<i<<" number : ";
cin>>arr[i];
if ( arr[i]<10 || arr[i]>100){
while(arr[i]<10 || arr[i]>100){
cout<<"Enter wrong value .... Enter "<<i<<" value again : ";
cin>>arr[i];
}
}
}
for (int i =0 ; i<10 ; i++){
for(int y=1;y<10;y++){
if (arr[i]== arr[y]){
arr[i]=0;
break;
}
else
arr[i] = arr[i];
}
if (arr[i]> 0)
cout<<arr[i]<<endl;
}

system("pause");
}

Department of Computer Science, BULC


Task 2:
Create a struct teacher which has id, name, and designation as its members. Pass a parameter of type
teacher it to function by value and assign value to it. Now print it in main.

ANSWER:
#include<iostream>
#include<string>
using namespace std;

struct teacher{
int id;
string name;
string designation;
};

teacher input(teacher b){


b.id=766;
b.name="Jasim";
b.designation="Teacher";
return b;
}

void main(){
teacher a,b;
a=input(b);
cout<<"ID : "<<a.id<<endl;
cout<<"Name : "<<a.name<<endl;
cout<<"Designation : "<<a.designation<<endl;

system("pause");
}

Task 3:
Create a struct teacher which has id, name, and designation as its members. Pass a parameter of type
teacher it to function by reference and assign value to it. Now print it in main.
ANSWER:
#include<iostream>
#include<string>
using namespace std;

struct teacher{
int id;
string name;
string designation;
};

void input(teacher& b){


b.id=766;
b.name="Jasim";
b.designation="Teacher";

Department of Computer Science, BULC


}

void main(){
teacher a;
input(a);
cout<<"ID : "<<a.id<<endl;
cout<<"Name : "<<a.name<<endl;
cout<<"Designation : "<<a.designation<<endl;

system("pause");
}

Lab Grading Sheet :


Max Obtained
Task Comments(if any)
Marks Marks
1. 10
2. 10
3. 10
4. 10

Total 40 Signature

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

Department of Computer Science, BULC

You might also like