You are on page 1of 5

ASSIGNMENT

SUBMITTED TO:
SIR UMAIR SB.
SUBMITTED BY:
MR. MUHAMMAD REHAN TARIQ
ROLL NO.:
(21-UON-0931)
SEMESTER:
BS CS (EVENING)
UNIVERSITY OF NAROWAL
(OLD CAMPUS)
COMMENTS
//program start with header file.
//using class name
Encapsulation //using private access specifier

is defined as: //using public access specifier


//int main (code runner)
Encapsulation is a process of wrapping of data and method in a single
unit. It is achieved in C++ language by class concept. Combining of
state and behavior in a single container is called Encapsulation. In C++
language encapsulation can be achieved using class keyword , state
represent declaration of variable in attributes and behavior represent //header file
operation in terms of method. //using class sum

Syntax of Encapsulation : //adding numbers


Class class name
{ //printing out
Private:
Datatype data;
Public: //code runner int main()
Member function ;
};
Main(){
Class name objectname;
}

Example:
#include<iostream>
using namespace std;
class sum{ private: int a,b,c;
public:
void
add(){
cout<<”enter any two number :”;
cin>>a>>b;
c=a+b;
cout<<”sum :”<<c;
}
};
int main(){
sum s;
s.add();
}
//using namespace std;
//as header file
TIME PROGRAM # 01: //declaring digits
//using void
#include<iostream>
using namespace std; //setting all the values of the integers
class time{
private:
int min,hour,sec;
public:
void setmin(int m){
min=m;
}
int getmin(){
return min; //using code runner int main()
}
void setsec(int s){ //using objects
sec=s; //clock in h, m and s
}
//printing out the values
int getsec(){
return sec;
}
void sethour(int h){
hour=h;
}
int gethour(){
return hour;
}
};
int main(){
int h,m,s;
time clock;
cout<<"enter hour"<<endl;
cin>>h;
clock.sethour(h);
cout<<"enter minute"<<endl;
cin>>m;
clock.setmin(m);
cout<<"enter second"<<endl;
cin>>s;
clock.setsec(s);
cout<<clock.gethour();
cout<<":";
cout<<clock.getmin();
cout<<":";
cout<<clock.getsec();} //again using header file

OUTPUT: //using class time

//including integers
//public specifier

//including all the values

TIME PROGRAM # 02:


//using void

#include<iostream>
using namespace std;
class time{
private:
int min,hour,sec;
public:
void setmin(int m){
min=m;
}
int getmin(){
return min;
}
void setsec(int s){
sec=s;
}
int getsec(){ //now
return sec;
} //using
void sethour(int h){
hour=h; //main functions
} //using objects
int gethour(){ //time as clock(object)
return hour;
//printing out
}
};
int main(){
time clock;
clock.setmin(2);
clock.setsec(3);
clock.sethour(5);
cout<<clock.gethour();
cout<<":";
cout<<clock.getmin();
cout<<":";
cout<<clock.getsec();}

OUTPUT:

You might also like