i am not new to c++ programing but i used 4 years back . So i lost touch with it.i am trying to implement a Stack of strings ADT, using a doubly linked list and As a minimum my class should offer Default constructor, copy constructor,Destructor,Overloaded assignment operator.i written some code like this
list.h
#ifndef STACK_H
#define STACK_H
#include "iostream"
using namespace std;
struct node{
string name;
string course;
node* next;
node* prev;
};
class list{
public:
static node* newnode();
//static void node* searchnode();
static note* deletenode();
static node* display();
private:
static node* firstnode;
static node* lastnode;
};
#endif
and
list.cpp
#include "iostream"
#include "stack.h"
using namespace std;
node* list::newnode()
{
node* nodehold;
nodehold = new node;
cout << endl << "Enter the Name:";
cin >> nodehold->name;
cout << endl << "Enter the Cource:";
cin >> nodehold->course;
if(firstnode == NULL)
{
firstnode = nodehold;
lastnode = nodehold;
nodehold->next = NULL;
nodehold->prev = NULL;
return nodehold;
}
if(firstnode != NULL)
{
nodehold->next = lastnode;
nodehold->prev = NULL;
return nodehold;
}
}
node* list::deletenode()
{
node *nodehold;
nodehold = firstnode;
firstnode = firstnode->next;
delete nodehold;
return;
}
//node* list::searchnode()
//{
//
//}
node* list::display()
{
node* nodehold;
if(firstnode == NULL)
{
cout << endl << "There are no nodes in list";
return;
}
else
{
nodehold = firstnode;
while(nodehold != NULL)
{
cout << endl <<"Name:"<< nodehold->name << "\tCourse:" << nodehold->course;
nodehold=nodehold->next;
}
cout << endl << "End of list";
}
}
and
listmain.cpp
#include "iostream"
#include "stack.h"
using namespace std;
void main()
{
int option;
//node list::firstnode=NULL;
//node list::lastnode=NULL;
firstnode=NULL;
lastnode=NULL;
do
{
cout << "Please select an option :" << endl;
cout << "0. Exit the program." <<endl;
cout << "1. Add a node" << endl;
cout << "2. Delete node from the list." << endl;
//cout << "3. search node from the list." << endl;
cout << "4. display node from the list." << endl;
cout << endl << " >> ";
switch (option)
{
case 1 : node* list::newnode();
break;
case 2 : node* list::deletenode();
break;
//case 3 : node* list::searchnode();
// break;
case 4 : node* list::display();
break;
}
}while(option != 0);
}
when i try to run i got 19 errors
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
warning C4183: 'deletenode': missing return type; assumed to be a member function returning 'int'
error C2065: 'firstnode' : undeclared identifier
error C2065: 'lastnode' : undeclared identifier
error C2761: 'node *list::newnode(void)' : member function redeclaration not allowed
error C2761: 'int *list::deletenode(void)' : member function redeclaration not allowed
error C2761: 'node *list::display(void)' : member function redeclaration not allowed list.cpp
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
warning C4183: 'deletenode': missing return type; assumed to be a member function returning 'int'
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
whats wrong with my code ...help me

New Topic/Question
Reply



MultiQuote




|