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

This is a C programming problem. Below is the file lab1exE.c #include <stdio.h>

ID: 3750225 • Letter: T

Question

This is a C programming problem.

Below is the file lab1exE.c

#include <stdio.h>

int is_valid_time(int hour, int min, int sec);
// Returns 1 if the parameters describe a valid time of day
// between 00:00:00 and 23:59:59.
// Returns 0 otherwise.

void call_is_valid_time(int hour, int min, int sec);
// Prints parameters within in a message stating whether
// the parameters make sense together as a time of day.

void describe(int h, int min, int s);
// Assumes that the parameters describe a valid time of day.
// Prints the time and a description of the time using terms
// such as "wee hours", "morning", etc., as describe in the Lab 1
// instructions.

int main(void)
{
call_is_valid_time(-1, 0, 0);
call_is_valid_time(0, -1, 0);
call_is_valid_time(0, 0, -1);

call_is_valid_time(24, 0, 0);
call_is_valid_time(0, 60, 0);
call_is_valid_time(0, 0, 60);

call_is_valid_time(0, 0, 0);
call_is_valid_time(23, 59, 59);

printf(" ");

describe(0, 0, 0);
describe(3, 12, 27);
describe(5, 29, 59);
describe(5, 30, 0);
describe(10, 3, 58);
describe(11, 59, 59);
describe(12, 0, 0);
describe(3, 0, 0);
describe(17, 30, 19);
describe(17, 30, 20);
describe(17, 30, 21);
describe(22, 59, 59);
describe(23, 0, 0);
describe(23, 0, 1);
describe(23, 59, 59);

return 0;
}

int is_valid_time(int hour, int min, int sec)
{
// Obviously, this is often wrong ...
return 1;
}

void call_is_valid_time(int hour, int min, int sec)
{
// Note %02d says "print an int with at least 2 digits,
// and fill with leading zeros if necessary.
printf("%02d:%02d:%02d ", hour, min, sec);
if (is_valid_time(hour, min, sec))
    printf("makes");
else
    printf("does not make");
printf(" sense as a time of day. ");
}

void describe(int h, int min, int s)
{
printf("%02d:%02d:%02d is in the ", h, min, s);

// Obviously, this too is often wrong ...
printf("wee hours. ");
}
.
Answer is better with some explanationsThanks!

Exercise E: Practice with decision-making Read This First With a 24 hour clock, time of day can be specified as a list of three integers such that

Explanation / Answer

#include <stdio.h>

int is_valid_time(int hour, int min, int sec);
// Returns 1 if the parameters describe a valid time of day
// between 00:00:00 and 23:59:59.
// Returns 0 otherwise.

void call_is_valid_time(int hour, int min, int sec);
// Prints parameters within in a message stating whether
// the parameters make sense together as a time of day.

void describe(int h, int min, int s);
// Assumes that the parameters describe a valid time of day.
// Prints the time and a description of the time using terms
// such as "wee hours", "morning", etc., as describe in the Lab 1
// instructions.

int main(void)
{
call_is_valid_time(-1, 0, 0);
call_is_valid_time(0, -1, 0);
call_is_valid_time(0, 0, -1);

call_is_valid_time(24, 0, 0);
call_is_valid_time(0, 60, 0);
call_is_valid_time(0, 0, 60);

call_is_valid_time(0, 0, 0);
call_is_valid_time(25, 59, 59);

printf(" ");

describe(0, 0, 0);
describe(3, 12, 27);
describe(5, 29, 59);
describe(5, 30, 0);
describe(10, 3, 58);
describe(11, 59, 59);
describe(12, 0, 0);
describe(3, 0, 0);
describe(17, 30, 19);
describe(17, 30, 20);
describe(17, 30, 21);
describe(22, 59, 59);
describe(23, 0, 0);
describe(23, 0, 1);
describe(25, 59, 59);

return 0;
}

int is_valid_time(int hour, int min, int sec)
{
if((hour>=0 && hour<24) && (min>=0 && min<60) && (sec>=0 && sec<60))
return 1;
else  
return 0;  
// Obviously, this is often wrong ...
return 1;
}

void call_is_valid_time(int hour, int min, int sec)
{
// Note %02d says "print an int with at least 2 digits,
// and fill with leading zeros if necessary.
printf("%02d:%02d:%02d ", hour, min, sec);
if (is_valid_time(hour, min, sec))
printf("makes");
else
printf("does not make");
printf(" sense as a time of day. ");
}

void describe(int h, int min, int s)
{
printf("%02d:%02d:%02d is in the ", h, min, s);
if (is_valid_time(h,min,s))
{
if((s>=0 && s<60) && (min>=0 && min<30) && (h>=0 && h<6))
{
printf("wee hours. ");

}
else if((s>=0 && s<60) && (min>=30 && min<60) && (h>=5 && h<12))
{
printf("morning. ");
}
else if((s>=0 && s<20) && (min>=0 && min<31) && (h>=12 && h<18))
{
printf("afternoon. ");
}
else if((s>0 && s<60) && (min>=0 && min<60) && (h==23))
{
printf("late night. ");
}
else
printf("evening. ");
}
else
{
printf("Invalid time. ");
  
}
}

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