Answer to Question #185680 in C++ for VARUN

Question #185680

Declare the class Time consisting of data members hours, minutes and seconds. Invoke a null constructor Time() when an object is created, the parameterized constructor Time(hrs, min, sec) to assign values for the data members and show() member function is used to display the time information in format. Finally free the resources of data objects using destructor member function

RUNTIME INPUT

12

59

45

Output should be

12:59:45


1
Expert's answer
2021-04-26T07:29:39-0400
#include <iostream>
using namespace std;
class Time{
    int hours, minutes, seconds;
    public:
    Time(){}
    Time(int hrs, int min, int sec){
        hours = hrs;
        minutes = min;
        seconds = sec;
    }
    void show(){
        cout<<this->hours<<":"<<this->minutes<<":"<<this->seconds<<endl;
    }
    ~Time(){
    }
};
int main(){
    int h, m, s;
    cout<<"Enter runtime input\n";
    cin>>h;
    cin>>m;
    cin>>s;
    Time time(h, m, s);
    cout<<"\noutput\n";
    time.show();
    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