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
  • Time Displacement (12-hour format) Write a program that requests the current time and a waiting time...

    Time Displacement (12-hour format) Write a program 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 input time and 12-hour notation for the output time. Include a loop that lets the user repeat this calculation for additional input values until the user says she or he wants...

  • C++ PROGRAM Write a program that converts from 24-hour notation to 12-hour notation. For example, it...

    C++ PROGRAM Write a program that converts from 24-hour notation to 12-hour notation. For example, it should convert 14:25 to 2:25 PM. The input is given as two integers. There should be at least three functions, one for input, one to do the conversion, and two for output (one for 12-hour time and another for 24-hour time). Record the AM/PM information as a value of type char, ‘A’ for AM and ‘P’ for PM. Thus, the function for doing the...

  • 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...

  • Write a C++ console application that calculates and displays the charges for multiple customers using a...

    Write a C++ console application that calculates and displays the charges for multiple customers using a parking garage. The parking garage charges a minimum fee of $3.00 to park for up to three hours. The garage charges an additional $0.85 per hour or fraction of an hour for parking over three hours. The maximum charge for any given 24-hour period is $20.00. You may assume that no car parks for longer than 24 hours at a time. Your program will...

  • 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...

  • in C++ Write a program that converts a time in 12-hour format to 24-hour format. The...

    in C++ Write a program that converts a time in 12-hour format to 24-hour format. The program will prompt the user to enter a time in HH:MM:SS AM/PM form. (The time must be entered exactly in this format all on one line.) It will then convert the time to 24 hour form. You may use a string type to read in the entire time at once including the space or you may choose to use separate variables for the hours,...

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