Question

using C++ Write a full program (starting from #include) that takes as input the number of...

using C++

Write a full program (starting from #include) that takes as input the number of seconds after midnight. It then displays the time in hours:minutes:seconds format. Assume the time is displayed in military time, e.g. 06:06:06 or 23:05:57. Note the placement of the zeros for numbers less than 10, which your program should properly display. Your program should show output as in the example below.

Enter number of seconds after midnight: 3601

0 0
Add a comment Improve this question Transcribed image text
Answer #1

here is the complete C++ program as per the requirement.

========================================================

Program:

========================================================

//header files

#include<iostream>

#include<iomanip>

//namespace std;

using namespace std;

//start of the main function

int main()

{

//variables

int seconds, hours, minutes;

cout<<"Enter the number of seconds after midnight: ";

cin >> seconds;

//find minutes

minutes = seconds / 60;

//find hours

hours = minutes / 60;

//display the hours, minutes, seconds

cout << setfill('0')<<setw(2)<<int(hours) << ":" << setfill('0')<<setw(2)<<int(minutes%60)

     << ":" << setfill('0')<<setw(2)<<int(seconds%60)<<endl;

return 0;

}

//end of the main function


========================================================

Sample Output:

=========================================================

Kindly Check and Verify Thanks..!!!

Add a comment
Know the answer?
Add Answer to:
using C++ Write a full program (starting from #include) that takes as input the number of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (C++) Write a function, remove, that takes three parameters: an array of integers, the number of...

    (C++) Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the user to enter 10 digits...

  • Write a C function called display_dollar which takes a floating point number as input, and displays...

    Write a C function called display_dollar which takes a floating point number as input, and displays this is a dollar value to the screen. This means that it should have a ‘$’ in front of it, and be displayed to exactly two decimal places in non-scientific form. Your function should not put spaces or newlines before or after the output?

  • 10) Write a program that inputs five numbers and determines the number of negative numbers input,...

    10) Write a program that inputs five numbers and determines the number of negative numbers input, the number of positive numbers input and the number of zeros input. An easy way to create a counter is given in the example below: int counter 0; initializes the counter counter counter +1;//increments the counter each time is used. Note: Output should read as shown below where # replaces the number of inputs and it is displayed on a table format] (40 pts.)...

  • Write a java program that uses a loop to input, from the user not using gui,...

    Write a java program that uses a loop to input, from the user not using gui, a collection of values that are the number of steps taken each day for a sequence of days and stores those amounts in an array. the array length should be 31, The user is not required to enter 31 values. the program determines and displays the largest number of steps for a single day, the smallest number of steps for a single day and...

  • Using C++ programming. Write a program that takes a string of input from the user and...

    Using C++ programming. Write a program that takes a string of input from the user and separates the string of words based on the premise that the string contains words whose first letter is uppercase. Then, display the phrase (or sentence) to a string in which the words are separated by spaces and only the first word of the phrase starts with an uppercase letter. For example, if the user enters "IAmTheTeacher", then the program would display: "I am the...

  • C++ Question 6 (10pt): Convert seconds Write a program that takes a number of seconds as...

    C++ Question 6 (10pt): Convert seconds Write a program that takes a number of seconds as user input (as an integer) and converts it to hours, minutes, and seconds as shown below. You should convert the amount of time in such a way that maximizes the whole numbers of hours and minutes. Expected output 1 (bold is user input) Enter a number of seconds: 60 0 hour(s) 1 minute(s) 0 second(s) Expected output 2 (bold is user input) Enter a...

  • Write a menu driven program to demonstrate the use of array and switch. It must be...

    Write a menu driven program to demonstrate the use of array and switch. It must be written in C language . Here is the menu - Press 1 to add a number to the array. Press 2 to display the numbers entered in the array so far Press 3 to find the average of the numbers entered. Press 4 to exit. Option 1 - The user should be able to enter 20 numbers only. If all twenty numbers are entered...

  • 3. Write a program called VibratingSystem that does the following a. Takes the following as input...

    This two problems go together 3. Write a program called VibratingSystem that does the following a. Takes the following as input i. Spring constant, k; ii. Mass under vibration, m; iii. Coefficient of viscous damping, c, iv. Initial position of the mass. xi, v. And initial velocity of the mass. vi b. If the values k or m are less than or equal to zero, ask for those variables again. c. Plot the results for t from 0 to 20...

  • (1) (50%) Write a C program that takes as input a fully parenthesized, arithmetic expression of...

    (1) (50%) Write a C program that takes as input a fully parenthesized, arithmetic expression of binary operators +, -,*,/, and converts the expression into a binary expression tree. Your program should take input from the command line. The entire expression should be in a character string without any space in it An input string only includes floating numbers in the format of Y.YY, that is, one digit to the left of the decimal point and two digits to the...

  • Using your choice of Pseudocode, C# or Java write a program that displays the sum of...

    Using your choice of Pseudocode, C# or Java write a program that displays the sum of all of the even elements in a 3x3 matrix (e.g., a 2D array). If there is no such number in the matrix it will display 0.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT