Develop an object-oriented programming (OOP) application to create two clocks simultaneously displaying 12:00 and 24:00 format and...

Free

80.2K

Verified Solution

Question

Programming

Develop an object-oriented programming (OOP) application tocreate two clocks simultaneously displaying 12:00 and 24:00 formatand allow for user input using secure and efficient C++ code. Thankyou!

Answer & Explanation Solved by verified expert
4.4 Ratings (904 Votes)

c++ code for displaying the clock of 12hr and 24 hr formats:

code:

--------------

#include
#include
using namespace std;
int main()
{
int h,minutes,seconds;
char mer[2];
char *s1=\"PM\",*s2=\"AM\";
cout<<\"\nEnter hours:\";
cin>>h;
cout<<\"\nEnter minutes:\";
cin>>minutes;
cout<<\"\nEnter seconds:\";
cin>>seconds;
cout<<\"\nenter meridian:(AM or PM)\";
cin>>mer;
cout<<\"12-hour format the time is:\n\";
cout< cout<<\":\"< if(h<=12 and minutes<=59 and seconds<=59)
{
if(strcmp(mer,s1)==0)
{
h=h+12;
}
else if(strcmp(mer,s2)==0)
{
if(h==12)
h=0;
}
cout<<\"\n24-hour format for the asked time is:\n\";
cout< }
else
cout<<\"\ninvalid\";
return 0;
}
----------------------------------------------

output:

Enter hours:4                                                                                                                                   

                                                                                                                                                

Enter minutes:25                                                                                                                                

                                                                                                                                                

Enter seconds:50                                                                                                                                

                                                                                                                                                

enter meridian:(AM or PM)PM                                                                                                                     

12-hour format the time is:                                                                                                                     

4:25:50PM                                                                                                                                       

24-hour format for the asked time is:                                                                                                           

16:25:50PM

----------------------------------------------

explanation:

here the time is read from the user in hours, minutes ans seconds format including the meridian.

if meridian==PM then add 12 hours to hours if hours!=12.

if meridian ==Am and hours!=0 make hours as usual.

display both the clock times.

--------------------------------

upvote if you like it.

Thankyou.


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students