I'm writing up a program for a class I'm taking where I need to make a linked list stack & queue. Right now I'm not quite done, but I'm having problems calling the functions from the .h file.
What's happening is in the while loop, I'm trying to get data loaded from a file to load the specific function, then send the numbers after it from that file into the function. VS 2010 is telling me that the identifier for each of the four functions is undefined. Do I just need to add int before each of them? I'm thinking I wouldn't because that would be declaring it right? which I've already done.
Here's an example of the data that's going to be loaded from a file:
push 10
push 35
push 50
append 100
pop
push 15
pop
serve
serve
append 200
It has been a little while since I've programmed so it may just be a few basic thing that I've forgotten, but if I could get help on this it'd be great. ^.^
Here's my .cpp
#include "LinkedLists.h"
using namespace std;
void main()
{
Stack();
Queue();
char reload = 'y';
cout<<"Student: Matthew Law"<<endl<<"Professor: Reza Sanati Mehrizy"<<endl<<"CS 2420"<<endl<<"Project 1"<<endl;
while(reload=='y'||reload=='Y')
{
string function;
string File;
ifstream fLocation;
cout<<endl<<"What is the file you would like to load? ";
cin>> File;
fLocation.open(File);
while(fLocation.good())
{
cin>>"function";
int num = 0;
if(function=="push"||function=="Push")
{
cin>>num;
push(num);
}
else if(function=="pop"||function=="Pop")
{
pop();
}
else if(function=="append"||function=="Append")
{
cin>>num;
append(num);
}
else if(function=="serve"||function=="Serve")
{
serve();
}
else
cout<<"\nAn incorrect function was defined in the file.\n";
}
cout<<"Would you like to run the program again? y/n: ";
cin>>reload;
}
}
and my .h
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <streambuf>
enum Error_code
{
success,
overflow,
underflow
};
#define NodeEntry int
#define Stack_entry int
#define Queue_entry int
struct Node
{
NodeEntry entry;
Node *next;
Node();
Node(NodeEntry item, Node* addOn);
};
class Stack
{
public:
Stack();
bool empty() const;
Error_code push(const Stack_entry &item);
Error_code pop();
~Stack();
protected:
Node *top_node;
};
class Queue
{
public:
Queue();
Error_code append(const Queue_entry &item);
Error_code serve();
~Queue();
protected:
Node *front_node, *back_node;
};
//-----------------Node----------------
Node::Node()
{
next = NULL;
}
Node::Node(NodeEntry item, Node* addOn)
{
entry = item;
next = addOn;
}
//-----------------Stack---------------
Error_code Stack::push(const Stack_entry &item)
{
Node *new_top = new Node(item, top_node);
if (new_top == NULL)
return overflow;
top_node = new_top;
return success;
}
Error_code Stack::pop()
{
Node *old_top = top_node;
if (top_node == NULL)
return underflow;
top_node = old_top->next;
delete old_top;
return success;
}
//-----------------Queue-------------
Error_code Queue::append(const Queue_entry &item)
{
}
Error_code Queue::serve()
{
}
also if you happen to notice any glaring errors, please let me know. ^^ Thanks~