Here are C++ programs to convert time in Hours:Minutes:Seconds to seconds.
C++ program to convert time in Hours:Minutes:Seconds to seconds
#include<iostream>
using namespace std;
int main()
{
long hours,minutes,seconds,result;
cout<<"Enter hours ";
cin>>hours;
cout<<"Enter minutes ";
cin>>minutes;
cout<<"Enter seconds ";
cin>>seconds;
result=hours*3600+minutes*60+seconds;
cout<<"Time in seconds "<<result<<endl;
return 0;
}
using namespace std;
int main()
{
long hours,minutes,seconds,result;
cout<<"Enter hours ";
cin>>hours;
cout<<"Enter minutes ";
cin>>minutes;
cout<<"Enter seconds ";
cin>>seconds;
result=hours*3600+minutes*60+seconds;
cout<<"Time in seconds "<<result<<endl;
return 0;
}
C++ program to convert time in Hours:Minutes:Seconds to seconds using class
#include<iostream>
using namespace std;
class time
{
private:
long hours,minutes,seconds;
public:
void getdata()
{
cout<<"Enter hours : ";
cin>>hours;
cout<<"Enter minutes : ";
cin>>minutes;
cout<<"Enter seconds : ";
cin>>seconds;
}
long findsec()
{
long result;
result=hours*3600+minutes*60+seconds;
return result;
}
};
int main()
{
time second;
long sec;
second.getdata();
sec=second.findsec();
cout<<"Time in seconds "<<sec<<endl;
return 0;
}
using namespace std;
class time
{
private:
long hours,minutes,seconds;
public:
void getdata()
{
cout<<"Enter hours : ";
cin>>hours;
cout<<"Enter minutes : ";
cin>>minutes;
cout<<"Enter seconds : ";
cin>>seconds;
}
long findsec()
{
long result;
result=hours*3600+minutes*60+seconds;
return result;
}
};
int main()
{
time second;
long sec;
second.getdata();
sec=second.findsec();
cout<<"Time in seconds "<<sec<<endl;
return 0;
}
No comments:
Post a Comment