0% found this document useful (0 votes)
62 views

Department of Computer Sciences Lab Journal 01: Bahria University, Lahore Campus

This document is a lab journal from Bahria University's Department of Computer Sciences for their OOP lab course. It contains 4 tasks related to classes and objects in C++, including creating classes for a sphere, clock, and time objects. The tasks get progressively more complex and cover concepts like constructors, destructors, private and public members, and copy constructors. The document also includes a grading sheet to record the student's marks for each task.

Uploaded by

HA Aim
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
0% found this document useful (0 votes)
62 views

Department of Computer Sciences Lab Journal 01: Bahria University, Lahore Campus

This document is a lab journal from Bahria University's Department of Computer Sciences for their OOP lab course. It contains 4 tasks related to classes and objects in C++, including creating classes for a sphere, clock, and time objects. The tasks get progressively more complex and cover concepts like constructors, destructors, private and public members, and copy constructors. The document also includes a grading sheet to record the student's marks for each task.

Uploaded by

HA Aim
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/ 4

Bahria University, Lahore Campus

Department of Computer Sciences


Lab Journal 01
(Fall 2017)

Course: OOP LAB Date:


Course Code: CSL - 113 Max Marks: 40
Lab Engineer: SIR SHOAIB
Faculty’s Name: Aasim Ali
KHAN

Name:____________________________________ Enroll No: _______________________

Objective(s) :
Lab 3 Tasks:

Task 1 :
#include<iostream>
using namespace std;

class Sphere
{
double pi;
public: Sphere()
{
pi=3.14;
}

~Sphere()
{
cout<<"destructor"<<endl;
}
double area(int r)
{ double area;
area=4*pi*r*r;
cout<<area;
return 0;
}

};
int main()
{ double radius;
Sphere s;
cout<<"Enter the radius"<<endl;
cin>>radius;
s.area(radius);
system("pause");
return 0;
}

Department of Computer Science, BULC


Task 2:
#include<iostream>
using namespace std;

class Clock{
int hours,min,sec;
public:
Clock(){
hours=min=sec=0;
}

~Clock(){
cout<<"Destructor"<<endl;
}
Clock(int h,int m,int s)
{
hours=h;
min=m;
sec=s;
cout<<hours<<":"<<min<<":"<<sec<<endl;
}
};
int main()
{ Clock t;
int hh,mm,ss;
cout<<"Enter hours : "<<endl;
HH:
cin>>hh;
if(hh<0||hh>12){
cout<<"Enter valid hours : ";
goto HH;}
cout<<"Enter minutes : "<<endl;

MM:
cin>>mm;
if(mm<0||mm>59){
cout<<"Enter valid minutes : ";
goto MM;
}
cout<<"Enter seconds : "<<endl;
SS:
cin>>ss;
if(ss<0||ss>59){
cout<<"Enter valid seconds : ";
goto SS;
}
Clock(hh,mm,ss);

system("pause");
return 0;
}

TASK 3:
#include<iostream>

Department of Computer Science, BULC


using namespace std;
class sample {
private:
int x; double y;
public:
sample() {
x = 0; y = 0;
cout << x << y << endl;
}
sample(int a)
{
y = 0;
cout << a << y << endl;
}
sample(int c, int b)
{
cout << c << b << endl;
}
sample(int s, double d) {
cout << s << d << endl;
}
};
int main() {
sample const1;
sample const2(21);
sample const3(65, 82);
sample const4(1, 0.1);
system("pause"); return 0;
}

Task 4 :
#include<iostream>
using namespace std;

class Time
{

int hours,minutes,seconds;
public:
Time( int = 0, int = 0, int = 0 );

void setTime(int hh,int mm,int ss){setHour(hh);


setMinutes(mm);
setSecond(ss);}
void setHour(int hh)
{ if(hh>=0 && hh<=23) hours=hh;}
void setMinutes(int mm)
{ if (mm>=0 && mm<=59) minutes=mm; }
void setSecond(int ss)
{ if(ss>=0 && ss<=59) seconds=ss; }

void input()

Department of Computer Science, BULC


{cout<<"Input Hours, minutes, seconds,";int hh, mm, ss; cin>>hh>>mm>>ss;
setTime(hh,mm,ss);}
void printUniversal()
{
cout<<hours<<":"<<minutes<<":"<<seconds<<endl;}

};
int main()
{
Time t;
t.setTime(11,59,59);
Time t1= t;// copy constructor
cout<<"normal constructor"<<endl;
t.printUniversal();
cout<<"copy constructor"<<endl;
t1.printUniversal();

system("pause");
return 0;
}

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