Class function

#include <iostream>
#include <ctime>
using namespace std;



class Time
{
public:
	int hour;
	int minute;
	int second;
	int time;

	Time()
	{
		time = time(0);
	}

	Time(int newTime)
	{
		time = newTime;
	}

	int getHour()
	{
		int totalSeconds = time(0);
		int currentSecond = totalSeconds % 60;
		int totalMinutes = totalSeconds / 60;
		int currentMinute = totalMinutes % 60;
		int totalHours = totalMinutes / 60;
		return totalHours;
	}

	int getMinute()
	{
		 int totalSeconds = time(0);
		 int currentSecond = totalSeconds % 60;
		 int totalMinutes = totalSeconds / 60;
		 int currentMinute = totalMinutes % 60;
		 return currentMinute;
	}

	 int getSecond()
	{
		int totalSeconds = time(0);
		int currentSecond = totalSeconds % 60;
		return currentSecond;
	}

};

int main()
{
  Time time;
  cout << time.getHour() << ":" << time.getMinute() << ":" << time.getSecond() << endl;

  Time time1(555550);
  cout << time1.getHour() << ":" << time1.getMinute() << ":" << time1.getSecond() << endl;

  return 0;
}



Ok so i have that so far.

The purpose of this code is to display the current time, and display the time if the seconds were 555550. The result should be something like:

Current Time is hh/mm/ss

Current Time for 555550 seconds is 10 hours, 19 minutes, 9 seconds.

I don't know where to go from here.
Last edited on
In the constructor:
time = time(0); You have time function from ctime and time member of your class.
Put std:: before the function time so the compiler can know which one it is

In other functions:
int totalSeconds = time(0); You should have the member time here, remove (0)
Topic archived. No new replies allowed.