Problems with my first class.

Hi! Sorry my first post is asking for help.
This is supposed to be able to work with a user's information and, in the end, calculate the student's GPA.

We've(We..the rest of my class) tried troubleshooting and looking up information but it's still not working out and I personally have no idea why.

I'm getting around 52 errors. Help?

Thanks!

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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// student.h

#ifndef _student_H
#define _student_H
#include <string.h>


class student
{
 public:
	  // constructors
	  student();               // default constructor
	  student(const student &); // copy constructor

	  // member functions
	  void   SetName(string);
	  string  GetName();
	  
	  void   SetClassi(int);
	  int   GetClassi();
	  
	  void   SetSid(string);
	  string   GetSid();
	  
	  void   SetCtake(int);
	  int   GetCtake();
	  
	  void   SetCcomp(int);
	  int   GetCcomp();
	  
	  void   SetQualpt(int);
	  int   GetQualpt();
	  
	  double CalcGPA();

 private:
	  // data
	  string Name;
	  int Classi;
      string Sid;
      int Ctake;
      int Ccomp;
      int Cualpt;
	  
};

student::student(){
      Name = "Name Here";
	  Classi = 1;
      Sid = "1234567";
      Ctake = 0;
      Ccomp = 0;
      Qualpt = 0;}
      
      // copy constructor
student::student(const student & Object)
{
  Name = Object.Name;
  Sid = Object.Sid;
  Classi = Object.Classi;
  Ctake = Object.Ctake;
  Ccomp = Object.Ccomp;
  Qualpt = Object.Qualpt;
}
// Method to set CredTaken
void student::SetCredTaken(float IncCtaken)
{
     Ctake = IncCtaken;
}

// Method to set Qualpt(quality points)
void student::SetQualPts(float IncQualpt)
{
     QualPt = IncQualpt;
}

// Method to set Ccomp(credits completed)
void student::SetCredComp(float IncCcomp)
{
     Ccomp = IncCcomp;
}

// Method to set Name
void student::SetName(string IncName)
{
     Name = IncName;
}

// Method to set Sid(student ID #)
void student::SetStudNum(string IncSid)
{
     Sid = IncSid;
}

// Method to set Classi(class classification)
void student::SetClassification(string IncClassi)
{
     Classi = IncClassi;
}

// Method to return Ctaken
int student::GetCtaken()
{
  return(Ctaken);
}

// Method to return QualPt
float student::GetQualpt()
{
  return(Qualpt);
} 

// Method to return Ccomp(credits completed)
int student::GetCcomp()
{
  return(Ccomp);
} 

// Method to return Name
string student::GetName()
{
  return(Name);
} 

// Method to return Sid(student ID #)
string student::GetSid()
{
  return(Sid);
} 

// Method to return Classi
int student::GetClassi()
{
  return(Classi);
} 

// Method to find GPA
float CalcGPA::CalcGPA()
{
      return(Qualpt / Ctaken);
}

#endif 
Fixed! Haha!

Instead of using "using namespace std" and "#include <string.h>", we changed everything to type oostring and "#include "oostring.cpp".

Apparently, this is a problem with Dev C++?

Still, anyone have any other input?

:D

Also, my code has alot of problems with variable consistency. Forgive that, please, I'm working on it. Misspellings, too.
Last edited on
Fixed:

But why do I have to use "oostring.h" in the test proggie and "oostring.cpp" in the class? If I try to use "oostring.cpp" for both, I get 71 linker errors.

Thanks!



To test class:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream.h>
#include "oostring.h"
#include "studentv2.h"


int main(){
    
    cout << "Hello world";
    
    system("pause");
    return 0;
}


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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// student.h

#ifndef _student_H
#define _student_H
#include "oostring.cpp"


class student
{
 public:
	  // constructors
	  student();               // default constructor
	  student(const student &); // copy constructor

	  // member functions
	  void   SetName(oostring);
	  oostring  GetName();
	  
	  void   SetClassi(int);
	  int   GetClassi();
	  
	  void   SetSid(oostring);
	  oostring   GetSid();
	  
	  void   SetCtaken(int);
	  int   GetCtaken();
	  
	  void   SetCcomp(int);
	  int   GetCcomp();
	  
	  void   SetQualpt(int);
	  int   GetQualpt();
	  
	  float CalcGPA();

 private:
	  // data
	  oostring Name;
	  int Classi;
      oostring Sid;
      int Ctaken;
      int Ccomp;
      int Qualpt;
	  
};

student::student(){
      Name = "Name Here";
	  Classi = 1;
      Sid = "1234567";
      Ctaken = 0;
      Ccomp = 0;
      Qualpt = 0;}
      
      // copy constructor
student::student(const student & Object)
{
  Name = Object.Name;
  Sid = Object.Sid;
  Classi = Object.Classi;
  Ctaken = Object.Ctaken;
  Ccomp = Object.Ccomp;
  Qualpt = Object.Qualpt;
}
// Method to set Ctaken
void student::SetCtaken(int IncCtaken)
{
     Ctaken = IncCtaken;
}

// Method to set Qualpt(quality points)
void student::SetQualpt(int IncQualpt)
{
     Qualpt = IncQualpt;
}

// Method to set Ccomp(credits completed)
void student::SetCcomp(int IncCcomp)
{
     Ccomp = IncCcomp;
}

// Method to set Name
void student::SetName(oostring IncName)
{
     Name = IncName;
}

// Method to set Sid(student ID #)
void student::SetSid(oostring IncSid)
{
     Sid = IncSid;
}

// Method to set Classi(class classification)
void student::SetClassi(int IncClassi)
{
     Classi = IncClassi;
}

// Method to return Ctaken
int student::GetCtaken()
{
  return(Ctaken);
}

// Method to return QualPt
int student::GetQualpt()
{
  return(Qualpt);
} 

// Method to return Ccomp(credits completed)
int student::GetCcomp()
{
  return(Ccomp);
} 

// Method to return Name
oostring student::GetName()
{
  return(Name);
} 

// Method to return Sid(student ID #)
oostring student::GetSid()
{
  return(Sid);
} 

// Method to return Classi
int student::GetClassi()
{
  return(Classi);
} 

// Method to find GPA
float student::CalcGPA()
{
      return(Qualpt / Ctaken);
}

#endif 
no no no, this is wrong. You will have all sorts of linker errors if you #include student.h in more than 1 file.

Here are some general guidelines:

- class bodies go in .h files
- function bodies go in .cpp files
- never include .cpp files

Obligatory link: http://www.cplusplus.com/forum/articles/10627/


The way to structure this would be like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// student.h

#ifndef _student_H
#define _student_H
#include "oostring.h"  // <- .h! don't include .cpp files!


class student
{
 public:
	  // constructors
	  student();               // default constructor
	  student(const student &); // copy constructor
  // ...
};

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
// student.cpp

#include "student.h"

 // put function bodies in the .cpp file

student::student(){
      Name = "Name Here";
	  Classi = 1;
      Sid = "1234567";
      Ctaken = 0;
      Ccomp = 0;
      Qualpt = 0;}



The reason you get linker errors when you #include cpp files is because this puts the function body in every cpp file. When a function exists in multiple cpp files, the linker sees this as multiple different functions all with the same name, so it doesn't know which one to use.
Topic archived. No new replies allowed.