From cc969008b7f77a172ff6461b7fecc7962092e42f Mon Sep 17 00:00:00 2001 From: jimtahu Date: Fri, 26 Apr 2013 12:44:33 -0500 Subject: [PATCH] Added class for List type --- ListVariable.cpp | 28 ++++++++++++++++++++++++++++ ListVariable.h | 28 ++++++++++++++++++++++++++++ Variable.h | 6 +++--- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 ListVariable.cpp create mode 100644 ListVariable.h diff --git a/ListVariable.cpp b/ListVariable.cpp new file mode 100644 index 0000000..4e395cf --- /dev/null +++ b/ListVariable.cpp @@ -0,0 +1,28 @@ +/* + * List.cpp + * + * Created on: Apr 25, 2013 + * Author: jimtahu + */ + +#include "ListVariable.h" + +ListVarable::ListVarable(string name):Variable(name) { + this->head=NULL; +} + +void ListVarable::add(string value){ + ListItem *item = new ListItem(); + item->value=value; + item->next=this->head; + this->head=item; +} + +ListVarable::~ListVarable() { + ListItem *item = this->head; + while(this->head != NULL){ + this->head=item->next; + delete item; + item=this->head; + }//end while list items +} diff --git a/ListVariable.h b/ListVariable.h new file mode 100644 index 0000000..631a72d --- /dev/null +++ b/ListVariable.h @@ -0,0 +1,28 @@ +/* + * List.h + * + * Created on: Apr 25, 2013 + * Author: jimtahu + */ + +#ifndef LIST_H_ +#define LIST_H_ + +#include "Variable.h" + +class ListItem { +public: + string value; + ListItem *next; +public: +}; + +class ListVarable: public Variable { + ListItem *head; +public: + ListVarable(string name); + void add(string value); + virtual ~ListVarable(); +}; + +#endif /* LIST_H_ */ diff --git a/Variable.h b/Variable.h index d39bd77..4083d14 100644 --- a/Variable.h +++ b/Variable.h @@ -19,9 +19,9 @@ class Variable { public: Variable(string name); Variable(Variable &other); - string GetName(); - string GetValue(); - void SetValue(string value); + virtual string GetName(); + virtual string GetValue(); + virtual void SetValue(string value); virtual ~Variable(); };