我有"未解决的外部因素"

时间:2014-10-29 17:42:49

标签: unresolved-external

    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>

    using namespace std;

    const int STUDENTS = 100;

    struct studentType
    {
        string fname;
        string lname;
        int test1;
        int test2;
        int test3;
        int test4;
        double average;
        char grade;
    };

    void initRecords(studentType students[]);
    int readData(studentType students[]);
    double getStudentAverageGrade(studentType aStudent);
    char getGrade(double average);
    void sortRecords(studentType students[], int totalStudents);
    void swapRecords(studentType& aStudent, studentType& bStudent);
    void writeRecords(studentType students[], int totalStudents);
    void drawLine(ofstream& fout, char ch, int width);
    void checkRecords(studentType students[], int totalStudents);
    int findMax(int, int);
    int findMin(int, int);

    int main()
    {
        int totalStudents = 0;
        studentType students[STUDENTS];
        initRecords(students);
        totalStudents = readData(students);
        checkRecords(students, totalStudents);
        sortRecords(students, totalStudents);
        cout << endl << "after sorting..." << endl;
        checkRecords(students, totalStudents);
        writeRecords(students, totalStudents);
        cout << "Done!" << endl;
        system("pause");
        return 0;
    }

    void initRecords(studentType students[])
    {
        for (int i = 0; i < STUDENTS; i++)
        {
            students[i].fname = "AA";
            students[i].lname = "ZZ";
            students[i].grade = 'F';
            students[i].test1 = 0;
            students[i].test2 = 0;
            students[i].test3 = 0;
            students[i].test4 = 0;
            students[i].average = 0.0;
        }
    }

    int readData(studentType students[])
    {
        ifstream fin;
        string fileName;
        int i;
        cout << "Enter filename: ";
        cin >> fileName;
        fin.open(fileName);
        if (!fin)
        {
            cout << "File does not exist!" << endl;
            cin.get();
            cin.get();
            exit (0);
        }
        i = 0;
        while (fin && i < STUDENTS)
        {
            fin >> students[i].fname >> students[i].lname >> students[i].test1 >> students[i].test2 >> students[i].test3 >> students[i].test4;

            if (!fin)
                break;

            students[i].average = getStudentAverageGrade(students[i]);
            students[i].grade = getGrade(students[i].average);
            i += 1;
        }
        fin.close();
        return i;
    }

    void checkRecords(studentType students[], int totalStudents)
    {
        for (int i = 0; i < totalStudents; i++)
        {
            cout << students[i].fname << " " << students[i].lname << " " << students[i].test1 << " " << students[i].test2 << " " << students[i].test3 << " " << students[i].test4 << " " << students[i].average << " " << students[i].grade << endl;

        }
    }

我有多次使用多个程序出现此错误,它似乎来去匆匆,我不完全理解未解决的外部错误,我之前已经搜索过它的帮助,似乎无法找到任何合法的建议,我不是要求任何人做我的功课,我只是想有人指出造成这个错误的原因,以及可能的解决方法。非常感谢任何帮助,提前谢谢。

更新:错误消息错误1错误LNK2019:未解析的外部符号&#34; double __cdecl getStudentAverageGrade(struct studentType)&#34; (?getStudentAverageGrade @@ YANUstudentType @@@ Z)在函数&#34; int __cdecl readData(struct studentType * const)&#34;中引用。 (?readData @@ YAHQAUstudentType @@@ Z)c:\ Users \ cpsalazar \ documents \ visual studio 2013 \ Projects \ Assignment7.cpp \ Assignment7.cpp \ Assignment7.obj Assignment7.cpp

sortRecords,writeRecords和getGrade还有3个。

0 个答案:

没有答案