Getting a bunch of errors from one line of code

Hey guys I am currently doing a homework assignment for my class and I could use a little help. The assignment is to create a an abstract class called "number" and have 3 classes derived from it: binary, octal, and hexadecimal. Each class takes an integer input by the user and converts it to a different base with respect to the class that is called (e.g. if the user puts 5 the screen will display 5 in binary, octal, and hex). Another class that is included is called "stack" and is required in the assignment.
I am using visual studio 2010 and I have all my code separated into different header files (binary.h, octal.h, hexadecimal.h, and stack.h) and one .cpp file called main. In main I have #include <iostream>, #include "binary.h" and the code compiles and runs exactly how I planned it to. When I add #include "octal.h" and try to compile, I get around 30 errors. Here is a screenshot of the error list (http://www.mediafire.com/i/?lhuhrk1sbc67bqi).
I have no idea what's going on and the errors don't make too much sense to me. Here is my code that will compile and run.

main.cpp
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
#include <iostream>
#include "binary.h"


int main()
{
	std::cout << "This program will convert a number in to binary, octal, and hexadecimal.\n\n";

	std::cout << "Please input a positive integer: ";
	int UserNumber;
	std::cin >> UserNumber;
	while(UserNumber < 0)
	{
		std::cout << "Invalid entry. Please enter a positive integer: ";
		std::cin >> UserNumber;
	}
	std::cout << "\n\n";

	number* convert;
	convert = new binary(UserNumber);
	std::cout << "In binary, " << UserNumber << " is ";
	convert->print_it();
	std::cout << ".\n";
	delete convert;

	return 0;
}


number.h
1
2
3
4
5
6
7
8
9
class number
{
public:
	virtual void print_it() = 0;

protected:
	int intInput;

};


stack.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
#include <iostream>
using namespace std;

const int STACK_SIZE = 100;

class stack
{
	private:
		int count;			// number of items in the stack
		int data[STACK_SIZE];
	public:
		stack();
		~stack();
		void push(const int item);	// push an item on the stack
		int pop();			// pop item off the stack
		int getCount() const;			// return count
};

stack::stack()	// constructor
{
	count = 0;	// zero the stack
}

stack::~stack() {}	// default destructor

void stack::push(const int item)
{
	if (count < STACK_SIZE)
	{
		data[count] = item;
		++count;
	}
	else cout << "Overflow!\n";
}

int stack::pop()
{
	if (count >0)
	{
		--count;
		return (data[count]);
	}
	else
	{
		cout << "Underflow!\n";
		return 0;
	}
}

int stack::getCount() const
{
	return count;
}


binary.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
#include <iostream>
#include "number.h"
#include "stack.h"

class binary : public number
{
	public:
		binary(int UserNumber);
		~binary();
		void print_it();
};

binary::binary(int UserNumber)
{
	intInput = UserNumber;
}

binary::~binary() {}

void binary::print_it()
{
	stack Stack;

	while(intInput > 0)
	{
		Stack.push(intInput%2);
		intInput /= 2;
	}

	while(Stack.getCount() > 0)
	{
		std::cout << Stack.pop();
	}
}


octal.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
#include <iostream>
#include "number.h"
#include "stack.h"

class octal : public number
{
	public:
		octal(int UserNumber);
		~octal();
		void print_it();
};

octal::octal(int UserNumber)
{
	intInput = UserNumber;
}

octal::~octal() {}

void octal::print_it()
{
	stack Stack1;

	while(intInput > 0)
	{
		Stack1.push(intInput%8);
		intInput /= 8;
	}

	while(Stack1.getCount() > 0)
	{
		std::cout << Stack1.pop();
	}
}

In order to make it not compile and get that huge error list just add the #include "octal.h" in main.
I realize it's a lot to ask for you all to look through, but I have been researching and trying to fix it for a few hours now and I am clueless as how to make it work. Any help would be really appreciated!
I didn't compile this yet but from what I notice, you have alot of header files that have included iostream but yor header files are not set up to load only once.

1
2
3
4
5
6
#ifndef HEADER_H
#define HEADER_H

// Code

#endif 


This is generally what you place in a header file so that if something it not loaded, it will load. If it is loaded, it will not load a second time.

Then I noticed you put this

1
2
	number* convert;
	convert = new binary(UserNumber);


Here is the problem with this, you are trying to convert a number to a binary and these classes are not set up to handle these. Based on what your teacher requests, you will need to have 3 separate variables in your main.

1
2
3
binary i1;
octa i2;
hexa i3;


Each of these classes will also be able to access the class of number which will hold your integer and have the function (most likely operator= overloading) that will set up number equal to an integer. Then each class will have its own print function to display the number as the type you need it to display.

1
2
3
4
5
6
7
8
9
10
11
12
13
class number
{
   int num;

public:
   number &operator=(const int &);
};

class hexa : number
{
public:
   void PrintScreen();
};


I didn't put the constructors and deconstructors in there because you should easily be able to handle them. hopefully this is enough to hepl you program it, if you need more help, let me know.
Topic archived. No new replies allowed.