1- Write a program that asks the user to input a number of seconds and displays the corresponding time in the form: hours:minutes:seconds. The total number of hours should not exceed 23.
Example: if the input is 7275, the output will be: 2:1:15
Hint: if t is the time in seconds, its components are:
Hours= (t/3600)%24
Minutes= (t/60)%60
Seconds= t%60
2- In many operations on time objects, you need to convert the time into seconds and perform the operation. Write a function that converts the time with hours, minutes, and seconds components into seconds. The function has the specifications:
int timeinseconds( int hours, int minutes, int seconds).
3- Implement the class Time with the following members:
a- The member variables hours, minutes, and seconds are private. The constructors will ensure that hours< 24, minutes<60, and seconds<60.
b- A constructor with three arguments representing respectively the hours, minutes, and seconds.
Add to this constructor features to adjust the time such that hours< 24, minutes<60, and seconds<60. For example, the time (25, 30,65) should be adjusted to (1, 31, 5).
c- A constructor with one argument assumes its argument is in seconds.
d- A copy constructor that uses a call by reference.
e- Readers and writers member functions.
f- A member function print displays the time in the form hours:minutes:seconds, for example 22:12:13.
g- A member function that adds two time objects
h- Boolean member functions that compare time objects.
4- In order to evaluate your work in a busy day, declare an array of 10 time objects, and initialize it to the times needed to perform your most important 10 tasks during this day (a task cannot exceed 3 hours).
a- Calculate and print the total time needed to perform these tasks.
b- Write a function bubble sort for time objects and use it to sort the array in ascending order of time. Use the result to print the time needed by the most important two tasks.
NEED help in The parts: 3 -h- and 4 -b- ;
my code is :
#include <iostream>
using namespace std;
class Time {
private:
int hours;
int minutes;
int seconds;
public:
Time () {
hours = 0;
minutes = 0;
seconds = 0;
}
Time(int hours , int minutes , int seconds){
switch( seconds < 60 ){
case true:
seconds = seconds;
case false:
seconds = seconds - 60;
minutes++;
if( minutes >59 && hours < 24 ){
seconds = 0;
minutes=0;
hours++;
}
else if ( hours > 24 ){
hours = 0;
seconds = 0;
minutes = 0;
}
}
}
Time ( int seconds ) {
seconds = 0 ;
}
Time ( const Time &t){
*this = t;
}
void set_time( int hrs , int mins , int secs ){
hours = hrs;
minutes = mins;
seconds = secs;
}
int get_hours () {
return hours;
}
int get_minutes () {
return minutes;
}
int get_seconds () {
return seconds;
}
void displayTime (){
cout << "the time in the form hours:minutes:seconds :" << hours << ":" << minutes;
cout << ":" << seconds << endl;
}
Time operator +(const Time & t){
Time time1;
time1.hours = t.hours + this->hours;
time1.minutes = t.minutes + this->minutes;
time1.seconds = t.seconds + this->seconds;
return time1;
}
};
int timeinseconds( int hours, int minutes, int seconds){
int s1=0;
int s2=0;
int s3=0;
s1 = hours * 3600 ;
s2 = minutes * 60 ;
s3 = s1 + s2 + seconds ;
return s3;
}
int main() {
int seconds = 0, minutes = 0, hours = 0, seconds_t = 0;
cout << "enter seconds :" << endl;
cin >> seconds_t;
hours = (seconds_t/3600)%24;
minutes = (seconds_t/60)%60;
seconds = (seconds_t)%60;
cout << " the corresponding time in the form: hours:minutes:seconds is : " << hours;
cout << ":" << minutes << ":" << seconds << endl;
Time t[10];
Time time;
int h=0,m=0,s=0;
cout << "enter the times needed to perform your most important 10 tasks "<<;
cout <<" during the day (hours then minutes then seconds ) : " << endl;
for( int i=0; i<10 ;i++ ){
cin >> h >> m >> s;
if( h <=3 ) {
t[i].set_time(h,m,s);
}
else
return false;
time = time + t[i];
}
time.displayTime();
system( "pause" );
return 0;
}