Object-Oriented Programming Lab: Arrays, Constants, and Student Data, Essays (university) of Object Oriented Programming

In this topic i will tell about how to add number in oop

Typology: Essays (university)

2019/2020

Uploaded on 06/15/2020

abdul-rehma
abdul-rehma 🇵🇰

5

(1)

2 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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;
pf3
pf4

Partial preview of the text

Download Object-Oriented Programming Lab: Arrays, Constants, and Student Data and more Essays (university) Object Oriented Programming in PDF only on Docsity!

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 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;

Enrollment Number: ____________________________ } }; void main() { time t(30, 9, 7); t.display(); }

Task 2

Write a program with a class that contains following data members

 Id

 name

 marks

Create and array of objects of size 10. Create a function read() to take input from user. Create

a function to calculate percentage of each student. Then create a function that displays the

student id and name of the student with the lowest percentage.

#include #include using namespace std; class student { int marks; int id; string name; public: student(); void read(); }; student::student() { marks = 0; id = 0; name = " "; } student::student() { marks = 0; id = 0; name = " "; } void student::read() { } void main() { student p[10];

Enrollment Number: ____________________________ cout << "enter the day:" << endl; cin >> a; person p(25,"12-3-2000","haider ali"); p.display(); Lab Grading Sheet :

Task

Max

Mark

s

Obtained

Marks

Comments( if any )

Total 10 Signature

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