Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a) Write a structure called Time which has three int fields: hrs, mins, secs. b)

ID: 3662883 • Letter: A

Question

a) Write a structure called Time which has three int fields: hrs, mins, secs.

b) Write a function called Display() which prints the time in form "hh/mm/ss"

c) In main declare a Time structure as follows: Time tm1={4, 63, 70}; which initializes to 4:63:70

d) We need to fix up this time. Write a function with prototype: void Normalize(Time* tm1) This function changes the time so secs < 60, and mins < 60 After calling this function, call Display again. The output should be something like: time is 04:63:70 Normalized..time is 05:04:10 Try format specifier %02d for output of seconds, minutes and hours. Call the program Time.CPP

Explanation / Answer

#include<iostream.h>
class Time
{
private:
int hr;
int min;
int sec;

public:
Time(int,int,int);
void get();
void show();

void normalize();
};

int main()
{
Time t1(4,61,70);   
t1.get();

t1.normalize();
t1.show();
system("pause");
}

Time::Time(int h,int m,int s)

{
hr=h;
min=m;
sec=s;
}

void Time::get()
{
cout<<" Enter hrs:";
cin>>hr;
cout<<"Enter min:";
cin>>min;
cout<<"Enter sec:";
cin>>sec;
}

void Time::show()
{
cout<<"Time is "<<hr<<":"<<min<<":"<<sec<<endl;
}

void Time::normalize()
{
int s = seconds;
int m = minutes;
int h = hours;

while(s < 0)
{
s += 60;
m--;
}

while(m < 0)
{
m += 60;
h--;
}

while(h < 0)
{
h = h + 24;
}

seconds = s % 60;
minutes = (m + s/60) % 60;
hours = (h + m/60 + s/3600) % 24;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote