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

oopm ex-4

Uploaded by

amnikshukla2501
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

oopm ex-4

Uploaded by

amnikshukla2501
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT NO.

Aim / Title: To understand the basic concept of OOPM

Problem Statement: C++ program to read time in HH:MM:SS format and convert into total seconds
Objectives: Defining functions inside class in C++

Outcomes: Students will be able to learn basic keyword

Pre-requisite: Basic knowledge of C++

Hardware requirements: Processor (CPU) with 2 gigahertz (GHz) frequency or above


A minimum of 2 GB of RAM
Monitor Resolution 1024 X 768 or higher
A minimum of 20 GB of available space on the hard disk

Software requirements: Any C++ Compiler/C++ IDE

Theory:

An object is an instance of a class. It represents a specific entity with its own state and behaviour.
Member Functions:
Member functions are functions that are defined within a class. They operate on the data
members of the class and define the object's behaviour.
Key Points:
1. Data Members:
o These are variables declared within a class that store data specific to an object of
that class.
o They can be of any data type, including primitive data types (like int, float, char)
and user-defined data types (like other classes).
2. Member Functions:
o These functions are defined within a class and are used to manipulate the data
members of the class.
o They can be used to:
 Initialize data members (constructor)
 Access and modify data members
 Perform calculations or operations on data members
 Interact with other objects
3. Access Specifiers:
o public: Members declared as public can be accessed from anywhere outside the
class.
o private: Members declared as private can only be accessed within the class.

1|Page
o protected: Members declared as protected can be accessed within the class and
its derived classes.
4. Member Function Calls:
o Member functions are called using the dot operator (.) on an object of the class.

Instructions: Write program in C++ language

Program:

#include<iostream>
using namespace std;

class Time
{
public:
int seconds;
int HH,MM,SS;
void gettime();
void convertIntoTime();
void display();
};

void Time::gettime()
{
cout<<"Enter hours: ";
cin>>HH;
cout<<"Enter minutes: ";
cin>>MM;
cout<<"Enter seconds:";
cin>>SS;
}
void Time::convertIntoTime()
{
seconds=HH*3600+MM*60+SS;
}
void Time::display(){
cout<<"Time in second is: "<<seconds;
}

int main(){
Time obj;

2|Page
obj.gettime();
obj.convertIntoTime();
obj.display();
}

Output:

Enter hours: 2
Enter minutes: 20
Enter seconds:10
Time in second is: 8410

Sample Viva Questions and Answers:

1. How you can convert HH:MM:SS into total seconds?

2. How many functions used in your program to convert it into seconds?

Roll Name of Date of Date of Grade Sign of Sign of


No. Student Performance Evaluation Student Faculty

3|Page

You might also like