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

Implement a solution for problem 3 from the Algorithms 1 assignment. (Do not sub

ID: 3874349 • Letter: I

Question

Implement a solution for problem 3 from the Algorithms 1 assignment. (Do not submit both.) Note the following directions for each of them. Make sure that you use appropriate data type for all variables, include the introductory comments (purpose of the program, input needed, output expected, and processing needed), and follow the posted Assignment Guidelines to the extent of material covered in class so far. Do not put any code in the introductory comments or any arithmetic expressions in cout statements.

If you choose problem 3 (time conversion), the user should be prompted to enter the whole number of seconds. Then you should calculate the whole number of days, hours, minutes, and remaining seconds. Your calculations should use a minimum number of arithmetic operators (no assignment statement should use more than 1 operator). Your output should be similar to the message below except you will have values where the blanks are. If is OK to have 0 as an output value. “______________ seconds corresponds to _________ days, _______________ hours, ________________ minutes and ________________ seconds.”
Make sure that you have included your introductory comments containing the purpose of the program i.e. what problem or task is being solved plus the input needed from user to complete the problem/task, output expected from the program, and the processing needed to get the output from the input. The processing should not include any C++ commands. An example of introductory comments for calculating the volume of a sphere is given below These introductory comments should be at the very beginning of the program before any other code (“# include <iostream>” and “using namespace std;”). Your introductory comments should also include your name and section number.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

/* Name
Section number
Program to calculate the volume of a sphere given the radius and
using the formula volume = 4/3PI(radius)cubed. PI is declared as a
constant with the value of 3.14159
input: Radius of sphere
output: radius and volume of sphere
processing: volume = 4.0/3 PI radius^3
*/

----------------------------------------------------------------------------------------------------------------------------------------------------------------

Problem 3: Create a process to prompt the user to enter the number of seconds and determine the whole number of days, hours, minutes, and seconds corresponding to the entered number of seconds. For example if the number of seconds entered was 183945, then 2 days, 3 hours, 5 minutes and 45 seconds should be displayed. There are 86400 seconds in a day, 3600 seconds in an hour, and 60 seconds in a minute. Consider all values to be whole numbers.

Explanation / Answer

#include<iostream>

int main()

{

using namespace std;

const int hours_in_day = 24;

const int mins_in_hour = 60;

const int secs_in_min = 60;

const int secs_in_day = 86400;

const int secs_in_hour = 3600;

long input_seconds;

cin >> input_seconds;

long seconds = input_seconds % secs_in_min; //seconds

long days = input_seconds / secs_in_day; //days

long x = input_seconds % secs_in_day; //remaining seconds after days are removed

long y = input_seconds % secs_in_hour; //remaining seconds after hours are removed

long hours = x / secs_in_hour; //hours

long mins = y / secs_in_min; //minutes

cout << input_seconds << " seconds corresponds to "<< days <<" days, "<< hours << " hours, "<< mins <<

" minutes and " << seconds << " seconds";

return 0;

}

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