2014-11-02 103 views
0
  //My name is Chris Salazar and this is Assignment 7. This program is an upgraded grading program 
    #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 argc,char** argv) 
    { 
     int totalStudents = 0; 
     studentType students[STUDENTS]; 
     initRecords(students); 
     totalStudents = readData(students); 
     checkRecords(students, totalStudents); 
     sortRecords(students, totalStudents); 
     cout << "after sorting..." << endl; 
     checkRecords(students, totalStudents); 
     writeRecords(students, totalStudents); 
     cout << "Done!" << endl; 
     system("pause"); 
     return 0; 
    } 

    int readData(studentType students[]) 
    { 
     ifstream fin; 
     string fileName; 
     int i; 
     cout << "Enter filename: "; 
     cin >> fileName; 
     fin.open(fileName); 
     //if (!fin) 
     //{ 
     // cout << "FILE NOT PRESENT" << 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 writeRecords(studentType students[], int totalStudents) 
    { 
     string fileName; 
     int i = 0; 
     ofstream fout; 
     cout << "Enter a file name to write to: " << endl; 
     getline(cin, fileName); 
     cin >> fileName; 
     fout.open(fileName); 
     while (fout && i < STUDENTS) 
     { 
      fout << STUDENTS << students[11].fname << " "; 
      fout << STUDENTS << students[11].lname << " "; 
      fout << STUDENTS << students[11].test1 << " "; 
      fout << STUDENTS << students[11].test2 << " "; 
      fout << STUDENTS << students[11].test3 << " "; 
      fout << STUDENTS << students[11].test4 << " "; 

       //<< students[i].lname << students[i].test1 << students[i].test2 << students[i].test3 << students[i].test4; 
      i += 1; 

     } 

    } 

我的'writeRecords'函數沒有返回任何準確的信息,而是返回隨機數字/字母。這不是我的全部代碼,並且爲了讓任何想尋求幫助的人閱讀而減少閱讀。任何幫助是極大的讚賞。文件無法將精確數據寫入文本文件

+0

可能重複(http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-doi-i-fix) – 2014-11-02 05:41:30

回答

2

您函數聲明:

void sortRecords(studentType students[], int totalStudents); 

你的函數定義不匹配:?什麼是未定義參考/解析的外部符號錯誤,如何修復它]的

void sortRecords(studentType students, int totalStudents[]) 
+0

謝謝,我不能相信我沒有明白。 – 2014-11-02 05:31:20