Seek for help..linked list..urgent!!!
I 'm C++ programming beginner..I need someone help me ..
There is error "expected primary-expression before "template""..I 'm really don't know how to fix it..my compiler is Dev C++..pls giv me a favor..
Thanks for helping...
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
fstream fp; // fstream provides an interface to read and write data from files as input/output streams.
ofstream ofp; // ofstream provides an interface to write data to files as output streams
template <class Type1, class Type2>
struct nodeType
{
Type1 month;
Type1 day;
Type1 year;
Type2 participant;
Type2 task_title;
Type1 status;
nodeType<Type1,Type2> *link;
};
template <class Type1, class Type2>
class c_system
{
public:
void initialiseList();
bool isEmpty();
c_system();
void insert(Type1 dd, Type1 mm, Type1 yy, Type2 person, Type2 title,Type2 description);
void addDetail();
nodeType<Type1,Type2> *first;
nodeType<Type1,Type2> *last;
};
template <class Type1, class Type2>
c_system<Type1,Type2> :: c_system()
{
first = NULL;
last = NULL;
}
template <class Type1, class Type2>
void c_system<Type1,Type2> :: insert(Type1 dd, Type1 mm, Type1 yy, Type2 person, Type2 title,Type2 description)
{
nodeType<Type1,Type2> *current;
nodeType<Type1,Type2> *trailCurrent;
nodeType<Type1,Type2> *newNode;
bool found;
newNode = new nodeType<Type1,Type2>;
assert(newNode != NULL); //terminate the program if cant allocate memory//
newNode ->day = dd; //store details into node
newNode ->month =mm;
newNode ->year =yy;
newNode ->participant = person;
newNode ->task_title = title;
newNode -> des=description;
newNode ->link = NULL;
newNode ->status = "pending";
if(first ==NULL) //if there is empty list
{
first = newNode;
last = newNode;
}
else
{
current = first;
found = false;
while(current !=NULL &&!found)
{
if(current->participant >= newNode->participant)
{
found = true;
}
else
{
trailCurrent = current;
current = current ->link;
}
}
if(current == first)
{
newNode->link = first;
first = newNode;
}
else
{
trailCurrent->link = newNode;
newNode ->link = current;
if(current == NULL)
last = newNode;
}
}
template <class Type1, class Type2>
void c_system<Type1,Type2> ::addDetail()
{
Type1 d,m,y;
Type2 people,name_title;
cout<<"Please enter the following details."<<endl;
cout<<"Date: (dd mm yy)";
cin>>d>>m>>y;
cout<<"Participant: ";
gets(people);
cout<<"Title: ";
gets(name_title)
cout<<"Description: ";
gets(des)
insert(d, m,y,people,name_title); //call function to insert data into node of the list
}
template <class Type1, class Type2>
void c_system<Type1,Type2> :: displayList()
{
nodeType<Type1,Type2> *current;
current = first;
while(current != NULL) //while there are nodes in the list
{
cout<<"---------------------------------------------------------"<<endl;
cout<<"Date: "<<current->day<<current->month<<current->year<<endl;
cout<<"Participant: "<<current->participant<<endl;
cout<<"Title: "<<current->task_title<<endl;
cout<<"Description: "<<current->des<<endl;
cout<<"Status: "<<current->status<<endl;
cout<<"---------------------------------------------------------"<<endl;
cout<<endl;
current = current->link;
}
}
int main()
{
c_system<string,long long> obj;
time_t d = time(0);
tm* current_date = localtime(&d);
cout<<"Time and Date: "<<ctime(&d)<<endl;
cout<<" ***My Calendar*** "<<endl;
while(begin!=0)
{
cout<<endl;
cout<<"Select an option which you want to proceed. "<<endl;
cout<<"1.Add the Task"<<endl;
cout<<"2.Delete the Task"<<endl;
cout<<"3.Display all Task"<<endl;
cout<<"0.To exit the program"<<endl;
cin>>begin;
switch(begin)
{
case 0: cout<<"Program ended"<<endl;
break;
case 1: obj.addTask();
break;
case 2: obj.deleteTask();
break;
case 2: obj.displayList();
break;
default: cout<<"Invalid input."<<endl;
}
}
system("pause");
return 0;
}
}