trouble with user defined namespace

Hey I have a problem with my homework assignment



Program Description:

Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy.
and the second namespace globalType fys should derive the class level based on a four year school policy.






Four Year School Policy:
Freshman 0-29 credits Sophomore 30-59 credits
Junior 60-89 credits Senior 90 or more credits

Two Year School Policy:
Freshman 0-29 credits Sophomore 30 or more credits

NOTE : use ignore() function with ifstream objects whenever you want to ignore the newline character.
For example :
ifstream transferSchoolFile ;
transferSchoolFile.open("student_status.txt", ios::in);

while( !transferSchoolFile.eof())
{
getline(transferSchoolFile,name) ;
transferSchoolFile >> id >> credits;
transferSchoolFile.ignore(); //Used here to ignore the newline character.
….
}

I did this in parts so I got it working with a four year criteria without the user defined name spaces.

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
include <iostream>
#include <fstream>
#include <string>

using namespace std;

enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };

int main()
{
	string  uplevel, name;
	int noc, id, i;

	
	class_level level = FRESHMAN;

	ifstream transferSchoolFile;
	transferSchoolFile.open("student_status.txt", ios::in);



	//check for error
	if (transferSchoolFile.fail()){
		cerr << "Error opening file" << endl;
		exit(1);

	}
	
	for (i = 0; i < 4; i++)
	{
	
		
			getline(transferSchoolFile, name);
			transferSchoolFile >> id >> noc;
			transferSchoolFile.ignore();
		
		
		if (noc < 30)
		{
			level = FRESHMAN;
		}
		else if (noc < 60 && noc > 29)
		{
			level = SOPHOMORE;
		}
		else if (noc > 59 && noc < 90)
		{
			level = JUNIOR;
		}
		else
			level = SENIOR;
		switch (level)
		{
		case FRESHMAN:
			uplevel = "Freshman";
			break;

		case SOPHOMORE:
			uplevel = "Sophomore";
			break;

		case JUNIOR:
			uplevel = "Junior";
			break;
		
		default:
			uplevel = "Senior";



		}


		cout << name << " " << id << "        " << noc << " " << uplevel << endl;

	}

	system("pause");
	return 0;

}

So that worked fine then I tried with name spaces -

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <fstream>
#include <string>



using namespace std;

enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
class_level classLevel;


namespace tys

{

	class_level deriveClassLevel(int noc)
	{
		if (noc >= 0 && noc <= 29)
		{
			classLevel = FRESHMAN;
		
		}
		else
		{
			classLevel = SOPHOMORE;
			

		}

		return classLevel;
		
	
	}
	namespace fys
	{
		class_level deriveClassLevel(int noc)
		{
			if (noc >= 0 && noc <= 29)
			{
				classLevel = FRESHMAN;
				
			}
			else if (noc >= 30 && noc <= 59)
			{
				classLevel = SOPHOMORE;
			
			}
			else if (noc >= 60 && noc <= 89)
			{
				classLevel = JUNIOR;
				
			}
			else
			{
				classLevel = SENIOR;
				
			}
			
			return classLevel;
		}
		using namespace tys;
		int main()
		{
			string uplevel, name;
			int noc, id, i;
			
			class_level level = FRESHMAN;

			ifstream transferSchoolFile;
			transferSchoolFile.open("student_status.txt", ios::in);


			//check for error
			if (transferSchoolFile.fail()){
				cerr << "Error opening file" << endl;
				exit(1);

			}

			for (i = 0; i < 4; i++)
			{

				getline(transferSchoolFile, name);
				transferSchoolFile >> id >> noc;
				transferSchoolFile.ignore();
		
				switch (level)
				{
				case FRESHMAN:
					uplevel = "Freshman";
					break;

				case SOPHOMORE:
					uplevel = "Sophomore";
					break;

				case JUNIOR:
					uplevel = "Junior";
					break;

				default:
					uplevel = "Senior";



				}

				cout << name << " " << id << "        " << noc << " " << uplevel << endl;
			}

			system("pause");
			return 0;
		}
	}
}



I know I have some stuff to mess around with but I am currently stuck with two errors, first -

Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup C:\Users\stephen\Documents\Visual Studio 2013\Projects\input\ConsoleApplication1\MSVCRTD.lib(crtexe.obj) ConsoleApplication1

then -

Error 2 error LNK1120: 1 unresolved externals C:\Users\stephen\Documents\Visual Studio 2013\Projects\input\Debug\ConsoleApplication1.exe ConsoleApplication1

I have googled these errors but so far other peoples solutions didnt seem to help me. Can anyone help me out real fast? Thank you!

Well turns out I had my } miss placed so my main was inside my namespace in case anyone runs across this in the future. Thank You!
Topic archived. No new replies allowed.