Question

In: Computer Science

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

Develop an object-oriented programming (OOP) application to create two clocks simultaneously displaying 12:00 and 24:00 format and allow for user input using secure and efficient C++ code. Thank you!

Solutions

Expert Solution

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

code:

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

#include <iostream>
#include<string.h>
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<<h;
cout<<":"<<minutes<<":"<<seconds<<mer;
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<<h<<":"<<minutes<<":"<<seconds<<mer;
}
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.


Related Solutions

(a) Explain at least TWO (2) major aspects of an object-oriented programming (OOP). Provide suitable examples,
(a) Explain at least TWO (2) major aspects of an object-oriented programming (OOP). Provide suitable examples,
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with...
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with its example/description. Question 2 options: 12345678 Providing a way for an entity to behave in several ways OR providing multiple entities to be treated in a similar way 12345678 A key way of saving having to retype a lot of code for similar but different objects 12345678 The removal of non-essential information 12345678 Allowing which function to be called by an object to be...
object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaida
This week, you will create and implement an object-oriented programming design for your project. You will...
This week, you will create and implement an object-oriented programming design for your project. You will learn to identify and describe the classes, their attributes and operations, as well as the relations between the classes. Create class diagrams using Visual Studio. Review the How to: Add class diagrams to projects (Links to an external site.) page from Microsoft’s website; it will tell you how to install it. Submit a screen shot from Visual Studio with your explanation into a Word...
*OBJECT ORIENTED PROGRAMMING* GOAL: will be able to throw and catch exceptions and create multi-threaded programs....
*OBJECT ORIENTED PROGRAMMING* GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts a false....
Research and explain in your words what is known as Object Oriented Programming. Then, identify two...
Research and explain in your words what is known as Object Oriented Programming. Then, identify two advantages of OOP for application development. In peer replies, choose from one of the following and define the concept as part of your response. Abstraction. Encapsulation. Inheritance. Polymorphism.
Write a Windows Form application named SumFiveInts. Microsoft Visual C#: An Introduction to Object-Oriented Programming,7th Edition....
Write a Windows Form application named SumFiveInts. Microsoft Visual C#: An Introduction to Object-Oriented Programming,7th Edition. Ch. 5, page 220. Take snip of program results.
Practice object-oriented principles by making two Peanut Butter and Jelly Sandwiches. The program must create two...
Practice object-oriented principles by making two Peanut Butter and Jelly Sandwiches. The program must create two sandwiches based on user input. The sandwich information for both must then print out their details and determine if the two sandwiches are equal. Requirements:   Write a class called Bread with the following Instance Variables Name: The name brand of the bread. o   Calories: The number of calories per slice assumed to be between 50 and 250 inclusively. Type: The kind of bread. This can...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT