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.

Luminous Jewels - The Polishing Game, plaese tell the full program for the ...

plaese tell the full program for the above given topic with the input and output

C program for string address, C Program for STRING ADDRESS #include std...

C Program for STRING ADDRESS #include stdio.h> #include conio.h> #include string.h> void main() {           char *name;           int length;           cha

Basics, conceptual difference between big o,big thete and big omega

conceptual difference between big o,big thete and big omega

Functions, Define  F u n c t i o n?  T h e r e a r e t...

Define  F u n c t i o n?  T h e r e a r e t w o t y p e s o f f u n ct i o n b u i l t - i n f un ct i o n s a n d u

Source code, processing two jobs through 2 machine

processing two jobs through 2 machine

Described c++ storage classes?, A: auto: the default. Variables are created...

A: auto: the default. Variables are created and initialized automatically while they are defined and destroyed at the ending of the block containing their definition. They are not

Define the bitwise operators in c language, Define the Bitwise Operators in...

Define the Bitwise Operators in c language? C has distinction of supporting special operators that known as bit wise operators for manipulation of data at bit level. These oper

Calculate the area and circumference of a circle , Write a program which in...

Write a program which incorporates a function named compute and which is used to calculate the area and circumference of a circle. Use the main function for inputs and outputs.

Procedure to compute recursive and iterative process, Consider the followin...

Consider the following mathematical function: (a) Write a procedure that computes f by means of a recursive process (b) Write a procedure that computes f by means of an

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