Question #172257

Determine the logic to complete C++ program with the following features.

a. Declare a class Time with three fields hour, minute and second

b. Provide appropriate constructors to initialize the data members.

c. Provide separate get() an set()methods for each of the data

members.


Expert's answer

#include <iostream>


using namespace std;


class Time
{
    int hour, minute, second;
    public:
        //constructor
        Time() : hour{ 0 }, minute{ 5 }, second{ 10 }
        {


        }


        //Setter methods
        void setHour(int h)
        {
            hour = h;
        }
        void minuteSetter(int m)
        {
            minute = m;
        }
        void secondSetter(int s)
        {
            second = s;
        }


        //Getter methods
        int hourGetter()
        {
            return hour;
        }
        int minuteGetter()
        {
            return minute;
        }
        int secondGetter()
        {
            return second;
        }


        //Output
        void print()
        {
            cout<<"The time is "<<hour <<":"<<minute <<":"<<second<<endl;
        }

};


int main()
{
    Time t{};
    t.print();
    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!

LATEST TUTORIALS
APPROVED BY CLIENTS