aim to implement a program to convert time in 24


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

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: aim to implement a program to convert time in 24
Reference No:- TGS0162069

Expected delivery within 24 Hours