//P5.6
//Ahmad Furqan
//1-3-2013
#include <iostream>
#include <conio.h>
using namespace std;
struct time
{
int hours;
int mins;
int secs;
};
long time_to_secs(time& );
time secs_to_time(long&);
void main(void)
{
time t;
long secs;
cout<<"Enter time in format (hh:mm:ss)"<<endl;
char ch;
cin>>t.hours>>ch>>t.mins>>ch>>t.secs;
cout<<"Equivalent time in seconds is "<<time_to_secs(t)<<" Seconds"<<endl;
cout<<"Enter time in seconds"<<endl;
cin>>secs;
time t1=secs_to_time(secs);
cout<<"Equivalent time is "<<t1.hours<<" Hours "<<t1.mins<<" Minutes "<<t1.secs<<" Seconds"<<endl;
_getch();
}
//time_to_secs
//converts time to secs
long time_to_secs(time& t)
{
return t.secs+t.mins*60+t.hours*60*60;
}
//secs_to_time
//converts secs to time
time secs_to_time(long& secs)
{
time t;
t.hours=secs/3600;
secs-=t.hours*3600;
t.mins=secs/60;
secs-=t.mins*60;
t.secs=secs;
return t;
}
Wednesday, 26 November 2014
Chapter 5,Problem 6:Object Oriented Programming by Robert Lafore in C++ Solution Manual
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment