Program using class, Errors!

closed account (9L8T0pDG)
Please help me, I do not know how to fix this.

Here are the errors:
1>------ Build started: Project: qq, Configuration: Debug Win32 ------
1> q.cpp
1>c:\users\me\documents\visual studio 2010\projects\qq\qq\q.cpp(30): error C3861: 'input': identifier not found
1>c:\users\me\documents\visual studio 2010\projects\qq\qq\q.cpp(34): error C3861: 'Grade': identifier not found
1>c:\users\me\documents\visual studio 2010\projects\qq\qq\q.cpp(35): error C3861: 'output': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Here is the code that I can't fix:

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

const int CLASS_TOTAL_STUDENTS = 5; 

class StudentClass
{
public:
	StudentClass();
	int studentNumber;
	double firstQuiz;
	double secondQuiz;
	double gradeMidterm;
	double gradeFinal;
	double gradeAverage;
	char grade;

	void input(StudentClass& student);
	void Grade(StudentClass& student);
	void output(const StudentClass student);

};

int main()
{
  StudentClass student[CLASS_TOTAL_STUDENTS];

  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
      input(student[i]);
   
   {  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
    {
      Grade(student[i]);
      output(student[i]);
      cout << endl;
    }
  }
  return 0;
}

void input(StudentClass &student)
{
  cout << "Please Enter the Student's Number: ";
  cin >> student.studentNumber;
  cout << student.studentNumber << endl;
  cout << "Enter both 10 Point Quizes" << endl;
  cin >> student.firstQuiz >> student.secondQuiz;
  cout << student.firstQuiz << " " << student.secondQuiz << endl;
  cout << "Enter both 100 Point Midterm and Final. \n";
  cin >> student.gradeMidterm >> student.gradeFinal;
  cout << student.gradeMidterm << " " << student.gradeFinal <<endl;
}

void Grade(StudentClass& student)
{
  double quizAvg= (student.firstQuiz + student.secondQuiz)/2.0;
  double quizAvgNormalized = quizAvg * 10; 

  student.gradeAverage = student.gradeFinal * 0.5 + 
                    student.gradeMidterm * 0.25 +
                    quizAvgNormalized * 0.25;
  char letterGrade[]= "FFFFFFDCBAA";
  int index = static_cast<int>(student.gradeAverage/10);
  if(index < 0 || 10 <= index)
  {
    cout << "Grade entered resulted in an ERROR: "
         << student.gradeAverage << endl << "  ENDED.\n";
    abort();
  }
  student.grade = letterGrade[index];
}

void output(const StudentClass student)
{
  cout << "Grade for student number: "
       << student.studentNumber << endl
       << "Quiz grades are: "
       << student.firstQuiz  << " " << student.secondQuiz << endl
       << "The Exam grades are: " << student.gradeMidterm << " " << student.gradeFinal << endl
       << "Average: " << student.gradeAverage << endl
       << "letter grade is " << student.grade  << endl;
}
Last edited on
Input is a method, so it needs to be called on an instance of the class. student[i].input() You probably don't need any parameters for those methods.
1
2
3
4
5
6
7
class StudentClass {
 public:
    ...
    void input();
    void grade();
    void output();
};
Either that, or you want the methods to be static.
1
2
3
4
5
6
class StudentClass {
 public:
    ...
    static void input(Student &student);
    ...
};
closed account (9L8T0pDG)
I put that in the class and I got more errors. What did I do wrong?

I am still getting errors.

Please help me.
Last edited on
If you get errors then post them so people will be able to find out what the problem is.

When you are calling input(), grade(), and output(), you are calling a class' function. In order to call them, you need to create an instance of that class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// In header file
class StudentClass
{
StudentClass();
void input();
..
// In implementation cpp file
StudentClass::StudentClass()
{
     ..
}
void StudentClass::Input()
{
     ..
}
..
// In main cpp
StudentClass student1;
..
student1.input();


Or you can make the function static so you don't have to create an instance of that class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// In header file
class StudentClass
{
StudentClass();
static void input();
..
// In implementation cpp file
StudentClass::StudentClass()
{
     ..
}
void StudentClass::Input()
{
     ..
}
..
// In main cpp

StudentClass::input();


You get the idea.
closed account (9L8T0pDG)
Please tell me how to fix it.


Here are the errors:
1>------ Build started: Project: qqqqq, Configuration: Debug Win32 ------
1> qqqqqqqq.cpp
1>c:\users\me\documents\visual studio 2010\projects\qqqqq\qqqqq\qqqqqqqq.cpp(32): error C3861: 'input': identifier not found
1>c:\users\me\documents\visual studio 2010\projects\qqqqq\qqqqq\qqqqqqqq.cpp(36): error C3861: 'Grade': identifier not found
1>c:\users\me\documents\visual studio 2010\projects\qqqqq\qqqqq\qqqqqqqq.cpp(37): error C3861: 'output': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Here is my code:
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
#include <iostream> 
using namespace std;  

const int CLASS_TOTAL_STUDENTS = 5; 

class StudentClass
{
public:
	StudentClass();
	void input();
    void Grade();
    void output();
	int studentNumber;
	double firstQuiz;
	double secondQuiz;
	double gradeMidterm;
	double gradeFinal;
	double gradeAverage;
	char grade;
	
	void input(StudentClass & student);
	void Grade(StudentClass & student);
	void output(const StudentClass student);

};

int main()
{
  StudentClass student[CLASS_TOTAL_STUDENTS];
  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
      input(student[i]);
   
   {  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
    {
      Grade(student[i]);
      output(student[i]);
      cout << endl;
    }
  }
  return 0;
}

void input(StudentClass & student)
{
  cout << "Please Enter the Student's Number: ";
  cin >> student.studentNumber;
  cout << student.studentNumber << endl;
  cout << "Enter both 10 Point Quizes" << endl;
  cin >> student.firstQuiz >> student.secondQuiz;
  cout << student.firstQuiz << " " << student.secondQuiz << endl;
  cout << "Enter both 100 Point Midterm and Final. \n";
  cin >> student.gradeMidterm >> student.gradeFinal;
  cout << student.gradeMidterm << " " << student.gradeFinal <<endl;
}

void Grade(StudentClass & student)
{
  double quizAvg= (student.firstQuiz + student.secondQuiz)/2.0;
  double quizAvgNormalized = quizAvg * 10; 

  student.gradeAverage = student.gradeFinal * 0.5 + 
                    student.gradeMidterm * 0.25 +
                    quizAvgNormalized * 0.25;
  char letterGrade[]= "FFFFFFDCBAA";
  int index = static_cast<int>(student.gradeAverage/10);
  if(index < 0 || 10 <= index)
  {
    cout << "Grade entered resulted in an ERROR: "
         << student.gradeAverage << endl << "  ENDED.\n";
    abort();
  }
  student.grade = letterGrade[index];
}

void output(const StudentClass student)
{
  cout << "Grade for student number: "
       << student.studentNumber << endl
       << "Quiz grades are: "
       << student.firstQuiz  << " " << student.secondQuiz << endl
       << "The Exam grades are: " << student.gradeMidterm << " " << student.gradeFinal << endl
       << "Average: " << student.gradeAverage << endl
       << "letter grade is " << student.grade  << endl;
}
Last edited on
Did you read what I wrote? To call a function of a class you need to create an instance of that class:

1
2
StudentClass student1;
student1.input();
closed account (9L8T0pDG)
where do i put that?
Have you made any progress?
closed account (9L8T0pDG)
None at all Mr. Wolf.

I cant figure it out at all.
Did you create an instance of the StudentClass class to execute the input() and other functions?
closed account (9L8T0pDG)
I do not know where to put it.

Can you show me?
This is your code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

int main()
{
  StudentClass student[CLASS_TOTAL_STUDENTS];
  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
      input(student[i]);
   
   {  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
    {
      Grade(student[i]);
      output(student[i]);
      cout << endl;
    }
  }
  return 0;
}

where you have:
input(student[i]);
you need

student1.input(student[i]);

where student1 is an instance of StudentClass.
closed account (9L8T0pDG)

What did I do wrong Now?

Alright now I have new errors:

1>------ Build started: Project: qqqqq, Configuration: Debug Win32 ------
1> qqqqqqqq.cpp
1>qqqqqqqq.obj : error LNK2019: unresolved external symbol "public: void __thiscall StudentClass::output(class StudentClass)" (?output@StudentClass@@QAEXV1@@Z) referenced in function _main
1>qqqqqqqq.obj : error LNK2019: unresolved external symbol "public: void __thiscall StudentClass::Grade(class StudentClass &)" (?Grade@StudentClass@@QAEXAAV1@@Z) referenced in function _main
1>qqqqqqqq.obj : error LNK2019: unresolved external symbol "public: void __thiscall StudentClass::input(class StudentClass &)" (?input@StudentClass@@QAEXAAV1@@Z) referenced in function _main
1>qqqqqqqq.obj : error LNK2019: unresolved external symbol "public: void __thiscall StudentClass::input(void)" (?input@StudentClass@@QAEXXZ) referenced in function _main
1>qqqqqqqq.obj : error LNK2019: unresolved external symbol "public: __thiscall StudentClass::StudentClass(void)" (??0StudentClass@@QAE@XZ) referenced in function _main
1>c:\users\me\documents\visual studio 2010\Projects\qqqqq\Debug\qqqqq.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Here is my newer code:
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
#include <iostream> 
using namespace std;  

const int CLASS_TOTAL_STUDENTS = 5; 

class StudentClass
{
public:
	StudentClass();
	void input();
    void Grade();
    void output();
	int studentNumber;
	double firstQuiz;
	double secondQuiz;
	double gradeMidterm;
	double gradeFinal;
	double gradeAverage;
	char grade;
	
	void input(StudentClass & student);
	void Grade(StudentClass & student);
	void output(const StudentClass student);

};

int main()
{
  StudentClass student[CLASS_TOTAL_STUDENTS];
  StudentClass student1;
	student1.input();
  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
      student1.input(student[i]);;
   
   {  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
    {
      student1.Grade(student[i]);;
      student1.output(student[i]);
      cout << endl;
    }
  }
  return 0;
}

void input(StudentClass & student)
{
  cout << "Please Enter the Student's Number: ";
  cin >> student.studentNumber;
  cout << student.studentNumber << endl;
  cout << "Enter both 10 Point Quizes" << endl;
  cin >> student.firstQuiz >> student.secondQuiz;
  cout << student.firstQuiz << " " << student.secondQuiz << endl;
  cout << "Enter both 100 Point Midterm and Final. \n";
  cin >> student.gradeMidterm >> student.gradeFinal;
  cout << student.gradeMidterm << " " << student.gradeFinal <<endl;
}

void Grade(StudentClass & student)
{
  double quizAvg= (student.firstQuiz + student.secondQuiz)/2.0;
  double quizAvgNormalized = quizAvg * 10; 

  student.gradeAverage = student.gradeFinal * 0.5 + 
                    student.gradeMidterm * 0.25 +
                    quizAvgNormalized * 0.25;
  char letterGrade[]= "FFFFFFDCBAA";
  int index = static_cast<int>(student.gradeAverage/10);
  if(index < 0 || 10 <= index)
  {
    cout << "Grade entered resulted in an ERROR: "
         << student.gradeAverage << endl << "  ENDED.\n";
    abort();
  }
  student.grade = letterGrade[index];
}

void output(const StudentClass student)
{
  cout << "Grade for student number: "
       << student.studentNumber << endl
       << "Quiz grades are: "
       << student.firstQuiz  << " " << student.secondQuiz << endl
       << "The Exam grades are: " << student.gradeMidterm << " " << student.gradeFinal << endl
       << "Average: " << student.gradeAverage << endl
       << "letter grade is " << student.grade  << endl;
}
Last edited on
Your compiler can't find the functions StudentClass::StudentClass(), StudentClass::Input().. etc

When making class function declarations you have to include the name of the class so the compiler knows those functions belong to the specific class.

1
2
3
4
5
6
7
8
9
10
11
12
void StudentClass::input(StudentClass & student)
{
  cout << "Please Enter the Student's Number: ";
  cin >> student.studentNumber;
  cout << student.studentNumber << endl;
  cout << "Enter both 10 Point Quizes" << endl;
  cin >> student.firstQuiz >> student.secondQuiz;
  cout << student.firstQuiz << " " << student.secondQuiz << endl;
  cout << "Enter both 100 Point Midterm and Final. \n";
  cin >> student.gradeMidterm >> student.gradeFinal;
  cout << student.gradeMidterm << " " << student.gradeFinal <<endl;
}

Last edited on
Thank you Mr Wolf.

I still have errors.

1>------ Build started: Project: qqqqq, Configuration: Debug Win32 ------
1> qqqqqqqq.cpp
1>qqqqqqqq.obj : error LNK2019: unresolved external symbol "public: void __thiscall StudentClass::input(void)" (?input@StudentClass@@QAEXXZ) referenced in function _main
1>qqqqqqqq.obj : error LNK2019: unresolved external symbol "public: __thiscall StudentClass::StudentClass(void)" (??0StudentClass@@QAE@XZ) referenced in function _main
1>c:\users\me\documents\visual studio 2010\Projects\qqqqq\Debug\qqqqq.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



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

const int CLASS_TOTAL_STUDENTS = 5; 

class StudentClass
{
public:
	StudentClass();
	void input();
    void Grade();
    void output();
	int studentNumber;
	double firstQuiz;
	double secondQuiz;
	double gradeMidterm;
	double gradeFinal;
	double gradeAverage;
	char grade;
	
	void input(StudentClass & student);
	void Grade(StudentClass & student);
	void output(const StudentClass student);

};

int main()
{
  StudentClass student[CLASS_TOTAL_STUDENTS];
  StudentClass student1;
	student1.input();
  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
      student1.input(student[i]);;
   
   {  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
    {
      student1.Grade(student[i]);;
      student1.output(student[i]);
      cout << endl;
    }
  }
  return 0;
}

void StudentClass::input(StudentClass & student)
{
  cout << "Please Enter the Student's Number: ";
  cin >> student.studentNumber;
  cout << student.studentNumber << endl;
  cout << "Enter both 10 Point Quizes" << endl;
  cin >> student.firstQuiz >> student.secondQuiz;
  cout << student.firstQuiz << " " << student.secondQuiz << endl;
  cout << "Enter both 100 Point Midterm and Final. \n";
  cin >> student.gradeMidterm >> student.gradeFinal;
  cout << student.gradeMidterm << " " << student.gradeFinal <<endl;
}

void StudentClass::Grade(StudentClass & student)
{
  double quizAvg= (student.firstQuiz + student.secondQuiz)/2.0;
  double quizAvgNormalized = quizAvg * 10; 

  student.gradeAverage = student.gradeFinal * 0.5 + 
                    student.gradeMidterm * 0.25 +
                    quizAvgNormalized * 0.25;
  char letterGrade[]= "FFFFFFDCBAA";
  int index = static_cast<int>(student.gradeAverage/10);
  if(index < 0 || 10 <= index)
  {
    cout << "Grade entered resulted in an ERROR: "
         << student.gradeAverage << endl << "  ENDED.\n";
    abort();
  }
  student.grade = letterGrade[index];
}

void StudentClass::output(const StudentClass student)
{
  cout << "Grade for student number: "
       << student.studentNumber << endl
       << "Quiz grades are: "
       << student.firstQuiz  << " " << student.secondQuiz << endl
       << "The Exam grades are: " << student.gradeMidterm << " " << student.gradeFinal << endl
       << "Average: " << student.gradeAverage << endl
       << "letter grade is " << student.grade  << endl;
}
I deleted the functions you weren't using - void input(void), Grade(void), output(void) since they are in the way. You tried calling the input(void) function and the compiler couldn't find it.
void means the parenthesis are blank.

I added a declaration for your class function StudentClass().

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

const int CLASS_TOTAL_STUDENTS = 5; 

class StudentClass
{
public:
	StudentClass();
	int studentNumber;
	double firstQuiz;
	double secondQuiz;
	double gradeMidterm;
	double gradeFinal;
	double gradeAverage;
	char grade;
	
	void input(StudentClass & student);
	void Grade(StudentClass & student);
	void output(const StudentClass student);

};

int main()
{
  StudentClass student[CLASS_TOTAL_STUDENTS];
  StudentClass student1;
  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
      student1.input(student[i]);;
   
   {  for(int i = 0; i < CLASS_TOTAL_STUDENTS; i++)
    {
      student1.Grade(student[i]);;
      student1.output(student[i]);
      cout << endl;
    }
  }
  return 0;
}

StudentClass::StudentClass()
{
}

void StudentClass::input(StudentClass & student)
{
  cout << "Please Enter the Student's Number: ";
  cin >> student.studentNumber;
  cout << student.studentNumber << endl;
  cout << "Enter both 10 Point Quizes" << endl;
  cin >> student.firstQuiz >> student.secondQuiz;
  cout << student.firstQuiz << " " << student.secondQuiz << endl;
  cout << "Enter both 100 Point Midterm and Final. \n";
  cin >> student.gradeMidterm >> student.gradeFinal;
  cout << student.gradeMidterm << " " << student.gradeFinal <<endl;
}

void StudentClass::Grade(StudentClass & student)
{
  double quizAvg= (student.firstQuiz + student.secondQuiz)/2.0;
  double quizAvgNormalized = quizAvg * 10; 

  student.gradeAverage = student.gradeFinal * 0.5 + 
                    student.gradeMidterm * 0.25 +
                    quizAvgNormalized * 0.25;
  char letterGrade[]= "FFFFFFDCBAA";
  int index = static_cast<int>(student.gradeAverage/10);
  if(index < 0 || 10 <= index)
  {
    cout << "Grade entered resulted in an ERROR: "
         << student.gradeAverage << endl << "  ENDED.\n";
    abort();
  }
  student.grade = letterGrade[index];
}

void StudentClass::output(const StudentClass student)
{
  cout << "Grade for student number: "
       << student.studentNumber << endl
       << "Quiz grades are: "
       << student.firstQuiz  << " " << student.secondQuiz << endl
       << "The Exam grades are: " << student.gradeMidterm << " " << student.gradeFinal << endl
       << "Average: " << student.gradeAverage << endl
       << "letter grade is " << student.grade  << endl;
}


input(void) is different than input(StudentClass & student) so you have to be careful.
Last edited on
:') YOU ARE AWESOME!!!

One thing though, Should I make anything private?

Thank You
Private is good, so if you can get away with it then by all means.

Edit: But you could instead make the functions static so you don't have to create an instance of the class in order to use the functions. That way you don't have to do:

1
2
StudentClass student1;
student1.input(etc..);


instead you can just do:

StudentClass:input(etc..);
Last edited on
Thank You AdventWolf!

OP: You should really really read up on classes. There is a nice tutorial on this site (see link below.) If you don't make the time to learn C++ you won't; you can't just half-@$$ it. You should understand why you need an instance of your class, and what the difference between a function and a method (member function) is.

http://www.cplusplus.com/doc/tutorial
Topic archived. No new replies allowed.