Need some Extra Eyes on this HomeWork Assignment

I have been fighting this for almost a week now and I can't figure out the issues. The program is not working the way that many of my previous assignments did. I have compared line by line trying to figure out what is different between the snipets of code that would cause the problem so if any one as an Idea what I am doing wrong with this please let me know.

the header file
Classes.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#define NULL 0
#include <string>

class myList
{
public:

	myList();

	~myList();

	void push_front(Node* N);

	void pop_front();

	Node* getFirst()const;

private:

	Node* firstN;
	int numNodes;

};

class Node
{
public:
	Node();

	~Node();

	Node(std::string a,std::string b);

	Node* getNext()const;

	void setNext(Node* N);
	
private:
	Node* NextPTR;
	
};

class Grocery: public Node
{
public:
	Grocery(void);
	~Grocery(void); 
	std::string Grocery::getItem()const;
	void Grocery::setItem(std::string I);
	std::string Grocery::getQuantity()const;
	void Grocery::setQuantity(std::string I);

private:
	std::string item;
	std::string quantity;
};



the MyList class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#include "Classes.h"
#define NULL 0

myList::myList()
{
	firstN = NULL;
	numNodes = NULL;
}

myList::~myList()
{	
	Node* next = myList.getFirst();
	while(next != NULL)
	{
		Node* deleter = next;
		next = next ->getNext();
		delete deleter;
	}
}

void push_front(Node* N)
{
	if(N != NULL)
	{	
		*firstN = N;
		myList::numNodes++;
	}
	else
	{
		N->setNext(*firstN);
		firstN = N;
		myList::numNodes++;
	}
}

void pop_front()
{
    Node* tempNode = firstN;
    firstN = firstN->getNext( );
    delete tempNode;
}

Node* myList::getFirst()const
{
	*firstN = *lastN;
}



the Node class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43


#include "Classes.h"
#include<iostream>
#include<string>
#define null 0

using namespace std;

Node()
{
	Node* NextPTR = null;
	NextPTR = null;
}

~Node()
{
	Node* NextPTR = Node.getNext();
	while(NextPTR != null)
	{
		Node* deleter = NextPTR;
		NextPTR = NextPTR ->getNext();
		delete deleter;
	}
	
}

Node(std::string a,std::string b)
{
	Grocery.setQuantity = a;
	Grocery.setItem = b;
	Node.setNext;
}

Node* Node::getNext()const
{
	return NextPTR;
}

void Node::setNext(Node* N)
{
	*NextPTR = *N;
}


the grocery class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37


#include "Classes.h"
#include <string>

Grocery()
{
	item = "";
	quantity = "";
}

:~Grocery(void)
{
	item = "";
	quantity = "";
}

std::string getItem()const	
{
	return item;
}

void setItem(std::string I)
{
	item = I;
}

std::string getQuantity()const
{
	return quantity;
}

void setQuantity(std::string I)
{
	quantity = I;
}


and my driver class( I simplified this one for testing)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#include <string>
#include <list>
#include "Classes.h"
#include <iostream>
using namespace std;

int main()
{
	list<Node> GroceryList;
	
	Node* GrList = new Node("2 Gallons","milk");

	GroceryList.push_front(GrList);
	
        cout << GrList;

	system("Pause");
	return 0;
}


As you can probably see I am a beginer and just need a little(or maybe a lot) of guidance in the right direction. thanks.

Why do you define a NULL? You don't need to, it will complicate matters and maybe the reason for your problem. The confusion is that NULL needs to be applied to the node, but since it equals zero, then you run into troubles I assume. The int should just equal 0 when you create the object. Also, make a grocery header for its functions instead of putting it all in classes.h. Try that and see where you get?
Last edited on
In your method definitions you haven't been referring to the classes they belong to correctly. For example, instead of:
void push_front(Node* N)
in myList, you should've written:
void myList::push_front(Node* N)
in the definition.

You don't need this in the class definition, but outside that you need to specify what class the method belongs to!
Also, in your 'driver class' you #include classes.h, but this doesn't contain the definitions, maybe you should include a different file?
I moved the grocery all byy itself and it has cut out a lot of the errors I was recieving the program complained when I took off the 0 for the NULL so I put the 0 back.

the program still seems to complain about the class definition for

 
void push_front(Node* N);


here is the error:
 
error C2061: syntax error : identifier 'Node'
That's the method declaration, it's inside a class definition.

The issue is with the use of 'Node', it doesn't recognise it. That's because you declare Node after this line. Move the Node class to the top to fix the issue.
Wow that just about fixed almost all the issues

I am now on a role.


it is running now.

I have to iron out some of the stuff I plugged in now but at least it is running.

THANK YOU !!! SAVED MY LIFE, WIFE, AND GRADES!



**I said my wife becuase she threatend to leave me if I failed lol
Too much information jonyrk3, but I'm glad I could help!
Topic archived. No new replies allowed.