Answer to Question #172257 in C++ for samra

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.


1
Expert's answer
2021-03-16T16:25:28-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS