Answer to Question #238690 in C++ for Ali khan

Question #238690
Create a class named time, the data members are hours, minutes and seconds. Write a
function to read the data members supplied by the user, write a function to display the
data members in standard (24) hour and also in (12) hour format
1
Expert's answer
2021-09-17T17:06:03-0400
#include <iostream>


using namespace std;


class Time{
    private:
        int hours, minutes, seconds; 
    public:
        void readData(){
            cout<<"\nEnter hours: ";
            cin>>hours;
            cout<<"\nEnter minutes: ";
            cin>>minutes;
            cout<<"\nEnter seconds: ";
            cin>>seconds;
        }
        void display(){
            if (hours>12){
                cout<<"\nTime in 12 hour format:\n";
                hours=hours-12;
                cout<<"\n"<<hours<<":"<<minutes<<":"<<seconds;
            }
            
            cout<<"\nTime in 12 hour format:\n";
            cout<<"\n"<<hours<<":"<<minutes<<":"<<seconds;
            
            
        }
};


int main()
{
    Time t;
    t.readData();
    t.display();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS