Hey..i'm new here and i'm actually taking a course related to C++ Programming. My assignment is to create a simulation on an agenda..

the agenda is a daily agenda, it only works for one day (so you will not see what day it is, it's general)

it stores info in hours, and can store more than one activity in the same hour

It should be able to delete, add, modify and show the activities.

The problem here is, it has to be developed using SLL (Single Linked Lists), which i have done already but my problem is that i'm not sure how to developed the action that shows me Hours and a menu.

I think i have and idea on how to add and remove activities, by using dynamic arrays but i need help and suggestions cuz it's been long since i've practiced programming.

thanx

I can see a few ways of this being done...

First of all, why use an array?

You can easily use a LinkedList (and even a nested LinkedList) to get the job done. Chances are you'll only need a 1 LinkedList anyways.

For example, you can track time using a time implementation and generate a new node in your LinkedList for each incrementing hour. The currently farthest node from the root will be the one that records the information that's occurring currently.

You probably wont need to delete nodes in this case, but you'll need to delete information stored in one.

By the way, what have you started with?

i'll try to post what i've got..

#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;
}

the second class SLL

#pragma once
#include"SLLNode.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);
}

the third one: AGENDA

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

template <typename DataType>

class Agenda
{
private:
	char tarea;



public:
	Agenda();
	Agenda(const Agenda&unaAgenda);
	Agenda&operator=(const Agenda&unaAgenda);
	bool operator ==(const Agenda&unaAgenda)const;
	int getEntry()const;
	void setEntry(char tarea);
	friend ostream&operator<<(ostream&output, const Agenda&unaAgenda);
};

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

Agenda::Agenda(const Agenda&unaAgenda)
{
	this->value=unaAgenda.tarea;
}

Agenda&Agenda::operator=(const Agenda&unaAgenda)
{
	this->value=unaAgenda.tarea;
	return(*this);
}

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

int Agenda::getEntry()const
{
	return(this->tarea);
}

void Agenda::setEntry(char tarea)
{
	this->tarea=tarea;
}

ostream&operator<<(ostream&output, const Agenda&unaAgenda)
{
	output<<unaAgenda.tarea;
	return(output);
}

and the last one for now: MiAgenda

#pragma once

#include "SLL.h"
#include "Agenda.h"

class Planner:protected SLL<Agenda>
{
public:
	Planner();
	(const Planner&unPlanner);
	int total()const;
	void addEntry(const Agenda&unaAgenda);
	bool sacarEntry(char tarea, Agenda&unaAgenda);
	Planner&operator=(const Planner&unPlanner);
	bool operator==(const Planner&unPlanner);
	friend ostream&operator<<(ostream&output, const Planner&unPlanner);
	

};

//Definiciones

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

Planner::Planner(const Planner&unPlanner):SLL<Agenda>(unPlanner)
{
}

int Planner::total()const
{
	int t=0;
	Billete unBillete;
	
	for(int i=0; i<this->cantidad(); i++)		//al ser herencia, uso operaciones de SLL. EJEMPLO: CANTIDAD
	{
		this->getDataAt(i,unaAgenda);
		t+=unaAgenda.getValue();
	}
	return(t);
}

bool Planner::sacarEntry(char tarea, Agenda&unaAgenda)
{
	bool hay = false;
	int index;
	Agenda otraAgenda(tarea);

	index= this->indexOf(otraAgenda);

	if(index!=-1)
	{
		hay=true;
		this->getDataAt(index, unaAgenda);
		this->removeAt(index);
	}

	return(hay);
}

void Agenda::addAgenda(const Agenda&unaAgebda)
{
	this->addFirst(unaAgenda);
}


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

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

ostream&operator<<(ostream&output,const Planner&unPlanner)
{
	Agenda unaAgenda;

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

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

}

sorry, i know it's kinda long..if you guys can give me some ideas would be good..
thanx in advance!

This article has been dead for over six months. Start a new discussion instead.