Question

In: Computer Science

using C program Assignment Write a computer program that converts a time provided in hours, minutes,...

using C program

Assignment

Write a computer program that converts a time provided in hours, minutes, and seconds to seconds

Functional requirements

  1. Input MUST be specified in hours, minutes, and seconds
  2. MUST produce the same output as listed below in the sample run
  3. MUST correctly compute times

Nonfunctional requirements

  1. MUST adhere to program template include below
  2. MUST compile without warnings and errors
  3. MUST follow the code template provided in this assignment
  4. MUST NOT change " int main() " function
  5. MUST only edit sections marked by " // complete this "

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);

}

Solutions

Expert Solution

/*
* 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("%d hours, %d minutes and %d seconds is equal to %d 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);
}


Related Solutions

Write a program that accepts a number of minutes and converts it both to hours and...
Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100.0 hours or 4.166666666666667 days. (I currently have what is below) import java.util.Scanner; public class MinutesConversion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numOfMinutes = sc.nextInt(); double hour = numOfMinutes/60.00; double days = (hour/24); System.out.println(numOfMinutes + " minutes is " + hour + " hours or " + days + " days.");...
Write a program that accepts a number of minutes and converts it to days and hours....
Write a program that accepts a number of minutes and converts it to days and hours. For example, 6000 minutes represents 4 days and 4 hours. Be sure to provide proper exception handling for non-numeric values and for negative values. Save the file as  MinuteConversionWithExceptionHandling.java
PART A Write a program that converts a total number of seconds to hours, minutes, and...
PART A Write a program that converts a total number of seconds to hours, minutes, and seconds. It should do the following: Prompt the user for input Read an integer from the keyboard Calculate the result Use printf to display the output Your output must be of the format: totalSeconds seconds = numHours hours, numMinutes minutes, and numSeconds seconds For example: If the user entered: 5000 Your program would output: 5000 seconds = 1 hours, 23 minutes, and 20 seconds...
Write a program that request a time interval in seconds and display it in hours, minutes,...
Write a program that request a time interval in seconds and display it in hours, minutes, second format. (java)
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write and implement an interactive C++ program to find...
For this computer assignment, you are to write and implement an interactive C++ program to find and print all prime numbers, which are less than or equal to a given value of n, using the algorithm known as the Sieve of Eratosthenes. A prime number p is an integer greater than 1 that is divisible only by 1 and p (itself). The algorithm begins by initializing a set container to contain all the integers in the range 2 to n....
Write a C++ code that can convert time into hours, minutes, seconds. It can accept (seconds),...
Write a C++ code that can convert time into hours, minutes, seconds. It can accept (seconds), (minutes, seconds), (hours, minutes, seconds) The input can be written in main It should produce the following output: (67.4, 14, 5) is 67 Hours, 38 Minutes, 5 Seconds (127.86) is 0 Hours, 2 Minutes, 8 Seconds (-3, 73, 2) is -1 Hours, -46 Minutes, -58 Seconds
Write a C++ program that converts an infix expression, which includes (, ), +, -, *,...
Write a C++ program that converts an infix expression, which includes (, ), +, -, *, and / operations to postfix notation. The program should allow the user to enter an infix expression using lower case characters, then it will display the result of conversion on the screen. (Note: Use the STL stack class to accomplish the solution.).
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program...
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into BMI is as follows: BMI = Weight *...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT