Bahria University, Lahore Campus
Department of Computer Science
Lab Journal 04
(Spring 2020)
Course: Object Oriented Programming - Lab Date: _______________
Course Code: CSL-210 Max Marks: 10
Faculty’s Name: Ms. Zupash Awais
Name: _____________________ Enroll No: ___________________ Class:
______________
Objective(s):
Upon completion of this lab session, learners will be able to:
Array of Objects
Const Members
Lab Tasks:
Task 1
Create a class called time that has separate int member data for hours, minutes, and seconds.
One constructor should initialize this data to 0, and another should initialize it to fixed values.
Another member function should display it, in 11:59:59 format.
#include<iostream>
using namespace std;
class time
{
int hour;
int min;
int second;
public:
time() :hour(0), min(0), second(0)
{
}
time(int a, int b, int c)
{
hour = a;
min = b;
second = c;
if (hour <= 0 || hour >= 23)
hour = 0;
if (min <= 0 || min >= 59)
min = 0;
if (second <= 0|| second >= 59)
second = 0;
}
void display()
{
cout << hour << ":" << min << ":" << second << endl;