Question

Write a program (C++) that requests the current time and a waiting time as two integers...

Write a program (C++) that requests the current time and a waiting time as two integers for the number of hours and the number of minutes to wait. The program then outputs what the time will be after the waiting period. Use 24-hour notation for the times. Include a loop that lets the user repeat this calculation for additional input values until the user says she or he wants to end the program.You can assume the wait time will always be less than 24 hours. You must meet the following requirements as well:

Your program must have three functions:

  1. One to get the current time and the wait time using four reference parameters.
  2. One to calculate the time after the wait time. This function will have six parameters:
    1. The current hour
    2. The current minutes
    3. The wait time hours
    4. The wait time minutes
    5. The finish time hours (reference parameter)
    6. The finish time minutes (reference parameter)
  3. A function to output the finish time in 24-hour time notation with a colon in between the hours and the minutes and a zero before the minutes if the minutes are less than 10.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below::::

#include<iostream>
using namespace std;

void getTime(int & currHour,int & currMin, int & waitHour, int & waitMin){
   cout<<"Enter current hours : ";
   cin>>currHour;
   cout<<"Enter current minutes : ";
   cin>>currMin;
   cout<<"Enter wait hours : ";
   cin>>waitHour;
   cout<<"Enter wait minutes : ";
   cin>>waitMin;
}

void calculateTime(int & currHour,int & currMin, int & waitHour, int & waitMin,int & finishHour,int & finishMin){
   finishHour = currHour + waitHour;
   finishMin = currMin + waitMin;
   //if minute is greater than 60 increase hour
   finishHour += finishMin/60;
   finishMin /= 60;
}

void printTime(int & finishHour,int & finishMin){
   if(finishHour<10){
       cout<<"0"<<finishHour;
   }else{
       cout<<finishHour;
   }
   cout<<":";
   if(finishMin<10){
       cout<<"0"<<finishMin;
   }else{
       cout<<finishMin;
   }
}
int main()
{
   int currHour,currTime,waitHour,waitMin,finishHour,finishMin;
   getTime(currHour,currTime,waitHour,waitMin);
   calculateTime(currHour,currTime,waitHour,waitMin,finishHour,finishMin);
   cout<<"Finish time is ----> ";
   printTime(finishHour,finishMin);
   return 0;
}

output:

Add a comment
Know the answer?
Add Answer to:
Write a program (C++) that requests the current time and a waiting time as two integers...
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
  • Create the Code using C Program: 2. Write a program to convert the time from 24-hour...

    Create the Code using C Program: 2. Write a program to convert the time from 24-hour notation to 12-hour notation and vice-versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following function: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the...

  • 1 Write a program to convert the time from 24-hour notation to 12-hour notation and vice...

    1 Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following functions: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the...

  • Need some assistance of reorganizing this whole program. I have the right code for everything I...

    Need some assistance of reorganizing this whole program. I have the right code for everything I just need help on putting all the codes in the right spot so it can come out to the correct output. output is supposed to look like this: 1 \\ user inputs choice to convert 12 to 24 8 \\ user inputs 8 for hours 30 \\ user inputs 30 for minutes 20 \\ user inputs 20 for seconds AM \\ user inputs AM...

  • Write and submit a MIPS Assembly Language program which requests an integer (year) from the user...

    Write and submit a MIPS Assembly Language program which requests an integer (year) from the user and then invokes a function to determine the beginning date and time of each season. The program must be properly documented which includes in file comments. Note: This is a Computer Science/Engineering course, not a Physics/Astronomy course. The exact time is not expected. Approximations are acceptable. Document your calculation process in the report. Basically, the intent is that you store a reference date and...

  • Write a C program as follows: Single source code file Requests the user to input two...

    Write a C program as follows: Single source code file Requests the user to input two integer numbers Requests the user to make a choice between 0 (add), 1 (subtract), or 2 (multiply) Declares three separate functions Uses a pointer to these three functions to perform the requested action Outputs the result to the screen Submit your program source code file to this assignment. Sample Output Enter first integer number: 15 Enter second integer number: 10 Enter Choice: 0 for...

  • 12. 13. Write a program that prompts the capacity, in gallons, of an automobile fuel tank...

    12. 13. Write a program that prompts the capacity, in gallons, of an automobile fuel tank and the miles per gallon the automobile can be driven. The program outputs the number of miles the automobile can be driven without refueling Write a C++ program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (For example, if the elapsed time is 9630 seconds, then...

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • 8. (15 marks) Write a complete C program, which uses an array of structures and two...

    8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10...

  • Can someone solve it with C plz Write a program that inputs a time from the...

    Can someone solve it with C plz Write a program that inputs a time from the console. The time should be in the format “HH:MM AM” or “HH:MM PM”. Hours may be one or two digits, for example, “1:10 AM” or “11:30 PM”. Your program should include a function that takes a string parameter containing the time. This function should convert the time into a four digit military time based on a 24 hour clock. For example, “1:10 AM” would...

  • HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number...

    HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number of seconds. This number should be less than or equal to 32767 because that is the largest number pep8 can handle. Your program should then output the number of hours, minutes, and seconds on the planet of Crypton, where there are 64 seconds in a minute and 32 minutes in an hour.

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
ADVERTISEMENT