Need help writing a simple C++ code. I am competing in a Triathlon in September.
ID: 3666433 • Letter: N
Question
Need help writing a simple C++ code. I am competing in a Triathlon in September. The race consists of a run, followed by a kayak segment, and a race back to the starting point on a bicycle. I want you to write a program that allows me to enter the time in hours, minutes and seconds for each segment( 3 sets of prompts, once for each event – lots of copy and paste) and gives me a total time in hours, minutes and seconds. They come pull you off the course in 3 hours so I need to know how I’m doing in training to avoid being booted off the course. The answer must be reported in hours, minutes, seconds (Ex. 2 hrs 20 min NOT 1 hr 80 min) use mod and div to get the final answer
Explanation / Answer
# include<iostream>
using namespace std;
class time
{
int hour;
int min;
int sec;
public:
void gettime();
void puttime();
void addtime(time t1,time t2,time t4);
};
void time::gettime()
{
cout<<" ENTER THE TIME IN HOURS SPACE MINUTES SPACE SECONDS:";
cin>>hour;
cin>>min;
cin>>sec;
}
void time::puttime()
{
cout<<" TOTAL TIME: ";
cout<<" HOURS: "<<hour;
cout<<" MINUTES: "<<min;
cout<<" SECONDS: "<<sec;
}
void time::addtime(time t1,time t2,time t4)
{
sec=t1.sec+t2.sec+t4.sec;
min=sec/60;
sec=sec%60;
min=t1.min+t2.min+t4.min+min;
hour=min/60;
min=min%60;
hour=t1.hour+t2.hour+t4.hour+hour;
}
int main()
{
time tm1,tm2,tm3,tm4;
cout<<" FIRST TIME ";
tm1.gettime();
cout<<" SECOND TIME ";
tm2.gettime();
cout<<" THIRD TIME ";
tm4.gettime();
tm3.addtime(tm1,tm2,tm4);
tm3.puttime();
}
If you want any other specifications to add to the program please specify me i will add those specifications to the program ..Thank you..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.