0% found this document useful (0 votes)
28 views1 page

Using Namespace Class Private Int Public

The document defines a Time class with member variables for hours, minutes and seconds. It includes constructors, setter and getter methods, and a method to increment seconds. The main function demonstrates creating Time objects and arrays, setting and getting values, and incrementing seconds.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

Using Namespace Class Private Int Public

The document defines a Time class with member variables for hours, minutes and seconds. It includes constructors, setter and getter methods, and a method to increment seconds. The main function demonstrates creating Time objects and arrays, setting and getting values, and incrementing seconds.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;


class Time
{
private:
int m_Hours, m_Minutes, m_Seconds;

public:
Time()// конструктор по умолчанию
{
m_Hours=0;
m_Minutes=0;
m_Seconds=0;
}
Time(int hours , int minutes, int seconds)
{
this->m_Hours=hours;
this->m_Minutes=minutes;
this->m_Seconds=seconds;
}
void set(int hr, int mn, int sc)
{
m_Hours = hr;
m_Minutes = mn;
m_Seconds = sc;
}
void plus1()
{
m_Seconds++;
}
void ShowTime()
{
cout<<m_Hours<<" : "<< m_Minutes<<" : "<< m_Seconds<<endl;
}
};

int main(void)
{
setlocale(LC_CTYPE, "Russian");
Time time;
Time obj = Time(11, 59, 58);
time.ShowTime();
obj.ShowTime();
Time* vrem = new Time;
vrem->ShowTime();
Time* vremp = new Time(9, 12, 12);
vremp->ShowTime();
Time* mas = new Time[3];
mas[0] = obj;
mas[1] = *vremp;
mas[2].set(8, 30, 0);
for (int i = 0; i < 3; i++)
{
mas[i].ShowTime();
}
for (int i = 0; i < 3; i++)
{
mas[i].plus1();
mas[i].ShowTime();
}
cout << endl;
system("pause");
return 0;
}

You might also like