using class functions

I'm in the final week of my online intro to programming class. I haven't had any issues all semester, which is good because my professor does not help his students at all. It hasn't been an issue, but I can't figure out this last assignment. I'm not looking for someone to give me the answer, just help to figure it out. Our book doesn't have any examples similar to our assignment. I looked online and none of the people who have had questions about this have gotten very good answers or they had different problems than I am having. I'm not sure if I have a simple/stupid problem or if this last chapter just went straight over my head.

The compiler error message is- multiple definition of 'TermPaper::TermPaper()'

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
// TermPaper.h

#include <string>
using namespace std;
#ifndef _TermPaper
#define _TermPaper
class TermPaper
{
   private:
	   string fName; // first name
	   string lName; // last name
	   string subject; // subject of the paper
	   char letterGrade; // assigned letter grade
   public:
	   TermPaper( );
	   void setFname(string fN);
	   void setLName(string lN);
	   void setSubject(string sub);
	   void setLetterGrade(char grade);
	   string  getFname( );
	   string getLName( );
	   string getSubject( );
	   char getLetterGrade( );
};
#endif 


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
//Termpaper.cpp
#include <cstdlib>
#include <iostream>
#include "Termpaper.h"

using namespace std;

TermPaper::TermPaper( )
{
  fName = "";
  lName = "";
  subject = "";
  letterGrade = 'F';
}
void TermPaper::setFname(string fN)
{
   fName = fN;
}
void TermPaper::setLName(string lN)
{
  lName = lN;
}
void TermPaper::setSubject(string sub)
{
  subject = sub;
}
void TermPaper::setLetterGrade(char grade)
{
  letterGrade = grade;
}
string  TermPaper::getFname( )
{
  return fName;
}
string TermPaper::getLName( )
{
  return lName;
}
string TermPaper::getSubject( )
{
  return subject;
}
char TermPaper::getLetterGrade( )
{
  return letterGrade;
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
// Pseudocode PLD Chapter 10 #3
// Start
//     Declarations
//       TermPaper  paper1
//       string firstName
//       string lastName
//       string subject
//       character grade
//     output "Please enter first name.  "
//     input firstName
//     output "Please enter last name.  "
//     input lastName
//     output "Please enter subject.  "
//     input subject
//     output "Please enter letter grade.  "
//     input grade
//     Set the first name for paper1
//     Set the last name for paper1
//     Set the subject for paper1
//     Set the letter grade for paper1
//     output "First Name: ", paper1.getFirstName()
//     output "Last Name: ", paper1.getLastName()
//     output "Subject: ", paper1.getSubject()
//     output "Grade: ", paper1.getGrade()
// Stop

#include <iostream>
#include <string>
#include <cstdlib>
#include "TermPaper.h"
#include "TermPaper.cpp"
using namespace std;
int main()
{
       TermPaper paper1;
       string fName;
       string lName;
       string subject;
       char letterGrade;
       
       cout << "Please enter first name. " << endl;
       cin >> fName;
       cout << "Please enter last name. " << endl;
       cin >> lName;
       cout << "Please enter subject. " << endl;
       cin >> subject;
       cout << "Please enter letter grade. " << endl;
       cin >> letterGrade;
       
       paper1.setFname(fName);
       paper1.setLName(lName);
       paper1.setSubject(subject);
       paper1.setLetterGrade(letterGrade);
       
       cout << "First Name: " << paper1.getFname() << endl;
       cout << "Last Name: " << paper1.getLName() << endl;
       cout << "Subject: " << paper1.getSubject() << endl;
       cout << "Grade: " << paper1.getLetterGrade() << endl;
    
       system("PAUSE");
       return 0;
}
Last edited on
You should never have to include .cpp files. Include the .h file instead.
Wow. The professor specifically told us to add it to the project. Thank you!
Topic archived. No new replies allowed.