Please help, Not sure what im doing wrong

I want to use a conditional statement to create the objects of my 2 derived class depending on the user's input and i got some error. I turned off linker.
STUDENT* s2 = NULL;
string option;
cin >> option;

if (option == "PART-TIME")
{
s2 = new PartTime;
}
else if (option == "FULLTIME")
{
s2 = new FullTime;
}
1>------ Build started: Project: Pp2 project2, Configuration: Debug Win32 ------
1>Source.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification
1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall PartTime::PartTime(void)" (??0PartTime@@QAE@XZ) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall FullTime::FullTime(void)" (??0FullTime@@QAE@XZ) referenced in function _main
1>c:\users\johnson\documents\visual studio 2013\Projects\Pp2 project2\Debug\Pp2 project2.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It seems the linker couldn't find your PartTime and FullTime default constructor. Didn't you create one or did you forget to add the file to the project?
forget do define class PartTime and FullTime ?
1
2
3
4
5
6
class PartTime  {
};

class FullTime {
};
Can you post the complete code?
I'm a lil afraid to post up my code...since i'll get laugh at. But I'm in need of help so..here's the code. Not entirely sure if there's any other error, but for now, i want to be able to create objects through a condition statement. Feel free to point out my mistakes. Still learning.

#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

class STUDENT //base class
{
public:
STUDENT();
~STUDENT();
STUDENT(char* fn, char* mn, char* ln)
{
firstname = fn;
middlename = mn;
lastname = ln;
}

protected:
char* firstname;
char* middlename;
char* lastname;

};

class PartTime: public STUDENT //derived class
{
public:
PartTime();
~PartTime();


void SetCourseCode()
{

int userinput;
std::cout << "Enter Amount of Subject Taken:";
std::cin >> userinput;
std::string display1 = "Enter CourseCode For Subject";
std::string display2 = "Enter CourseName For Subject";
std::string display3 = "Enter CourseHour For Subject";
std::string display4 = "Enter Course Letter Grade For Subject";
for (int i = 1; i < userinput; i++)
{
std:: cout << display1;
std::cin >> coursecode[i];
display1 += i;
std::cout << display2;
std::cin >> coursename[i];
display2 += i;
std::cout << display3;
std::cin >> coursehour[i];
totalCHrs += i;
display3 += i;
std::cout << display4;
std::cin >> courselettergrade[i];
}
}

double StudentGPA(int x)
{
double gpa;
gpa = totalGP / totalCHrs;
}

char* getFirstName()
{
return firstname;
}
char* getMiddleName()
{
return middlename;
}
char* getLastName()
{
return lastname;
}

private:
std::string coursecode[5];
std::string coursename[5];
std::string coursehour[5];
std::string courselettergrade[5];
double totalGP = 0;
double totalCHrs = 0;
};

class FullTime : public STUDENT //derived class
{
public:
FullTime();
~FullTime();


void SetCourseCode()
{

int userinput;
std::cout << "Enter Amount of Subject Taken:";
std::cin >> userinput;
std::string display1 = "Enter CourseCode For Subject";
std::string display2 = "Enter CourseName For Subject";
std::string display3 = "Enter CourseHour For Subject";
std::string display4 = "Enter Course Letter Grade For Subject";
for (int i = 1; i < userinput; i++)
{
std::cout << display1;
std::cin >> coursecode[i];
display1 += i;
std::cout << display2;
std::cin >> coursename[i];
display2 += i;
std::cout << display3;
std::cin >> coursehour[i];
totalCHrs += i;
display3 += i;
std::cout << display4;
std::cin >> courselettergrade[i];
}
}

double StudentGPA(int x)
{
double gpa;
gpa = totalGP / totalCHrs;
}

char* getFirstName()
{
return firstname;
}
char* getMiddleName()
{
return middlename;
}
char* getLastName()
{
return lastname;
}

private:
std::string coursecode[8];
std::string coursename[8];
std::string coursehour[8];
std::string courselettergrade[8];
double totalGP = 0;
double totalCHrs = 0;
};


int main()
{
char firstname[20];
char middlename[20];
char lastname[20];


cout << "Enter Student's First Name:" << endl;
cin.getline(firstname, 20);
cout << "Enter Student's Middle Name:" << endl;
cin.getline(middlename, 20);
cout << "Enter Student's Last Name" << endl;
cin.getline(lastname, 20);




STUDENT s1(firstname, middlename, lastname);

STUDENT* s2 = NULL;
string option;
getline(cin, option);
if (option == "PART-TIME")
s2 = new PartTime;
else if (option == "FULLTIME")
s2 = new FullTime;
delete s2;
}
you might wonder why the derive class looks so similar.. well the idea is that user to select either part time or full time since their credit hours are different. So whichever one the user select will do the work. So if they select part time, then part time object will be created and the full time class will just sit there. There's a lot of stuff i erased becuz i was trying to get the last part of the program working...so i erase there and there to try find out the reason. I'll have to restore them bk to how it was..the derive class and others.
As I guessed. Your PartTime and Fulltime constructors are missing + the STUDENT destructor.
You declared PartTime and Fulltime constructors but don't implement them.

http://www.cprogramming.com/declare_vs_define.html
http://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration
so you mean i have to put something like this

PartTime(){};

im missing the {} right?
yup, i changed all mines and added the {} empty body
its now working.
Thank you very much.
yup, i changed all mines and added the {} empty body

There's actually no need to do that. You can just remove the declarations for those default constructors, if the bodies are empty. The compiler will create them for you.

The problem was because, as Thomas said, you declared them, but didn't implement them. Do neither, or do both.
Last edited on
thanks for reminding me something important.
You're welcome - glad it worked!
Topic archived. No new replies allowed.