Another Time question

Our last chapter is covering Classes. The assignment is to design, implement, and test a class that represents an amount of time in only minutes and seconds (no hours, which is kinda wierd). There are several things that we are required to display in this program- see comments.

For some reason, I am getting errors on lines 110, 142, and 152 for my void functions, and I have no idea why because I was going by an example in the textbook.

I havent ran this yet because of those errors, so I dont even know if it will run at all- I need to understand and get past the errors before I go any further.

Here's what Ive got so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  #include <iostream>
#include <string>

using namespace std;

//Class that represents an amount of time in minutes and seconds
class Time
{
public:
	//Default Constructor that creates an object for a time of zero mins/secs
    Time(); 
	//Constructor that sets time to a specified number of minutes and seconds
    Time(int,int); 
	//Observers that return minutes and seconds separately
  	int GetMinutes() const;
	int GetSeconds() const;
	//Observer that returns a total time in seconds
	int GetTotalTime() const;
	//Write a zero for time values less than 10
    void Write();
	//Boolean comparison observers that test two times for equality, greater than or less than qualities
	bool Equal(Time time1, Time time2) const;
	bool LessThan(Time time1,Time time2) const;
	bool GreaterThan(Time time1, Time time2) const;
    //Functions that add and subtract one time from another
	void sumTimes();
	void differenceTimes();


private:
    int minutes, seconds, totalTime;
};

int main()
{
	Time time1;
	Time time2;
	//Get data for time1
   	cout << "Enter two times in minutes and seconds format.  Example 30 25" << endl;
    cout << "Enter first time" << endl;
	time1.GetMinutes();
	time1.GetSeconds();
	cout << endl;
	cout << "Time 1:  ";
	time1.Write();
	//Get data for time2
    cout << "Enter second time:" << endl;
	time2.GetMinutes();
	time2.GetSeconds();
	cout << endl;
	cout << "Time 2:  ";
	time2.Write();
	//Determine if times are equal, less than or greater than one another
	if (time1.Equal(time2))
		cout << "The times are Equal" << endl;
	if (time1.LessThan(time2))
		cout << "Time 1 is less than Time 2" << endl;
	if (time2.LessThan(time1))
		cout << "Time 2 is less than Time 1" << endl;
	if (time1.GreaterThan(time2))
		cout << "Time 1 is greater than Time 2" << endl;
	if (time2.GreaterThan(time1))
		cout << "Time 2 is greater than Time 1" << endl;
	//Display Time in total seconds
	cout << "Time 1 total in seconds is:  " << time1.GetTotalTime;
	cout << "Time 2 total in seconds is:  " << time2.GetTotalTime;
	//Display total of time1 and time2
    Time sumTimes; 
	//Display difference between time1 and time2
    Time differenceTimes;

	//End Program
    cin.get();
	cin.get();
	return 0;
}

//Function Descriptions
Time::Time()
{
	minutes = 0;
	seconds = 0;
}

Time::Time(int initMinutes, int initSeconds)
{
	minutes = initMinutes;
	seconds = initSeconds;
	
}


int Time::GetMinutes() const
{
	return minutes;
}

int Time::GetSeconds() const
{
	return seconds;
}

int Time::GetTotalTime() const
{
	totalTime == (minutes * 60) + seconds;
	return totalTime;
}


void Time::Write() const  //Why is this declaration "incompatible"?
{
	if (minutes < 10) 
		cout << '0';
	cout << minutes << ':';
	if (seconds < 10) 
		cout << '0';
	cout << seconds << ':';
}

bool Time::Equal(Time time1, Time time2) const
{
	return (time1.minutes == time2.minutes
		&& time1.seconds == time2.seconds);
}

bool Time::LessThan(Time time1, Time time2) const
{
	return (time1.minutes < time2.minutes || minutes == time2.minutes
		&& time1.seconds < time2.seconds || minutes == time2.minutes
		&& time1.seconds == time2.seconds
		&& time1.seconds < time2.seconds);
}

bool Time::GreaterThan(Time time1, Time time2) const
{
	return (time1.minutes > time2.minutes || minutes == time2.minutes
		&& time1.seconds > time2.seconds || minutes == time2.minutes
		&& time1.seconds == time2.seconds
		&& time1.seconds > time2.seconds);
}

void Time::sumTimes(Time time1, Time time2)//Same here: Why is this declaration "incompatible"?
{
	int sum;

	sum = time1 + time2;

	cout << "The sum of times is:  " << sum << endl;

	return;
}
void Time::differenceTimes(Time time1, Time time2) // and here
{
	int difference;
	if (time1 < time2)
	difference = time1 - time2;
	cout << "The difference between the two times is:  " << difference << endl;
	else 
		cout << "The time difference is 00:00"; //Cannot allow negative numbers

	return;
}
1
2
3
4
Definition in code
void Time::Write() const 
void Time::sumTimes(Time time1, Time time2)
void Time::differenceTimes(Time time1, Time time2) 
Class declaration
void Write(); //Add const here
void sumTimes(); //Declared as aren't taking any paremeters
void differenceTimes(); //Same here
Thanks! That seemed to take care of the Write function, but Im still getting errors for the sumTimes and differenceTimes void functions.

Also, now I am getting errors for the bool functions: Too few arguments in function call?
Topic archived. No new replies allowed.