error LNK2001: unresolved external symbol

This is the first error I'm getting. But I think I'm going to need a lot of help on this one. I feel pretty lost.

Here's the beginning of my code. Then I'm typing out what my assignment is.

Any/all help is GREATLY appreciated!

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
#include <iostream>
#include <stdio.h>
#include <conio.h>

using namespace std;
class student
{
	private :
		int nr;
		static int count;
		char name[20];
		int age;
		char phone [11];
		
	public :
		student() : nr(count)
		{
			++count;
		}
			int getID() {return nr;}
			static int getCount() {return count;}

		void Getdata()
		{
			cout << "Enter Student Name  "; cin >> name;
			cout << "Enter Student Age  "; cin >> age;
			cout << "Enter Student Phone Number  "; cin >> phone;             
		}             
		void Putdata()
		{                   
			cout << "Student name      :" << name;
			cout << "Student age  :" << age;
			cout << "Student phone number     :" << phone;
		}
};
int  main()
{      
	student s;      
	s.Getdata();      
	s.Putdata();
	return 0;
}


Assignment:
Create a class, called studentClass. It should have following data members:
• Name
• Age
• Telephone Number
It should also have member function to set and display these data members. It should have two constructors; one a default constructor which sets Name to blank, Age to 0 and Telephone Number to blank and other constructor should have three parameters which sets the value of these three data members to the values passed in the parameters. 
This class should also have a static data member which keeps track how may objects of this class have been created. 
Write a test program (main), which creates individual objects of this class (like studentClass a, studentClass b), creates objects using new operator, creates array of the objects like (studentClass c[5]), delete the objects created by new operator. After each of these operations, please display the total number of objects at each stage using the static data member.
The static variable needs to be created somewhere, once, because it is not created each time an instance of the class is created like all the non-static variables.

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
#include <iostream>
#include <stdio.h>
#include <conio.h>

using namespace std;
class student
{
	private :
		int nr;
		static int count;
		char name[20];
		int age;
		char phone [11];
		
	public :
		student() : nr(count)
		{
			++count;
		}
			int getID() {return nr;}
			static int getCount() {return count;}

		void Getdata()
		{
			cout << "Enter Student Name  "; cin >> name;
			cout << "Enter Student Age  "; cin >> age;
			cout << "Enter Student Phone Number  "; cin >> phone;             
		}             
		void Putdata()
		{                   
			cout << "Student name      :" << name;
			cout << "Student age  :" << age;
			cout << "Student phone number     :" << phone;
		}
};

int student::count = 0;

int  main()
{      
	student s;      
	s.Getdata();      
	s.Putdata();
	return 0;
}
Is this how it is supposed to be? How do I get the Count working for the student 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
//Count header file

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include "Student.h"

using namespace std;

class Count
{
	private :
		int nr;
		static int count;

	public :

		Count() : nr(count)
		{
			++count;
		}
			int getID() {return nr;}
			static int getCount() {return count;}
}


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
//Student header file
#ifndef Student_H
#define Student_H
#include <iostream>
#include <string>

using namespace std;

//declaration section
class Student {
      private:
              string FirstName;
              string LastName;
 			  string Phone;
			  int Age;			
	
//interface
      public:
		    void getData()	//request user data input
			{
				cout << "Enter student first name: ";
				cin >> FirstName;
				cout << "Enter student last name: ";
				cin >> LastName;
				cout << "Enter student telephone number:  ";
				cin >> Phone;
				cout << "Enter student age:  ";
				cin >> Age;
			}
			void displayData()
			{                   
			cout << "Student name: " << FirstName << " " << LastName << endl;
			cout << "Student age: " << Age << endl;
			cout << "Student phone number: " << Phone << endl;
			}
};
#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Student Main file

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include "Student.h"
#include "Count.h"

;using namespace std;


int  main()
{      
	Student s;      
	s.getData();      
	s.displayData();
return 0;
}
I tried adding the constructors. Am I doing this correctly?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//Count header file

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include "Student.h"

using namespace std;

class Count
{
	private :
		int nr;
		static int count;

	public :

		Count() : nr(count)
		{
			++count;
		}
			int getID() {return nr;}
			static int getCount() {return count;}
}

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
//Student header file
#ifndef Student_H
#define Student_H
#include <iostream>
#include <string>

using namespace std;

//declaration section
class Student {
      private:
              string FirstName;
              string LastName;
 			  string Phone;
			  int Age;			
//interface
      public:
		  Student();
		  Student (string, string, string, int);  //constructor
		  void setStudentFirstName(string);
		  void setStudentLastName(string);
		  void setStudentPhone(string);
		  void setStudentAge(string);
		  void getData()	//request user data input
			{
				cout << "Enter student first name: ";
				cin >> FirstName;
				cout << "Enter student last name: ";
				cin >> LastName;
				cout << "Enter student telephone number:  ";
				cin >> Phone;
				cout << "Enter student age:  ";
				cin >> Age;
			}
			void displayData()
			{                   
			cout << "Student name: " << FirstName << " " << LastName << endl;
			cout << "Student age: " << Age << endl;
			cout << "Student phone number: " << Phone << endl;
			}
};

//implementation
Student::Student() {
}

Student::Student (string Fname, string Lname, string Tphone, int Sage) {
	FirstName = Fname;
	LastName = Lname;
	Phone = Tphone;
	Age = Sage;
}
void Student::setStudentFirstName (string Fname) {
	FirstName = Fname;
}
void Student::setStudentLastName (string Lname) {
	LastName = Lname;
}
void Student::setStudentPhone (string Tphone) {
	Phone = Tphone;
}
void Student::setStudentAge (int Sage) {
	Age = Sage;
}

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Student Main file

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include "Student.h"
#include "Count.h"

;using namespace std;


int  main()
{      
	Student s;
	s.setStudentFirstName(NULL);
	s.setStudentLastName(NULL);
	s.setStudentPhone(NULL);
	s.setStudentAge(0);
	s.getData();      
	s.displayData();
	Count();
return 0;
}
I already showed you. You have to create the variable count somewhere. Because it is static it does not get created with the rest of the class. Go back to the code I posted and look at line 37.
omg, I totally missed your line 37. I even checked what you'd posted line by line with my code (supposedly). Ugh! Sorry about that.

Ok, so I'll delete my Count class and use your line 37 instead.

Thank you!

What about my "two constructors; one a default constructor which sets Name to blank, Ag to 0 and Telephone Number to blank and other constructor should have three parameters which sets the balue of these three data members to the values passed int he paramaeters"

Did I add those correctly in the header and cpp files above?
Topic archived. No new replies allowed.