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.

C program to print character array, Program to print character array : ...

Program to print character array : Write a program to print the character array by using string class functions. void main() {  char line[30];   int i=0;   clrsc

Develop a c program for linux, develop a C program for Linux called pipes.c...

develop a C program for Linux called pipes.c that does the following: In the main() function, it creates a pipe using the pipe() function, then creates two child processes with

Flight Departure in C, I really have a hard time analyzing how to write a c...

I really have a hard time analyzing how to write a code in C. It''s all bout Time Departure and we must used a 24 hour clock. Can u help me?

Program to find a greatest string: c - program , Program to find a Greatest...

Program to find a Greatest String: C - Program: Write a program find largest string by c program. int main( int argc, char *argv[] ) {     if( argc         {

Why can''t one open a file in a different directory , Why can't one open a ...

Why can't one open a file in a different directory like "..\test.dat"? A: Since " " is a tab character. You must employ forward slashes in your filenames, even on operating s

Assignment problem, how to write c code to solve assignment problem?

how to write c code to solve assignment problem?

What is the significance of external declaration, Problem 1 What is the...

Problem 1 What is the difference between function declaration and function definition? 2 Write a recursive function to find sum of even numbers from 2 to 10. 3 List some

Project, Project Overview A certain financial institution (bank) wishes to ...

Project Overview A certain financial institution (bank) wishes to promote its new business products/services by conducting road shows in rural areas. Their aim is to encourage peop

Msp, A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of 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