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

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

Posted Date: 9/29/2012 4:06:57 AM | Location : United States







Related Discussions:- C program to convert time in 24 hour format to 12., Assignment Help, Ask Question on C program to convert time in 24 hour format to 12., Get Answer, Expert's Help, C program to convert time in 24 hour format to 12. Discussions

Write discussion on C program to convert time in 24 hour format to 12.
Your posts are moderated
Related Questions
Write a function that takes in a number n and divides the screen into n vertical bars, alternating black and white. (What should you do if someone puts in n=0 or n=-99?)

when you allocate memory with new[], you ought to free the memory via delete[]. While you allocate memory along 'new', then use 'delete' with no the brackets. You employ new[] to a

How would I use variables of a C++ object within a Lua function, and then call the Lua function from C++ code?


Give practice in writing program''s..

Ravi is a newbie to the programming and while learning the programming language he came to know the following rules:

Use the program called harris-shell.c and add some code to find the corners in the image checkers.jpg. You should say that a pixel in the image is a corner if it passes the given t

Call by Reference Passing variables(parameters) to a function in C can be done in two ways - pass by value, also called as call by value and pass by address or also known as ca

Dereferencing the Pointer this Sometimes a member function requires to make a copy of the invoking instance so that it can change the copy without affecting the original instan

What is the difference between early binding and late binding? What are advantages of early binding? a.) Late binding refers to function calls which aren't resolved until run t