Question

Time can be expressed in [hours, minutes, seconds]. Create a program in C++ that takes a...

Time can be expressed in [hours, minutes, seconds]. Create a program in C++ that takes a current time and adds an elapsed time to compute the future time. NOTE: hours are expressed using the 24 hours clock. For example, if the current time is 17, 34, 56 and the elapsed time is 9, 48, 17 then the future time is 3, 23, 13.

You should have variables cth, ctm, cts, eth, etm, ets, fth, ftm, fts, representing the current/elapsed/future hours/minutes/seconds.

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

SourceCode:


#include <iostream>

using namespace std;

int main()
{
//Declaring the variables
int cth, ctm, cts, eth, etm, ets, fth, ftm, fts;

//Taking input form the user
cout << "Please enter values for hour,minutes and seconds for current time: " << endl;
cin>>cth;
cin>>ctm;
cin>>cts;

cout << "Please enter values for hour,minutes and seconds for elapsed time: " << endl;
cin>>eth;
cin>>etm;
cin>>ets;
//Computing the future seconds
fts = (cts + ets) % 60;
//Computing the future minutes
ftm = ((ctm + etm) + ((cts + ets) / 60)) % 60;
//Computing the future hours
fth = ((cth + eth)+(((ctm + etm) + ((cts + ets) / 60))/60)) % 24;
//Printing the output
cout<<"Future time in hour,minutes and seconds in respectively are: "<<fth<<","<<ftm<<","<<fts;

return 0;
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Time can be expressed in [hours, minutes, seconds]. Create a program in C++ that takes a...
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
  • Write a C program to converts a number of seconds to days, minutes, hours, and seconds....

    Write a C program to converts a number of seconds to days, minutes, hours, and seconds. Variables days minutes hours seconds Execution sample How many seconds? 234567 Days:      2 Hours:     17 Minutes:   9 Seconds:   27

  • HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the...

    HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the second line of the display, using the HH:MM:SS format. Use the 24-hour format for the hours, in other words, have the time go from 00:00:00 to 23:59:59. #include<LiquidCrystal.h> LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8); int minutes = 27; //These global integers keep the value of the clock int sec = 10; int hr = 10; const long interval = 1000; //This interval is...

  • elise age 20 is a full timwv Remaining Time: 2 hours, 17 minutes, 59 seconds. cts...

    elise age 20 is a full timwv Remaining Time: 2 hours, 17 minutes, 59 seconds. cts Question Completion Status: ents 2 points Save Answer QUESTION 3 Elise, age 20, is a full-time college student with earned income from wages of $4,400 and interest income of $500. Elise's parents provide more than half of her support. Elise's 2019 taxable income is O $500. O $150. free of 118 GB DEO_TS Click Save and Submit to save and submit. Click Save All...

  • Python 3 Here is my question. In clock.py, define class Clock which will perform some simple...

    Python 3 Here is my question. In clock.py, define class Clock which will perform some simple time operations. Write an initializer function for Clock that will take three arguments from the user representing hour (in 24-hour format), minutes, and seconds. Each of these parameters should have a reasonable default value. You should check that the provided values are within the legal bounds for what they represent and raise a ValueError if they are not. if error_condition: raise ValueError("Descriptive error message")...

  • This lab will create a digital clock based on nested FOR loops for hours, minutes, and...

    This lab will create a digital clock based on nested FOR loops for hours, minutes, and seconds, and a WHILE loop for doing over and over so that your clock works for all year long without interruption. Note: If a group of students is interested, we could create a real digital wall-mounted clock to be placed in our classroom, so I can keep track of the time during my lectures. The actual clock would be based on the LED Strip...

  • aining Time: 2 hours, 21 minutes, 49 seconds. astion Completion Status: QUESTION 24 Consider the circuit...

    aining Time: 2 hours, 21 minutes, 49 seconds. astion Completion Status: QUESTION 24 Consider the circuit below and answer the following questions. In this sketch, V=8V, RI-200, R2-300, and R3-4000 ww a) What is the equivalent resistance of the circuit? b) How much current is drawn from the battery? How much power is dissipated by R3? Please write your answers in the space below and email your work TTTT Paragraph Arial - 3120 • E- E - T-... XD09 T'...

  • Q1. Write a C++ class called Time24h that describes a time of the day in hours,...

    Q1. Write a C++ class called Time24h that describes a time of the day in hours, minutes, and seconds. It should contain the following methods: • Three overloaded constructors (one of which must include a seconds value). Each constructor should test that the values passed to the constructor are valid; otherwise, it should set the time to be midnight. A display() method to display the time in the format hh:mm:ss. (Note: the time can be displayed as 17:4:34, i.e. leading...

  • Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment...

    Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment 1 ID: 1. True / False 2. True / False 3. True / False 4. True / False 5. True / False 6. True / False 7. True / False 8. True / False 9. True / False 10. True / False Variable and functions identifiers can only begin with alphabet and digit. Compile time array sizes can be non-constant variables. Compile time array...

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