C program to convert time in 24 hour format to 12., C/C++ Programming

Assignment Help:

Aim: To implement a program to convert time in 24 hour format to 12 hour format.

Code:                      

#include

#include

#include

class time24

{

            public:

            int hhhh;

            void  displaytime24()

            {

                        cout<<"\nTime(24):"<

            }

            void gettime24()

            {

                        cout<<"\nEnter time in 24 hour format:";

                        cin>>hhhh;

            }

 

};

 

class time12

{

            public:

            int hh,mm;

            char ap[3];

            time12(time24 t2)

            {

                        if((t2.hhhh/100)>=12)

                        {

                                    if(((t2.hhhh/100)%12)==0)

                                    {

                                                hh=12;

                                    }

                                    else

                                    {

                                                hh=(t2.hhhh-1200)/100;

                                    }

                                    strcpy(ap,"pm");

                        }

                        else

                        {

                                    hh=(t2.hhhh/100);

                                    strcpy(ap,"am");

                        }

                        mm=(t2.hhhh%100);

            }

            void displaytime12()

            {

                        cout<<"\nTime(12):";

                        if(hh<10)

                                    cout<<"0";

                        cout<

                        if(mm<10)

                                    cout<<"0";

                        cout<

            }

};

 

void main()

{

            clrscr();

            time24 t1;

            t1.gettime24();

            time12 t2=t1;

            t1.displaytime24();

            t2.displaytime12();

            getch();

}

Output:

Enter time in 24 hour format:1830

Time(24):1830 hours

Time(12):06:30 pm


Related Discussions:- C program to convert time in 24 hour format to 12.

Explain the type conversion in expressions in c language, Explain The Type ...

Explain The Type Conversion in Expressions in c language? When variables and constants of different types are used in an expression they are all converted to same type. The com

Coding, Problem Statement: You have to write a C program to develop a Car P...

Problem Statement: You have to write a C program to develop a Car Parking Management System for a busy commercial area. The system will record the car plate number, date and time w

Type cast operator, What is  T y pe C a s t Op er a t o r :...

What is  T y pe C a s t Op er a t o r :   T h e f l o a t c a n b e c o n v e r t e d t o i n t e g e r v a l u

Explain in brief about the one-definition rule, Explain one-definition rule...

Explain one-definition rule (ODR). According to one-definition rule, C++ constructs should be identically defined in each compilation unit they are used in. As per ODR, two

What does it mean to declare a destructor as static, d) a "static destructo...

d) a "static destructor" is a static member function of the class which accepts one argument - a pointer to the object of that class to be cracked. It is probably utilized along wi

#superASC2 SRTING COST, A string S is said to be "Super ASCII", if it conta...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Game coding, polishing the jewel game with c coding

polishing the jewel game with c coding

Create an array of strings, Create an array of Strings and fill it with som...

Create an array of Strings and fill it with some interesting text, such as vacation destinations, album names, or weapon names from a CRPG. Display three elements of the array on t

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd