Diary Agenda using SLL

hey, well my problem is that i'm required to make a diary agenda for a class. The agenda must be able to Add, Remove, Modify, View all the activities and can also store more than one activity in the same hour.

My problem is that i've got no idea on how to make the hour thing work. I mean, i don't know what function should I do in order to prompt the user to select the hour the activity has to be putted on.

I don't know if i can post my code here, but if anyone can help me, i'll send the code in order to see if you can help me. I believe it's almost done, i just need that little help there.

Thanx in advance
You certainly can post code and will generaly get better answers if you do - please use the # format button (on the right of the box when posting) and stick your code between the [code][/code] tags.
That way it will appear as
1
2
3
4
5
int main()
{
   //This does nothing:-)
   return 0;
}

rather than

int main()
{
//This does nothing:-)
return 0;
}

If you post the code (or the relevant parts if it's long) and give as much info on the problem as possible someone will almost certainly reply with soem help:-)
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
#pragma once

template<typename DataType>

class SLLNode
{
private:
	DataType data;
	SLLNode<DataType> * next;
public:
	SLLNode(const DataType & unDato, SLLNode<DataType> * next = NULL);
	const DataType & getData()const;
	void setData(const DataType & unDato);
	SLLNode<DataType> * getNext()const;
	void setNext(SLLNode<DataType>* next);

};

template<typename DataType>
SLLNode<DataType>::SLLNode(const DataType & unDato, SLLNode<DataType>* next)
{
	this->data=unDato;
	this->next=next;
}
//Si el type es inventado por usted, hay que crear un operador de asignar overloaded;

template<typename DataType>
const DataType & SLLNode<DataType>::getData()const
{
	return(this->data);
}

template<typename DataType>
void SLLNode<DataType>::setData(const DataType & unDato)
{
	this->data=unDato;
}

template<typename DataType>
SLLNode<DataType> * SLLNode<DataType>::getNext()const
{
	return(this->next);
}

template<typename DataType>
void SLLNode<DataType>::setNext(SLLNode<DataType>* next)
{
	this->next=next;
}


^That's the one for SLLN.h

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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

#pragma once
#include"SLLN.h"

template<typename DataType>
class SLL
{
protected:
	SLLNode<DataType> * head;
public:
	SLL();
	SLL(const SLL<DataType>& unaLista);
	virtual ~SLL();
	SLL<DataType> & operator=(const SLL<DataType> & unaLista);
	bool operator==(const SLL<DataType> & unaLista)const;
	void addFirst(const DataType & unDato);
	void addLast(const DataType & unDato);
	bool addAt(int index, const DataType & unDato);
	bool removeFirst();
	bool removeLast();
	bool removeAt(int index);
	void empty();
	bool modifyAt(int index, const DataType & unDato)const;
	bool getDataAt(int index, DataType & unDato)const;
	int cantidad()const;
	int indexOf(const DataType & unDato)const;
};
template<typename DataType>
SLL<DataType>::SLL()
{
	this->head=NULL;
}
template<typename DataType>
SLL<DataType>::SLL(const SLL<DataType> & unaLista)
{
	this->head=NULL;
	*this=unaLista;
}
template<typename DataType>
SLL<DataType>::~SLL()
{
	this->empty();
}
template<typename DataType>
void SLL<DataType>::empty()
{
	while(this->removeFirst());
}
template<typename DataType>
int SLL<DataType>::cantidad()const
{
	int total=0;
	SLLNode<DataType>*current;
	current=this->head;
	while(current!=NULL)
	{
		total++;
		current=current->getNext();
	}
return (total);
}
template<typename DataType>
void SLL<DataType>::addFirst(const DataType &unDato)
{
	SLLNode<DataType>*newNode;
	newNode = new SLLNode<DataType>(unDato, this->head);
	this->head=newNode;
}
template<typename DataType>
void SLL<DataType>::addLast(const DataType &unDato)
{
	SLLNode<DataType>*last,*newNode;
	if(this->head!=NULL)
	{
		newNode=new SLLNode<DataType>(unDato);
		last=this->head;
		while(last->getNext()!=NULL)
			{
			last=last->getNext();
			}
		last->setNext(newNode);
	}
	else
		this->addFirst(unDato);
}
template<typename DataType>
bool SLL<DataType>::addAt(int index, const DataType &unDato)
{
	SLLNode<DataType>* newNode, *previous;
	bool added=false;
	int previousPosition;
	if(index >=0 && index<=this->cantidad())
	{	
		added=true;
		if(index==0)
			this->addFirst(unDato);
		else
			if(index==this->cantidad())
				this->addLast(unDato);
			else{
				previous=this->head;
				newNode=new SLLNode<DataType>(unDato);
				previousPosition=0;
				while((previousPosition+1)<index)
				{
					previousPosition++;
					previous=previous->getNext();
				}
					newNode->setNext(previous->getNext());
					previous->setNext(newNode);
	}
	}
	return(added);
}
template<typename DataType>
bool SLL<DataType>::removeAt(int index)
{
	SLLNode<DataType>*toDelete, *previous;
	bool removed=false;
	int previousPosition;
	if(index >=0 && index<this->cantidad())
	{	
		removed=true;
		if(index==0)
			this->removeFirst();
		else
			if(index==(this->cantidad()-1))
				this->removeLast();
			else{
				previous=this->head;
				previousPosition=0;
				while((previousPosition+1)<index)
				{
					previousPosition++;
					previous=previous->getNext();
				}
				toDelete=previous->getNext();
				previous->setNext(toDelete->getNext());
				delete toDelete;
	}
	}
	return(removed);
}
template<typename DataType>
bool SLL<DataType>::removeLast()
{
	SLLNode<DataType>*toDelete, *previous;
	bool removed=false;
	if(this->cantidad()!=0)
	{	
		removed=true;
		if(this->cantidad()==1)
			this->removeFirst();
		else
		{
				
				previous=this->head;
				toDelete=previous->getNext();
				while(toDelete->getNext()!=NULL)
				{
					previous=toDelete;
					toDelete=toDelete->getNext();
				}

				previous->setNext(toDelete->getNext());
				delete toDelete;
	}
	}
	return(removed);
}
template<typename DataType>
bool SLL<DataType>::removeFirst()
{
		SLLNode<DataType>*toDelete;
	bool removed=false;
	if(this->cantidad()!=0)
	{	
		removed=true;
		toDelete=this->head;
		this->head=toDelete->getNext();
		delete toDelete;
	}
	return(removed);
}
template<typename DataType>
SLL<DataType> & SLL<DataType>::operator=(const SLL<DataType> & unaLista)
{
	DataType unDato;
	bool found;
	this->empty();
	for(int i=0; i<unaLista.cantidad(); i++)
	{
		unaLista.getDataAt(i,unDato);
		this->addLast(unDato);
	}

		return(*this);
}
template<typename DataType>
bool SLL<DataType>::operator==(const SLL<DataType> & unaLista)const
{
	DataType unDato;
	bool equal=true,found;
	if(this->cantidad()!=unaLista.cantidad())
		equal=false;
	else
		for(int i=0;(i<unaLista.cantidad())&&equal;i++)
			if(!(this->getDataAt(i,unDato)==unaLista.getDataAt(i,unDato)))
				equal=false;
	return (equal);
}
template<typename DataType>
int SLL<DataType>::indexOf(const DataType &unDato) const
{
	DataType unDato1;
	int index=-1;
	bool found=false;
	for(int i=0; (i<this->cantidad())&&(index==-1);i++){
		this->getDataAt(i,unDato1);
		if((unDato1==unDato))
			index=i;
	}
		return(index);
}
template<typename DataType>
bool SLL<DataType>::getDataAt(int index, DataType & unDato)const
{
	SLLNode<DataType>*current;
	bool esta=false;
	if(index>=0 && index<this->cantidad())
	{
		esta=true;
		current=this->head;
		for(int i=0; i<index; i++)
			current=current->getNext();
		unDato=current->getData();

	}
	return(esta);
}
template<typename DataType>
bool SLL<DataType>::modifyAt(int index, const DataType &unDato) const
{
SLLNode<DataType>*current;
bool esta=false;
if(index>=0&&index<this->cantidad())
{
	esta=true;
	current=this->head;
	for(int i=0;i<index;i++)
		current=current->getNext();
	current->setData(unDato);
}
return(esta);
}


^SLL.h

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

#include <iostream>
#include "SLL.h"
#include "Tareas.h"

class Agenda:protected SLL<Tarea>
{
public:
	Agenda();
	Agenda(const Agenda&unaAgenda);
	~Agenda();
	int total()const;
	bool addTareaAt(int index, const Tarea&unaTarea);
	bool removeTareaAt(int index);
	bool modifyTareaAt(int index, const Tarea&unaTarea)const;
	void empty();
	Agenda&operator=(const Agenda&unaAgenda);
	bool operator==(const Agenda&unaAgenda);
	friend ostream&operator<<(ostream&output, const Agenda&unaAgenda);

};

//Definiciones

Agenda::Agenda()
{							//Van vacios porque utilizan la definicion de la clase SLL.h
}

Agenda::Agenda(const Agenda&unaAgenda):SLL<Tarea>(unaAgenda)
{
}

int Agenda::total()const
{
	int t=0;
	Tarea unaTarea;
	
	for(int i=0; i<this->cantidad(); i++)		//al ser herencia, uso operaciones de SLL. EJEMPLO: CANTIDAD
	{
		this->getDataAt(i,unaTarea);
		t+=unaTarea.getTarea();
	}
	return(t);
}

template<typename DataType>
bool removeTareaAt(int index):SLL<Tarea>(unaAgenda)
{
	SLLNode<DataType>*toDelete, *previous;
	bool removed=false;
	int previousPosition;
	if(index >=0 && index<this->cantidad())
	{	
		removed=true;
		if(index==0)
			this->removeFirst();
		else
			if(index==(this->cantidad()-1))
				this->removeLast();
			else{
				previous=this->head;
				previousPosition=0;
				while((previousPosition+1)<index)
				{
					previousPosition++;
					previous=previous->getNext();
				}
				toDelete=previous->getNext();
				previous->setNext(toDelete->getNext());
				delete toDelete;
	}
	}
	return(removed);
}

template<typename DataType>
bool addTareaAt(int index, const Tarea&unaTarea):SLL<Tarea>(unaAgenda)
{
	SLLNode<DataType>* newNode, *previous;
	bool added=false;
	int previousPosition;
	if(index >=0 && index<=this->cantidad())
	{	
		added=true;
		if(index==0)
			this->addFirst(unaTarea);
		else
			if(index==this->cantidad())
				this->addLast(unaTarea);
			else{
				previous=this->head;
				newNode=new SLLNode<DataType>(unaTarea);
				previousPosition=0;
				while((previousPosition+1)<index)
				{
					previousPosition++;
					previous=previous->getNext();
				}
					newNode->setNext(previous->getNext());
					previous->setNext(newNode);
	}
	}
	return(added);
}

Agenda&Agenda::operator=(const Agenda&unaAgenda) //Operador de asignar
{
	SLL<Tarea>::operator=(unaAgenda);				//Utilizo la deficinicion dada en Billete.h
	return(*this);
}

bool Agenda::operator==(const Agenda&unaAgenda)	//Operador de igual
{
	return(SLL<Tarea>::operator==(unaAgenda));
}

ostream&operator<<(ostream&output,const Agenda&unaAgenda)
{
	Tarea unaTarea;

	for(int i=0; i<unaAgenda.cantidad();i++)
	{
		unaAgenda.getDataAt(i,unaTarea);
		output<<unaTarea<<endl;
	}

	output<<endl<<endl;
	return(output);

}

template<typename DataType>
bool modifyTareaAt(int index, const Tarea &unaTarea)const:SLL<Tarea>(unaAgenda)
{
SLLNode<DataType>*current;
bool esta=false;
if(index>=0&&index<this->cantidad())
{
	esta=true;
	current=this->head;
	for(int i=0;i<index;i++)
		current=current->getNext();
	current->setData(unaTarea);
}
return(esta);
}


^Agenda


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

#pragma once 
#include<iostream>
#include "SLL.h"

using namespace std;


//Programa que simula una tarea

class Tarea
{
private:
	char tarea;
public:
	Tarea(char tarea);
	Tarea(const Tarea&unaTarea);
	Tarea&operator=(const Tarea&unaTarea);
	~Tarea();
	bool operator ==(const Tarea&unaTarea)const;
	int getTarea()const;
	void setTarea(int value);
	friend ostream&operator<<(ostream&output, const Tarea&unaTarea);
};

//Definiciones

Tarea::Tarea(char tarea=0)
{
	this->tarea=tarea;
}

Tarea::Tarea(const Tarea&unaTarea)
{
	this->tarea=unaTarea.tarea;
}

Tarea&Tarea::operator=(const Tarea&unaTarea)
{
	this->tarea=unaTarea.tarea;
	return(*this);
}

bool Tarea::operator==(const Tarea&unaTarea)const
{
	return(this->tarea==unaTarea.tarea);
}

int Tarea::getTarea()const
{
	return(this->tarea);
}

void Tarea::setTarea(int value)
{
	this->tarea=tarea;
}

ostream&operator<<(ostream&output, const Tarea&unaTarea)
{
	output<<"$"<<unaTarea.tarea;
	return(output);
}


^Tarea

As you can see it has to be done using inheritance from the SLL.h and SLLN.h (which are the ones for Single Linked List)
Again, my problem is that i don't know how to make the hour thing, and how to input the activity..

thanx in advanced

Ok, as far as I understand the code you have a template class Agenda which is descended from SLL (a linked list) holding nodes of type SLLN which in turn hold a memeber of Tarea - which is the data.
So what you need to do is
1) Extend Tarea to hold the activity and hour information.
2) Create your user interface to access and modify the Tarea data within Agenda. This includes creating new instances of Tarea to add to Agenda, etc.
This does not need to be done inside the class (but it can be if you need to) - it can simply uses the Agenda class to store the information.
Topic archived. No new replies allowed.