Question

v +include <iostreams 2 #include <string> Instructions 3 Write a program to convert the time from 24-hour notation to 12-hourv Instructions Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program musv Instructions Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program musv Instructions } Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program mNeed 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 for morning time

8:30:20 \\ then program displays the time converted

99 \\ user inputs 99 to exit the program

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

Note: For any issues or doubts, just put a comment before giving a thumbs down. Thanks.

COde( There were many faults in the logic so I fixed them ):

#include <iostream>
#include <string>

using namespace std;

void DisplayChoices();
void getTime12Format();
void getTime24Format();
void ConversionFrom12to24(int minutes, int hours, int seconds, string AMorPM);
void ConversionFrom24to12(int minutes, int hours, int seconds);
void Display12to24(int minutes, int hours, int seconds);
void Display24to12(int minutes, int hours, int seconds, string AMorPM);

int main(){

int input;
DisplayChoices();
cin>> input;


switch (input)
{
case 1:
getTime12Format();
break;

case 2:
getTime24Format();
break;
  
case 99:
exit(0);
  
default:
cout<<"Invalid Option!!";
break;
}

return 0;
}

void DisplayChoices(){
cout<< "press 1 to convert from 12-hour to 24-hour notation or"<<endl;
cout<< "press 2 to convert from 24-hour to 12-hour notation"<<endl;
cout<< "Enter 99 to exit the program"<<endl;
}

void getTime12Format(){
int hours;
cout<< "Time in hours: ";
cin>> hours;

int minutes;
cout<< "Time in minutes: ";
cin>> minutes;

int seconds;
cout<< "Time in seconds: ";
cin>> seconds;

string AMorPM;
cout<< "AM or PM: ";
cin>>AMorPM;
ConversionFrom12to24(minutes, hours, seconds, AMorPM);
}

void getTime24Format(){
int hours;
cout<< "Time in hours: ";
cin>> hours;

int minutes;
cout<< "Time in minutes: ";
cin>> minutes;

int seconds;
cout<< "Time in seconds: ";
cin>> seconds;
ConversionFrom24to12(minutes, hours, seconds);
}

void ConversionFrom24to12(int minutes, int hours, int seconds){
string AMorPM = "";

if(hours>12){
AMorPM = "PM";
hours = hours%12;
}
else
{
AMorPM = "AM";
hours = hours;
}
  

Display24to12(minutes, hours, seconds, AMorPM);
}

void ConversionFrom12to24(int minutes, int hours, int seconds, string AmorPm){

if(AmorPm == "PM"){
hours = hours + 12;
}
else
{
hours = hours;
}
  
Display12to24(minutes, hours, seconds);
}

void Display12to24(int minutes, int hours, int seconds){
char zero = ' ';
char hour_zero = ' ';
  
if(hours < 10){
hour_zero = '0';
}
if(minutes < 10)
{
zero = '0';
}
  
cout<<"Time: "<<hour_zero<<hours<<":"<<zero<<minutes<<":"<<seconds<<endl;

}

void Display24to12(int minutes, int hours, int seconds, string AMorPM){
char zero = ' ';

if(minutes<10){
zero = '0';
}

cout<<"Time: "<<hours<<":"<<zero<<minutes<<":"<<seconds<<AMorPM<<endl;
}

Add a comment
Know the answer?
Add Answer to:
Need some assistance of reorganizing this whole program. I have the right code for everything I...
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...

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

  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...

    Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c)...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • I need help implementing 3 function prototypes with using operator overloading in a class. I have...

    I need help implementing 3 function prototypes with using operator overloading in a class. I have bolded the section I need help with since the cpp file is bigger than I expected. Any comments throughout would be extremely helpful. Time.cpp file #include "Time.h" #include #include #include // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for...

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

  • For this project you will be writing up a simple Clock program to keep track of...

    For this project you will be writing up a simple Clock program to keep track of time. SimpleClock.java - contains your implementation of the SimpleClock class. You will need to provide the code for a constructor as well as the mutator methods set and tick and the accessor method toString. Look at the comments for each method to see how they should be implemented - the trickiest method is probably tick, which requires that you deal with the changing of...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

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