program to add n time using class and object concept
#include<iostream.h>
#include<conio.h>
class time
{
public:
int h,m,s,oh,om,os,i,j,n,p,q;
void read();
void display();
}ob;
void time:: read()
{
cout<<"Enter the limit\n";
cin>>n;
h=0;
m=0;
s=0;
for(i=0;i<n;i++)
{
cout<<"Enter the "<<i+1<<" time in hh/mm/ss format \n";
cin>>oh;
h=h+oh;
cin>>om;
m=m+om;
cin>>os;
s=s+os;
}
}
void time::display( )
{
p=ob.s/60;
ob.s=ob.s%60;
q= (ob.m+p)/60;
ob.m=(ob.m+p)%60;
ob.h=ob.h+q;
cout<<" time in hh/mm/ss format \n";
cout<<ob.h<<":"<<ob.m<<":"<<ob.s;
}
void main()
{
clrscr();
ob.read();
ob.display();
getch();
}
program to add n numbers using class and object concept |
#include<conio.h>
class time
{
public:
int h,m,s,oh,om,os,i,j,n,p,q;
void read();
void display();
}ob;
void time:: read()
{
cout<<"Enter the limit\n";
cin>>n;
h=0;
m=0;
s=0;
for(i=0;i<n;i++)
{
cout<<"Enter the "<<i+1<<" time in hh/mm/ss format \n";
cin>>oh;
h=h+oh;
cin>>om;
m=m+om;
cin>>os;
s=s+os;
}
}
void time::display( )
{
p=ob.s/60;
ob.s=ob.s%60;
q= (ob.m+p)/60;
ob.m=(ob.m+p)%60;
ob.h=ob.h+q;
cout<<" time in hh/mm/ss format \n";
cout<<ob.h<<":"<<ob.m<<":"<<ob.s;
}
void main()
{
clrscr();
ob.read();
ob.display();
getch();
}
No comments:
Post a Comment