In: Computer Science
using C program
Assignment
Write a computer program that converts a time provided in hours, minutes, and seconds to seconds
Functional requirements
Nonfunctional requirements
Sample run
4 hours, 13 minutes and 20 seconds is equal to 15200 seconds. 8 hours, 0 minutes and 0 seconds is equal to 28800 seconds. 1 hours, 30 minutes and 0 seconds is equal to 5400 seconds.
Grading
This assignment will be graded according to the programming grading rubric.
Due date
The assignment is due by the 11:59pm on September 20, 2019.
Requested files
time_to_sec.c
/*
* time_to_sec.c
*
* Created on: Jul 20, 2016
* Author: leune
*/
// appropriate #include statements
/* Convert a time interval specified in hours, minutes and seconds to
* seconds.
* Parameters:
* hours, minutes, seconds: input time elements
* Preconditions:
* 0 <= minutes < 60
* 0 <= seconds < 60
* Return:
* number of seconds in the interval
*/
unsigned int time_to_sec(unsigned int hours, unsigned int minutes,
unsigned int seconds) {
// complete this
}
/* Print a formatted representation of the calculation
* Parameters:
* hours, minutes, seconds: input time elements
* Postcondition:
* Function will write the calculation to standard output.
*/
void format_seconds(unsigned int hours, unsigned int minutes,
unsigned int seconds) {
// complete this
}
int main(void) {
format_seconds(4, 13, 20);
format_seconds(8, 0, 0);
format_seconds(1, 30, 0);
}
/*
* time_to_sec.c
*
* Created on: Jul 20, 2016
* Author: leune
*/
// appropriate #include statements
/* Convert a time interval specified in hours, minutes and seconds to
* seconds.
* Parameters:
* hours, minutes, seconds: input time elements
* Preconditions:
* 0 <= minutes < 60
* 0 <= seconds < 60
* Return:
* number of seconds in the interval
*/
#include <stdio.h>
unsigned int time_to_sec(unsigned int hours, unsigned int minutes,
unsigned int seconds) {
return (((hours * 60) + minutes) * 60) + seconds;
}
/* Print a formatted representation of the calculation
* Parameters:
* hours, minutes, seconds: input time elements
* Postcondition:
* Function will write the calculation to standard output.
*/
void format_seconds(unsigned int hours, unsigned int minutes,
unsigned int seconds) {
printf("%u hours, %u minutes and %u seconds is equal to %u seconds.\n", hours, minutes, seconds,
time_to_sec(hours, minutes, seconds));
}
int main(void) {
format_seconds(4, 13, 20);
format_seconds(8, 0, 0);
format_seconds(1, 30, 0);
}
