-4

So I am trying to call a function which creates an assessment class object within the newStudent function. Ideallly the aim is for the newStudent function to run and after it reaches level selection it would call the respective makeAssess functions. Each of the makeAssess functions would then recursively call themselves until the total weighting of each level is 100 and then move onto the next makeAssess function. All the makeAssess functions were already defined at the start of the program.

Edit: Iam using CodeBlocks with a GNU GCC compiler. The two errors are "|undefined reference to `makeassessH()'|" and "|error: ld returned 1 exit status|"

MPE:

//Relevant libraries
#include <iostream>
#include <fstream>

using namespace std;

int option;

void newStudent();
void makeassessH();
void makeassessI();
void makeassessC();

class Student {
public:
    int stuNum;

    std::string stuName;

    int startDate;

    int endDate;

    string progofStudy;

    char level;
};

class Assessment{
public:
    std::string title;

    int weight;

    double grade;

    string deadline;
};

int main()
{
//The option page
while (option != 5) {
    cout << "\nPlease choose an option\n"
    "1. Add new students\n"
    "2. Student Login\n"
    "3. Staff Login\n"
    "4. Admin View\n"
    "5. Exit\n"
    "Enter option: ";

    cin >> option;

    if (option == 1) {
        newStudent();

    } else if (option == 5)
           return 0;

    }
}


void newStudent() {
    Student stu;
        string studentName = stu.stuName;

        cout << "Please enter in your student number: ";
        cin >> stu.stuNum;

        cout << "Please enter in your name: ";
        cin.ignore();
        getline (cin, studentName);

        cout << "Please enter in your start date: ";
        cin >> stu.startDate;

        cout << "Please enter in your end date: ";
        cin >> stu.endDate;

        cout << "Please enter in your programme of study: ";
        cin.ignore();
        getline(cin, stu.progofStudy);

        cout << "Please enter your level of study: ";
        cin >> stu.level;

        if(stu.level == toupper('h')){
            makeassessH();
            makeassessI();
            makeassessC();
        }else if (stu.level == toupper('i')){
            makeassessI();
            makeassessC();

        }else if(stu.level == toupper('c')) {
            makeassessC();
        }
}

void makeassesH(){
    Assessment assessmentH;

    cout << "Assessment title: ";
    cin.ignore();
    getline (cin, assessmentH.title);

    cout << "Assessment weighting: ";
    cin >> assessmentH.weight;

    cout << "Assessment grade: ";
    cin >> assessmentH.grade;

    cout << "Assessment deadline: ";
    cin >> assessmentH.deadline;

}

void makeassessI(){
    Assessment assessmentI;

    cout << "Assessment title: ";
    cin.ignore();
    getline (cin, assessmentI.title);

    cout << "Assessment weighting: ";
    cin >> assessmentI.weight;

    cout << "Assessment grade: ";
    cin >> assessmentI.grade;

    cout << "Assessment deadline: ";
    cin >> assessmentI.deadline;
}
void makeassessC(){
    Assessment assessmentC;

    cout << "Assessment title: ";
    cin.ignore();
    getline (cin, assessmentC.title);

    cout << "Assessment weighting: ";
    cin >> assessmentC.weight;

    cout << "Assessment grade: ";
    cin >> assessmentC.grade;

    cout << "Assessment deadline: ";
    cin >> assessmentC.deadline;

    int totalWeight = totalWeight + assessmentC.grade;
}
LGGawd
  • 1
  • 1
  • A [mre] would help a lot in getting an answer about the code you are compiling. – Drew Dormann Aug 08 '22 at 20:43
  • There is nothing in your post that is adequate to connect to an undefined reference error. Even more so since that error message is not being reproduced in full in the post. Most undefined reference error questions boil down to [this](https://stackoverflow.com/q/12573816/631266). – Avi Berger Aug 08 '22 at 20:46
  • I strongly suspect the full error message said more than `Undefined reference error`. It likely described the specific problem. – Drew Dormann Aug 08 '22 at 20:50
  • As a side note, the functions that you provide in the post set up objects as local variables that are automatically destroyed at function exit with no use of them or way to use them in your program. This might just be an artifact of simplifying your code for the post, in which case it would be a non-issue. – Avi Berger Aug 08 '22 at 20:52
  • Post-edit, `int totalWeight = totalWeight + assessmentC.grade;` is guaranteed Undefined Behavior. Regarding the error message you are getting, we still can not see the full error message you are asking about. The part of the message that describes _what is wrong_ is missing, so we only know that _something_ is wrong. – Drew Dormann Aug 08 '22 at 21:17
  • Apologies I have added in the code now and the copied error messages. – LGGawd Aug 08 '22 at 21:20
  • The error message is telling you (and us all now) that you have _declared_ a function named `void makeassessH()`, but you never _defined_ it. You **do** have a function named `void makeassesH()`, but that's not the same spelling. Providing the actual error message would have solved this mystery quickly. – Drew Dormann Aug 08 '22 at 21:28
  • Wow thank you so much. I was stuck on this for over an hour and it was something as silly as one missing letter. – LGGawd Aug 08 '22 at 21:31

1 Answers1

1

The error message is telling you (and us all now) that you have declared a function named

void makeassessH()

but you never defined it. You do have a function named

void makeassesH()

but that's not the same spelling.

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180