Professional Documents
Culture Documents
Encapsulation and Time Program
Encapsulation and Time Program
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
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
//including integers
//public specifier
#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: