'How to fix the Linker Tools Error LNK2001,LNK2019,LNK1120
The code contains 5 header files, attached here + implementation of the methods. What is the problem is with what I wrote?
Header 1
`#pragma once
#ifndef _COURSE_H_
#define _COURSE_H_
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
class Course
{
protected:
char* name;
char* lecturer;
int grade;
public:
Course();
Course(char* name, char* lecturer, int grade);
Course(const Course &c);
virtual ~Course();
};
#endif //_COURSE_H_`
Header 2
#pragma once
#ifndef _STUDENT_H_
#define _STUDENT_H_
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
class Student
{
protected:
char* name;
long id;
public:
Student();
Student(char* name, long id);
Student(const Student &s);
virtual ~Student();
};
#endif //_STUDENT_H_`
Header 3
#pragma once
#ifndef _STUDENT0_H_
#define _STUDENT0_H_
#define _CRT_SECURE_NO_WARNINGS
#include "Student.h"
using namespace std;
class Student0 : public Student
{
private:
bool is_short;
public:
Student0();
Student0(char* name, long id, bool is_short);
Student0(const Student0 &s0);
virtual ~Student0();
};
#endif //_STUDENT0_H_`
Header 4
`#pragma once
#ifndef _STUDENT1_H_
#define _STUDENT1_H_
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
#include "Student.h"
#include "Course.h"
class Student1 : public Student , public Course
{
private:
Course* c;
int size_c;
int year;
public:
Student1();
Student1(char* names1,long id, int size_C, Course* arr, int year);
Student1(const Student1 &s1);
virtual ~Student1();
};
#endif //_STUDENT1_H_`
Header 5
#pragma once
#ifndef _STUDENT2_H_
#define _STUDENT2_H_
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
#include "Student.h"
class Student2 : public Student
{
private:
char* thesis;
char* supervisor;
public:
Student2();
Student2(char* names2, long id , char* thesis, char* supervisor);
Student2(const Student2 &s2);
virtual ~Student2();
};
#endif //_STUDENT2_H_
#define _CRT_SECURE_NO_WARNINGS
#include "Course.h"
#include <string.h>
#include <iostream>
using namespace std;
Course::Course()
{
name = NULL;
lecturer = NULL;
grade = 0;
}
Course::Course(char* name, char* lecturer, int grade)
{
this->name = new char[strlen(name) + 1];
if (!this->name)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->name, name);
this->lecturer = new char[strlen(lecturer) + 1];
if (!this->lecturer)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->lecturer, lecturer);
this->grade = grade;
}
Course::Course(const Course &c)
{
this->name = new char[strlen(c.name) + 1];
if (!this->name)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->name, c.name);
this->lecturer = new char[strlen(c.lecturer) + 1];
if (!this->lecturer)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->lecturer, c.lecturer);
this->grade = c.grade;
}
Course:: ~Course()//virtual
{
delete []name;
delete []lecturer;
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include "Student.h"
#include <string.h>
using namespace std;
Student::Student()
{
name = NULL;
id = 0;
}
Student::Student(char* name, long id)
{
this->name = new char[strlen(name) + 1];
if (!this->name)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->name, name);
this->id = id;
}
Student::Student(const Student &s)
{
this->name = new char[strlen(s.name) + 1];
if (!this->name)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->name, s.name);
this->id = id;
}
Student:: ~Student()
{
delete []name;
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include "Student.h"
#include "Student0.h"
#include <string.h>
Student0::Student0() : Student()
{
is_short = false;
}
Student0::Student0(char* name,long id,bool is_short) : Student(name,id)
{
this->is_short = is_short;
}
Student0::Student0(const Student0 &s0) : Student(s0)
{
this->is_short = s0.is_short;
}
Student0 :: ~Student0()
{
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include "Student.h"
#include "Student1.h"
#include "Course.h"
#include <string.h>
Student1::Student1() : Student()
{
c=NULL;
size_c = 0;
year = 0;
}
Student1::Student1(char* names1, long id, int size_C, Course* arr, int year) : Student(names1,id)
{//nameC=name course
this->size_c = size_C;
c = new Course[size_c];
if (!c)
return;
for (int i = 0; i < size_c; i++)
{
c[i]=arr[i];
}
if (this->year < 1 || this->year >4)
{
cout << "The year need to be between 1-4" << endl;
}
else
this->year = year;
}
Student1::Student1(const Student1 &s1) : Student(s1) , Course(s1)
{
this->size_c = s1.size_c;
this->c = new Course[this->size_c];
if (!this->c)
{
cout << "no memory!!" << endl;
exit(1);
}
this->year = s1.year;
}
Student1 :: ~Student1()
{
delete []c;
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include "Student.h"
#include "Student2.h"
#include <string.h>
Student2::Student2() : Student()
{
thesis = NULL;
supervisor = NULL;
}
Student2::Student2(char* names2, long id, char* thesis, char* supervisor) : Student(names2,id)
{
this->thesis = new char[strlen(thesis) + 1];
if (!this->thesis)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->thesis, thesis);
this->supervisor = new char[strlen(supervisor) + 1];
if (!this->supervisor)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->supervisor, supervisor);
}
Student2::Student2(const Student2 &s2) : Student(s2)
{
this->thesis = new char[strlen(s2.thesis) + 1];
if (!this->thesis)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->thesis, s2.thesis);
this->supervisor = new char[strlen(s2.supervisor) + 1];
if (!this->supervisor)
{
cout << "no memory!!" << endl;
exit(1);
}
strcpy(this->supervisor, s2.supervisor);
}
Student2:: ~Student2()
{
delete []thesis;
delete []supervisor;
}
The question
A course class that describes a course that a student is studying, and contains the following fields:
- name - an array of characters that contains the name of the course.
- lecturer - an array of characters that contains the lecturer's name.
- grade - an integer that describes a grade.
A student class that describes a student and contains the following fields.
- name - an array of characters that contains the student's name.
- id - a long number that contains the student's ID card.
Student0 class describing a student in a preparatory program. A student in a preparatory school is also a student, and everything must be saved Preparatory student: *short_is - a Boolean value that determines whether the student is studying in a short (true) or long (false) preparatory course.
Department Student1 describes a undergraduate student. An undergraduate student is also a student, and there is Save for each undergraduate student:
- An array of objects from the Course class and its size, describing all the courses the student has studied.
- year - an integer between 1 and 4 that describes his school year.
Student2 department describing a graduate student. A graduate student is also a student, and should be kept For each graduate student:
- thesis - a string that describes the topic of the thesis.
- supervisor - a string that describes the thesis supervisor.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|