11-09-2008, 09:06 PM
|
| Addicted to Computer | | Join Date: Sep 2007 Location: ------------ Age: 34
Posts: 1,309
Contact Number: --------------- Program / Discipline: BSIT Class Roll Number: 07-01 | |
Solution of Ex 5,6,2 & 4 Ch# 5 Robert Lafore OOP c++
Solution of Exercise 5 Code: #include <iostream>
using namespace std;
long hms_to_secs(int h,int m,int s)
{
long seconds;
seconds=h*3600+m*60+s;
return seconds;
}
void main()
{
char c;
int h,m,s;
for(int n=1;n<10;n++)
{
cout<<"enter time in this formate 12:12:49 : ";
cin>>h>>c>>m>>c>>s;
cout<<hms_to_secs(h,m,s)<<endl;
}
}
Solution of Exercise 6 Code: #include <iostream>
using namespace std;
struct time
{
int hours,minutes,seconds;
};
long time_to_secs(time);
time secs_to_time(long);
int main()
{
time time1,time2;
char colon;
cout<<"enter First time in this format (12:30:30):";
cin>>time1.hours>>colon>>time1.minutes>>colon>>time1.seconds;
cout<<"enter Second time in this format (12:30:30):";
cin>>time2.hours>>colon>>time2.minutes>>colon>>time2.seconds;
long totalseconds1=time_to_secs(time1);
long totalseconds2=time_to_secs(time2);
long totalseconds=totalseconds1+totalseconds2;
time totaltime=secs_to_time(totalseconds);
cout<<"\nTotal Time: "<<totaltime.hours<<":"<<totaltime.minutes<<":"<<totaltime.seconds<<endl;
return 0;
}
long time_to_secs(time time1)
{
long totalseconds=time1.hours*3600 + time1.minutes*60 + time1.seconds;
return totalseconds;
}
time secs_to_time(long totalseconds)
{
int temp;
time time3;
time3.hours=totalseconds/3600;
temp=totalseconds%3600;
time3.minutes=temp/60;
time3.seconds=temp%60;
return time3;
} Ahmad ne kaha tha mein kar doon ga post...
Ahmad ne tu post karnay hi nahin hain, Main he kar daita hoon |