Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me fix this codes: ....................................... #include #include class time { public: time(void); time(int hrs, int min, int sec); void input_time(); void print_12(); time

Please help me fix this codes:

.......................................

#include

#include

class time

{

public:

time(void);

time(int hrs, int min, int sec);

void input_time();

void print_12();

time operator-(time t);

private:

int hours,minutes,seconds;

};

time::time(void)

{

hours=99;

minutes=99;

seconds=99;

};

time::time(int hrs, int min, int sec)

{

hours=hrs;

minutes=min;

seconds=sec;

}

void time::input_time()

{

printf("Please enter the hour value:");

scanf("%d",hours);

printf("Please enter the minute value:");

scanf("%d",minutes);

printf("Please enter the second value:");

scanf("%d",seconds);

}

void time::print_12()

{

int thours=hours;

bool am=true;

if(hours>12)

{

thours=thours-12;

}

if(hours>=12)

{

am=false;

}

if(thours>9)

{

printf("%d:",thours);

}

else

{

printf("0%d:",thours);

}

if(minutes>9)

{

printf("%d:",minutes);

}

else

{

printf("0%d:",minutes);

}

if(seconds>9)

{

printf("%d:",seconds);

}

else

{

printf("0%d:",seconds);

}

if(am)

{

printf("am");

}

else

{

printf("pm");

}

}

time time::operator-(time t)

{

int t1sec=0, t2sec=0;

int second_difference;

int final_hours, final_minutes;

t1sec=t1sec+seconds;

t1sec=t1sec+(minutes*60);

t1sec=t1sec+(hours*60*60);

t2sec=t2sec+t.seconds;

t2sec=t2sec+(t.minutes*60);

t2sec=t2sec+(t.hours*60*60);

second_difference=abs((t1sec-t2sec));

final_hours=(second_difference/3600);

second_difference=second_difference-(final_hours*3600);

final_minutes=(second_difference/60);

second_difference= second_difference-(final_minutes*60);

time diff(final_hours,final_minutes,second_difference);

return diff;

}

int main(void)

{

time t;

time s;

time t1(12,40,16);

printf("The original time values are: ");

printf("Hours: 12 ");

printf("Minutes: 40 ");

printf("Seconds: 16 ");

printf("Please enter the new time: ");

t.input_time();

printf("New time value in 12 hour format");

t.print_12();

printf("Original time in 12 hour format");

t1.print_12();

s=t.operator-(t1);

printf("The difference between the two times is:");

s.print_12();

return 0;

}

........................................................

problem# 15.

image text in transcribed

this is the error

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Explain what erosion is, and why it is relevant.

Answered: 1 week ago