Need help with assignment

I'm getting multiple error's on my homework assignment, and I've been trying to figure it out for the last 8 hours, can someone please tell me what I'm doing wrong? I'm new at all of this, so I haven't reached inheritance, templating.. etc. just the basics. Any help of advice will be more than appreaciated, sorry for the really long code.

The code in main will be like this:

1
2
entry anEntry;
productiondb db(anEntry);


and it starts at productions productiondb.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
#ifndef PRODUCTIONDB_H
#define PRODUCTIONDB_H
#include"entry.h"
#include "resource.h"
#include "monthdata.h"
#include "yeardata.h"
#include "station.h"
#include<string>
#include <map>

class productiondb {

public:
	productiondb() {};
	~productiondb();

	bool addData(Entry &anEntry);

private:
	typedef std::map<int, class YearData*> yrMap;
	yrMap years;

	yrMap::const_iterator getProductionBegin() const { return years.cbegin(); }
	yrMap::const_iterator getProductionEnd() const { return years.cend(); }


};



#endif 


productiondb.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "productiondb.h"

bool productiondb::addData(Entry &anEntry)
{
	int year = anEntry.getYear();
	yrMap::iterator exact;
	exact = years.find(year);

	if (exact == years.end())
	{
		YearData *newYear = new YearData();
		newYear->addData(anEntry);
		return years.insert(std::make_pair(year, newYear)).second;
	}
	else
	{
		exact->second->addData(anEntry);
		return true;
	}
}


Then production send anEntry to yeardata.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
#ifndef YEARDATA_H
#define YEARDATA_H
#include"entry.h"
#include "resource.h"
#include "monthdata.h"
#include "station.h"
#include "productiondb.h"
//#include <map>

class YearData {

public:
	YearData() : totalYearResource(0) {};
	~YearData();

	bool addData(Entry &anEntry);
	int getTotalResource() const { return totalYearResource; }

private:
	int totalYearResource;

	typedef std::map<std::string, Station*> stationMap;
	stationMap stations;

	stationMap::const_iterator getProductionBegin() const { return stations.cbegin(); }
	stationMap::const_iterator getProductionEnd() const { return stations.cend(); }

	friend class productiondb;

};
#endif 


and the yeardata.cpp file

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
#include "yeardata.h"


bool YearData::addData(Entry &anEntry)
{
	totalYearResource += anEntry.getAmount();
	std::string aStation = anEntry.getStationName;

	stationMap::iterator exact;
	exact = stations.find(aStation);

	if (exact == stations.end())
	{
		Station *newStation = new Station(aStation);
		newStation->addResource(anEntry);
		return stations.insert(std::make_pair(aStation, newStation)).second;
	}
	else
	{
		exact->second->addResource(anEntry);
		return true;
	}
}

YearData::~YearData()
{
	for (aMap::iterator it = stations.begin(); it != stations.end(); ++it)
		delete it->second;
}


and the yeardata sends anEntry to station.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
#ifndef STATION_H
#define STATION_H
#include"entry.h"
#include "resource.h"
#include "monthdata.h"
#include "yeardata.h"
#include "productiondb.h"
#include <string>

class Station {

private:
	int totalStationResource;
	std::string stationName;

	typedef std::map<int, MonthData*> resourceMap;
	resourceMap months;

	resourceMap::const_iterator getBegin() const { return months.cbegin(); }
	resourceMap::const_iterator getEnd() const { return months.cend(); };


public:
	Station() : stationName("Undefined"), totalStationResource(0) {}
	Station(std::string nameOfStation) : stationName(nameOfStation) {}
	~Station();

	bool addResource(Entry & anEntry);
	int getTotalResource() const { return totalStationResource; }
	std::string getStationName() const { return stationName; )

};

#endif 


station.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
28
#include "station.h"

bool Station::addResource(Entry & anEntry)
{
	int month = anEntry.getMonth();
	totalStationResource += anEntry.getAmount();

	stationMap::iterator exact;
	exact = months.find(month);

	if (exact == months.end())
	{
		MonthData *newMonth = new MonthData();
		newMonth->addEntry(anEntry);
		return months.insert(std::make_pair(month, newMonth)).second;
	}
	else
	{
		exact->second->addEntry(anEntry);
		return true;
	}
}

Station::~Station()
{
	for (aMap::iterator it = months.begin(); it != months.end(); ++it)
		delete it->second;
}


and station.h sends it to monthdata.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
59
60
61
62
#ifndef MONTHDATA_H
#define MONTHDATA_H
#include"entry.h"
#include "resource.h"
#include "yeardata.h"
#include "station.h"
#include "productiondb.h"
#include <map>
#include "entry.h"

class MonthData {
private:
	int monthTotalResource;

	typedef std::map<std::string, Resource*> aMap;
	aMap resources;

	aMap::const_iterator getBegin() const { return resources.cbegin(); }
	aMap::const_iterator getEnd() const { return resources.cend(); }

	friend class productiondb;

public:
	MonthData(int totalRsrc = 0) : monthTotalResource(totalRsrc) {}
	~MonthData();

	bool addEntry(Entry & anEntry);
	int getTotalResource() const { return monthTotalResource; }

};

#endif
[\code]

monthdata.cpp
[code]
#include "monthdata.h"

bool MonthData::addEntry(Entry & anEntry)
{
	std::string rsrcName = anEntry.getResourceName();
	aMap::iterator exact = resources.find(rsrcName);
	monthTotalResource += anEntry.getAmount;

	if (exact == resources.end())
	{
		Resource *newResource = new Resource(rsrcName);
		newResource->addResource(anEntry);
		return resources.insert(std::make_pair(rsrcName, newResource)).second;
	}
	else
	{
		exact->second->addResource(anEntry);
		return true;
	}
}

MonthData::~MonthData()
{
	for (aMap::iterator it = resources.begin(); it != resources.end(); ++it)
		delete it->second;
}


and monthdata.h send it to resource.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
#ifndef RESOURCE_H
#define RESOURCE_H
#include"entry.h"
#include "monthdata.h"
#include "station.h"
#include "yeardata.h"
#include "productiondb.h"
#include <string>
#include<map>

class Resource {

private:
	int resourceAmount;
	std::string resourceName;

	typedef std::map<int, Entry*> entryMap;
	entryMap dayToResource;
	
	entryMap::const_iterator getBegin() const { return dayToResource.cbegin(); }
	entryMap::const_iterator getEnd() const { return dayToResource.cend(); }

	friend class productiondb;

public:
	Resource(std::string rscName = "Undefined") : resourceAmount(0), resourceName(rscName) {};
	~Resource();

	bool addResource(Entry & anEntry);
	int getTotalResource() const { return resourceAmount; }

};

#endif 


resource.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
#include "resource.h"

bool Resource::addResource(Entry & anEntry)
{
	int day = anEntry.getDay();

	if (dayToResource.find(day) == dayToResource.end())
	{
		Entry *newEntry = new Entry(anEntry);
		resourceAmount += newEntry->getAmount;
		return dayToResource.insert(std::make_pair(day, newEntry)).second;
	}
	else
		return false;

}

Resource::~Resource()
{
	for (aMap::iterator it = dayToResource.begin(); it != dayToResource.end(); ++it)
	{
		delete it->second;
	}
}


and finally resources.h send it to entry.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
#ifndef ENTRY_H
#define ENTRY_H
#include "resource.h"
#include "monthdata.h"
#include "yeardata.h"
#include "station.h"
#include "productiondb.h"
#include <string>


class Entry {

private:
	int year;
	int month;
	int day;
	int amount;
	std::string station;
	std::string resource;

public:
	Entry() : year(0), month(0), day(0), amount(0), station("NO Station"), resource("No Resource") {}
	Entry(int yr, int mnth, int dy, int amnt, std::string stat, std::string resrc) : year(yr), month(mnth), day(dy), amount(amnt), station(stat), resource(resrc) {}
	~Entry();

	Entry(const Entry &anEntry);
	Entry & operator=(const Entry &anEntry);

	int getYear();
	int getMonth();
	int getDay();
	int getAmount();
	std::string getStationName();
	std::string getResourceName();

};
#endif 


I don't yet have entry.cpp.
Last edited on
What's the first error?
Here are some of the error reports:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
	2	IntelliSense: name followed by '::' must be a class or namespace name	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\productiondb.cpp	6	2	Production Project 1
	3	IntelliSense: expected a ';'	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\productiondb.cpp	6	18	Production Project 1
	4	IntelliSense: identifier "exact" is undefined	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\productiondb.cpp	7	2	Production Project 1
	5	IntelliSense: identifier "YearData" is undefined	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\productiondb.cpp	11	3	Production Project 1
	6	IntelliSense: identifier "newYear" is undefined	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\productiondb.cpp	11	13	Production Project 1
	7	IntelliSense: expected a type specifier	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\productiondb.cpp	11	27	Production Project 1
	8	IntelliSense: explicit type is missing ('int' assumed)	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\station.h	16	10	Production Project 1
	9	IntelliSense: namespace "std" has no member "map"	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\station.h	16	15	Production Project 1
	10	IntelliSense: expected a ';'	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\station.h	16	18	Production Project 1
	11	IntelliSense: identifier "resourceMap" is undefined	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\station.h	17	2	Production Project 1
	12	IntelliSense: name followed by '::' must be a class or namespace name	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\station.h	19	2	Production Project 1
	13	IntelliSense: name followed by '::' must be a class or namespace name	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\station.h	20	2	Production Project 1
	14	IntelliSense: identifier "Entry" is undefined	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\station.h	28	19	Production Project 1
	15	IntelliSense: expected a declaration	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\yeardata.h	19	1	Production Project 1
	16	IntelliSense: qualified name is not allowed	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\yeardata.h	22	10	Production Project 1
	17	IntelliSense: expected a ';'	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\yeardata.h	22	18	Production Project 1
	18	IntelliSense: identifier "stationMap" is undefined	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\yeardata.h	23	2	Production Project 1
	19	IntelliSense: name followed by '::' must be a class or namespace name	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\yeardata.h	25	2	Production Project 1
	20	IntelliSense: a type qualifier is not allowed on a nonmember function	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\yeardata.h	25	50	Production Project 1
	21	IntelliSense: name followed by '::' must be a class or namespace name	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\yeardata.h	26	2	Production Project 1
	22	IntelliSense: a type qualifier is not allowed on a nonmember function	c:\Users\LOFT\source\repos\Production Project 1\Production Project 1\yeardata.h	26	48	Production Project 1
Last edited on
What's the first compilation error?
Error 1 error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...". C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets 64 5 Production Project 1
I haven't slept the whole night trying to figure out what is going on here :( because intellisense is pointing out tons of problems.
Last edited on
Well, the first thing you did wrong which is of no help to you at all at this point is write an awful lot of code without compiling it, such that now you've got a big mess. As a beginner, I would say you should be trying to compile and build roughly every time you enter a line of code.

Looks like you've simply got a big mess of a project, and you're trying to build it with badly configured tools. Intellisense is confused because your project is a mess. I would suggest creating a new project with a completely empty main and getting it to compile. At least then you've got somewhere to start and can begin adding in these headers and other files.


typedef std::map<int, class YearData*> yrMap; You should not have "class" in this line.

You've got circular includes that mean it's possible to try to compile headers in the wrong order such that they've never heard of the types; productiondb.cpp includes productiondb.h which includes entry.h which includes resource.h which includes monthdata.h which includes yeardata.h

Why does monthdata need to know about yeardata? You've just #included everything everywhere and made a big mess such that you can't even tell what order the header files will be seen in. You can start fixing it by sticking things like
1
2
3
class Entry;
class Station;
class everything_else;

into header files, but that's really just bodging over the top of the mess.

I suggest creating a new, empty project with an empty main and getting it to compile.

Then, add one cpp and one header to it, and try to build it. Slowly fix the errors the compiler tells you until you've got something that builds.
Topic archived. No new replies allowed.