2016-12-08 5 views
0

Я начинаю C++, не знаю на C++. Я пишу код для ученика и модуля. Требование - это отобразить модуль и ученика с окончательным счетом, а также дублирование. Когда я пишу случай 5 и случай 6, после компиляции он показывает ошибку ниже.ошибка C2360: ошибка C2361: ошибка C2039:

ошибка C2360: инициализация «код» пропускается «случай» этикетки см декларация «Код» ошибка C2361: инициализация «код» пропускается «по умолчанию» ярлыком см декларирование «код»

ошибка C2039: 'GetId': не является членом 'станд :: вектор < _Ty>' с [_Ty = Student]

ошибка C2039: 'getModule': не является членом «станд: : вектор < _Ty> ' с [_Ty = Student]

main.cpp

#include <iostream> 
#include <fstream> 
#include <string> 
#include <vector> 
#include <sstream> 
#include <algorithm> 
#include <cmath> 
#include <vector> 
#include "Student.h" 
#include "Module.h" 
using namespace std; 

void printMenu(); 
vector<Student> readFile(); 
void liststudentRecord(vector<Student>); 
string trim(string); 
bool isValidClasscode(string s); 
bool isvalidStudentid(string s); 
bool test1Ascending(Student s1, Student s2); 
bool test1Desscending(Student s1, Student s2); 
bool test1finalScoreAscending(Student s1, Student s2); 
vector<Module> readFile2(); 
void listmoduleRecord(vector<Module>); 
bool moduleName (Module m1, Module m2); 
vector<Student> getStudentByModule(vector<Student>,string); 
bool isDuplicateStudentRecord(vector<Student>, Student); 


//gloval variable 
vector<Student> duplicates; 

int main() { 

    int choice; 
    vector<Student> students;//list of student 
    vector<Module> modules; 
    vector<Student> list; 


    do { 
     printMenu(); 
     cin >> choice; 

     switch(choice) { 
     case 1: 
      cout << "Read Student file ... " << endl; 
      students =readFile(); 
      cout<<"Number of records read: " <<students.size() <<endl; 
      break; 
     case 2: 
      liststudentRecord(students); 
      break; 
     case 3: 
      cout << "Read Module file ... " << endl; 
      modules =readFile2(); 
      cout<<"Number of records read: " <<modules.size() <<endl; 
      break; 
     case 4: 
      listmoduleRecord(modules); 
      break; 

     case 5: 
      liststudentRecord(duplicates); 
      break; 
     case 6: 
      cout << "Enter Module Code: "; 
      string code; 
      cin >> code; 
      list = getStudentByModule(students, code); 
      for (int i=0; i < list.size(); i++){ 
       Student s = list.at(i); 
       cout << s.toString() << endl; 
      } 
      cout<<"List Student by Module Code"<<endl; 
      break; 
     case 7: 
      //http://www.cplusplus.com/reference/algorithm/sort/ 
      //sort(students.begin(), students.end(), test1finalScoreAscending); 
      sort(students.begin(), students.end(),test1finalScoreAscending); //finalScoreAcending 
      break; 
     case 8: 
      break; 
     case 9: cout << "Exiting program... " << endl; break; 
     default: 
      cout << "Invalid option specified. Please try again" << endl; 
     } 
    } while(choice != 9); 

    return 0; 
} 

void printMenu() { 
    cout << "Menu" << endl; 
    cout << "----" << endl; 
    cout << "[1] Read student file" << endl; 
    cout << "[2] List student records" << endl; 
    cout << "[3] Read module file" << endl; 
    cout << "[4] List module records" << endl; 
    cout << "[5] List Duplicate Record" << endl; 
    cout << "[6] Display Student by Module" << endl; 
    cout << "[7] Sort by Final Score" <<endl; 
    cout << "[8] Write to file" << endl; 
    cout << "[9] Exit" << endl; 
    cout << "Choice: "; 
} 

vector<Student>readFile(){ 
    vector<Student>students; 
    string filename; 
    ifstream inputFile; 

    cout << "Enter filename: "; 
    cin >> filename; 

    inputFile.open(filename, ios::in);//open file, read only 
    if(inputFile.is_open()){ 
     while (inputFile.good()){ 
      string line; 
      getline(inputFile, line); 

      Student s; //create a new student 

      //extract id 
      int i = line.find(","); 
      string id = trim(line.substr(0, i));// extract id 
      s.setId(id); // set student id 
      line = line.substr(i+1);// remove id form line 
      /*if(isvalidStudentid(id)){ 
       string s = id.substr(0,1); 
       const char* s = id.substr(1,7); 
      }*/ 

      //extract name 
      i = line.find(","); 
      string name = trim(line.substr(0, i)); // extract name 
      s.setName(name); //set student name 
      line = line.substr(i+1); //remove name from line 

      //extract classcode 
      i = line.find(","); 
      string classcode = trim(line.substr(0, i)); 
      s.setClasscode(classcode); 
      line = line.substr(i+1); 
      if(isValidClasscode(classcode)){ 
       string module = classcode.substr(0,6); 
       s.setModule(module); 
       string status = classcode.substr(7,9); 
       char *ft ="FT"; 
       if(status.compare(ft)==0){ 
        s.setFulltime(true); 
       }else{ 
        s.setFulltime(false); 
       } 
       string classnumber = classcode.substr(9,11); 
       s.setClassnumber(classnumber); 
      } 


      //to use a for-loop for attendance 
      for (int j =0; j < 10 ; j++){ 
       i = line.find(","); 
       string attendance = trim(line.substr(0, i)); 
       s.setAttendance(j, attendance); 
       line = line.substr(i+1); 
      } 

      //to extreact test1 
      i = line.find(","); 
      int test1 = stoi(line.substr(0, i)); 
      s.setTest1(test1); 
      line = line.substr(i+1); 

      //to extreact test2 
      i = line.find(","); 
      int test2 = stoi(line.substr(0, i)); 
      s.setTest2(test2); 
      line = line.substr(i+1); 


      //to extreact tutorial 
      i = line.find(","); 
      int tutorial = stoi(line.substr(0, i)); 
      s.setTutorial(tutorial); 
      line = line.substr(i+1); 

      //to extreact exam 
      i = line.find(","); 
      int exam = stoi(line.substr(0, i)); 
      s.setExam(exam); 
      line = line.substr(i+1); 


      //need to do validationfirst 
      //to only add the valid student 

      if(isDuplicateStudentRecord(students, s) == false){ 
      students.push_back(s); //add student to list 
      } else { 
       duplicates.push_back(s); 
      } 
      //cout<< line << endl; 
     } 
     inputFile.close(); 
    }else{ 
     cout << "Invalid file" << endl; 
    } 

    return students; 
} 

void liststudentRecord(vector<Student> list){ 
    int numberStudents = list.size(); 

    if (numberStudents > 0){ 
     for (int i = 0; i < numberStudents; i++){ 
      Student s = list.at(i); 
      cout << s.toString() << endl; 
     } 
    }else{ 
      cout << "Empty list" <<endl; 

     } 
} 

bool test1Ascending(Student s1, Student s2){ 
    return s1.getTest1() < s2.getTest1(); 
} 

bool test1Descending(Student s1, Student s2){ 
    return s1.getTest1() < s2.getTest1(); 
} 

bool finalScoreAscending(Student s1, Student s2){ 
    return s1.getFinalScore() < s2.getFinalScore(); 
} 

bool isvalidStudentid(string s){ 
    int i; 

    if(s.length() !=8){ 
     return false;} //first check th length is 8 

    if (s.at(i) != 'S') { 
     return false;} //start with s 

    for (i =1 ; i<8; i++){ //7 digit 
     if(isdigit(s.at(i))==0){ 

      return false; 
     } 
    } 

    return false; 
} 

bool isValidClasscode(string s){ 
    int i; 

    if(s.length() !=11){ 
    return false;} //first check th length is 8 


    for (i =0 ; i<3; i++){ // first 3 char are letters 
     if(isalpha(s.at(i))==0){ 
     return false;} 
    } 

    for (i =3 ; i<6; i++){ //next 3 char are number 
     if(isdigit(s.at(i)) == 0){ 
     return false;} 

    } 
     if (s.at(6) != '-') { 
     return false;} //has a hyphen 

     if (s.at(7) != 'F' && s.at(7) != 'P') { 
     return false;} 

     if (s.at(8) != 'T') { 
     return false;} // T 

     if (isdigit(s.at(9)) == 0 || isdigit(s.at(10)) == 0){ 
     return false;} 


    return false; 
} 

vector<Module> readFile2(){ 
    vector<Module>modules; 
    string filename; 
    ifstream inputFile; 

    cout << "Enter filename: "; 
    cin >> filename; 

    inputFile.open(filename, ios::in);//open file, read only 
    if(inputFile.is_open()){ 
     while (inputFile.good()){ 
      string line; 
      getline(inputFile, line); 

      Module m; //create a new student 

      //extract name 
      int i = line.find(","); 
      string modulecode = trim(line.substr(0, i));// extract id 
      m.setModulecode(modulecode); // set student id 
      //cout << id<< endl; 
      line = line.substr(i+1);// remove id form line 
      //cout << line << endl; 

      //extract id 
      i = line.find(","); 
      string modulename = trim(line.substr(0, i)); // extract name 
      m.setModulename(modulename); //set student name 
      line = line.substr(i+1); //remove name from line 



      //to extreact test1 
      i = line.find(","); 
      int test1 = stoi(line.substr(0, i)); 
      m.setTest1(test1); 
      line = line.substr(i+1); 

      //to extreact test2 
      i = line.find(","); 
      int test2 = stoi(line.substr(0, i)); 
      m.setTest2(test2); 
      line = line.substr(i+1); 


      //to extreact tutorial 
      i = line.find(","); 
      int tutorial = stoi(line.substr(0, i)); 
      m.setTutorial(tutorial); 
      line = line.substr(i+1); 

      //to extreact exam 
      i = line.find(","); 
      int exam = stoi(line.substr(0, i)); 
      m.setExam(exam); 
      line = line.substr(i+1); 

      modules.push_back(m); //add student to list 

      //cout<< line << endl; 
     } 
     inputFile.close(); 
    }else{ 
     cout << "Invalid file" << endl; 
    } 

    return modules; 

} 

void listmoduleRecord(vector<Module> list){ 
    int numberModules = list.size(); 

    if (numberModules > 0){ 
     for (int i = 0; i < list.size(); i++){ 
      Module m = list.at(i); 
      cout << m.toString() << endl; 
     } 
    }else{ 
      cout << "Empty list" <<endl; 

     } 
} 

vector<Student> getStudentByModule(vector<Student> students,string code){ 
    vector<Student> list; 
    for (int i=0; i< students.size(); i++){ 
     Student s = students.at(i); 
     if (code.compare(current_module) == 0){ 
      list.push_back(s); 
     } 
    } 
    return list; 
} 



bool isDuplicateStudentRecord(vector<Student> student, Student s){ 
    string id = student.getId(); 
    string name = student.getName(); 
    string module = student.getModule(); 
    for(int i=0; i< student.size(); i++){ 
     Student s = student.at(i); 
     string current_id = s.getId(); 
     string current_name = s.getName(); 
     string current_module = s.getModule(); 
     if(id.compare)(current_id) == 0 && 
      name.compare(current_name) == 0 && 
      (module.compare(current_module) == 0);{ 
      return true; 
     } 
    } 
    return false; 
} 


//http://stackoverflow.com/a/6500499/3839235 
string trim(string s){ 
    s.erase(0, s.find_first_not_of(' ')); //prefixing spaces 
    s.erase(s.find_last_not_of(' ')+1); //surfixing spaces 
    return s; 
} 

Module.cpp

#include "Module.h" 
#include <sstream> 
using namespace std; 

Module::Module(void){ 
} 


    string Module:: getModulecode(){ 
     return modulecode; 
    } 

    void Module::setModulecode(string modulecode){ 
     this->modulecode = modulecode; 
    } 

    string Module:: getModulename(){ 
     return modulename; 
    } 

    void Module:: setModulename(string modulename){ 
     this->modulename = modulename; 
    } 

    int Module:: getTest1(){ 
     return test1; 
    } 
    void Module:: setTest1(int value1){ 
     test1 = value1; 
    } 

    int Module:: getTest2(){ 
     return test2; 
    } 
    void Module:: setTest2(int value2){ 
     test2 = value2; 
    } 

    int Module:: getTutorial(){ 
     return tutorial; 
    } 
    void Module:: setTutorial(int value3){ 
     tutorial = value3; 
    } 

    int Module:: getExam(){ 
     return exam; 
    } 
    void Module:: setExam(int value4){ 
     exam = value4; 
    } 


    string Module::toString(){ 
     stringstream ss; 

     ss<<"Module Code: " << modulecode<< "-"<< modulename <<endl; 
     ss << "Test 1: " << getTest1Percentage() << "%" << endl; 
     ss << "Test 2: " << getTest2Percentage() << "%" << endl; 
     ss << "Tutorial: " << getTutorialPercentage() << "%" << endl; 
     ss << "Exam: " << getExamPercentage() << "%" << endl; 
     //ss<< "Score percentage: " << getScorePercentage() << "%"<< endl; 
     ss<< "Final score: " << getFinalScore() << "%" <<endl; 
     return ss.str(); 
    } 

    int Module::getTest1Percentage(){ 
     int result; 
     result = (getTest1() * 100)/100; 
     return result; 
    } 

    int Module::getTest2Percentage(){ 
     int result; 
     result = (getTest2() * 100)/100; 
     return result; 
    } 

    int Module::getTutorialPercentage(){ 
     int result; 
     result = (getTutorial() * 100)/100; 
     return result; 
    } 

    int Module::getExamPercentage(){ 
     int result; 
     result = (getExam() * 100)/100; 
     return result; 
    } 

    int Module::getFinalScore(){ 
     int final = getTest1Percentage()+getTest2Percentage()+getTutorialPercentage()+getExamPercentage(); 
     return final; 
    } 


    /*int Module::getFinalScore(){ 
     int final = test1+test2+tutorial+exam; 
     return final; 
    }*/ 

Student.cpp

#include "Student.h" 
#include <sstream> 
using namespace std; 

Student::Student(void){ 
} 


    string Student:: getId(){ 
     return id; 
    } 
    void Student:: setId(string newid){ 
     id = newid; 
    } 

    string Student:: getName(){ 
     return name; 
    } 
    void Student:: setName(string name){ 
     this->name = name; 
    } 

    string Student:: getClasscode(){ 
     return classcode; 
    } 
    void Student::setClasscode(string classcode){ 
     this->classcode = classcode; 
    } 

    string Student:: getAttendance(int i){ 
     return attendance[i]; 
    } 
    void Student:: setAttendance(int i, string value){ 
     attendance[i] = value; 
    } 

    int Student:: getTest1(){ 
     return test1; 
    } 
    void Student:: setTest1(int value1){ 
     test1 = value1; 
    } 

    int Student:: getTest2(){ 
     return test2; 
    } 
    void Student:: setTest2(int value2){ 
     test2 = value2; 
    } 

    int Student:: getTutorial(){ 
     return tutorial; 
    } 
    void Student:: setTutorial(int value3){ 
     tutorial = value3; 
    } 

    int Student:: getExam(){ 
     return exam; 
    } 
    void Student:: setExam(int value4){ 
     exam = value4; 
    } 


    string Student::toString(){ 
     stringstream ss; 

     ss << name << "(" <<id << ")" << endl; 
     ss << classcode << endl; 
     for(int i=0; i<10; i++){ 
      ss << getAttendance(i) << " "; 
     } 
     ss << endl; 
     ss << "Test 1: " << test1 << endl; 
     ss << "Test 2: " << test2 << endl; 
     ss << "Tutorial: " << tutorial << endl; 
     ss << "Exam: " << exam << endl; 
     ss<< "Attendance percentage: " << getAttendancePercentage() << "%"<< endl; 
     ss<< "Final score: " << getFinalScore() <<endl; 
     return ss.str(); 
    } 


    double Student::getAttendancePercentage(){ 
     int n =0 ; // n will be the total number of "yes" 
     for (int i=1; i<10; i++){ 
      string s = getAttendance(i); 
      char*yes = "yes"; 
      if(s.compare(yes)== 0){ 
       n++; 
      } 
     } 
     double percentage = n/10.0 * 100; //avoud interger division 
     return percentage; 
    } 


    int Student::getFinalScore(){ 
     int final = test1+test2+tutorial+exam; 
     return final; 
    } 

    /*string Student::getModule() { return module; } 
    void Student::setModule(string m) { module = m;} 
    bool Student::getFulltime() { return fulltime; } 
    void Student::setFulltime(bool v) { fulltime = v;} 
    string Student::getClassnumber() { return classnumber; } 
    void Student::setClassnumber(string v) { classnumber = v;} */ 


    string Student:: getModule(){ 
     return module; 
    } 
    void Student:: setModule(string m){ 
     module =m; 
    } 

    bool Student:: getFulltime(){ 
     return fulltime; 
    } 
    void Student:: setFulltime(bool v){ 
     fulltime = v; 
    } 

    string Student:: getClassnumber(){ 
     return classnumber; 
    } 

    void Student:: setClassnumber(string c){ 
     classnumber = c; 
    } 

module.h

#ifndef MODULE_H 
#define MODULE_H 

#include <string> 
using namespace std; 

class Module { 

public: 
    Module(); 

    string getModulecode(); 
    void setModulecode(string); 

    string getModulename(); 
    void setModulename(string); 

    int getTest1(); 
    void setTest1(int); 

    int getTest2(); 
    void setTest2(int); 

    int getTutorial(); 
    void setTutorial(int); 

    int getExam(); 
    void setExam(int); 

    string toString(); //to displayed info 
    int getTest1Percentage(); 
    int getTest2Percentage(); 
    int getTutorialPercentage(); 
    int getExamPercentage(); 

    int getFinalScore(); 

private: 
    string modulecode; 
    string modulename; 
    int test1; 
    int test2; 
    int tutorial; 
    int exam; 

}; 


#endif //MODULE_H 

Student.h

#ifndef STUDENT_H 
#define STUDENT_H 

#include <string> 
using namespace std; 

class Student { 
//methods 
public: 
    Student(); 

    string getId(); 
    string getName(); 
    string getClasscode(); 
    string getAttendance(int); 
    int getTest1(); 
    int getTest2(); 
    int getTutorial(); 
    int getExam(); 

    void setId(string); 
    void setName(string); 
    void setClasscode(string); 
    void setAttendance(int, string); 
    void setTest1(int); 
    void setTest2(int); 
    void setTutorial(int); 
    void setExam(int); 

    string toString(); //to displayed info 
    double getAttendancePercentage(); 

    int getFinalScore(); 

    string getModule(); 
    void setModule(string); 

    bool getFulltime(); 
    void setFulltime(bool); 

    string getClassnumber(); 
    void setClassnumber(string); 
    //to create the get and set methods for all the attributes 


//attribute 
private: 
    string id; 
    string name; 
    string classcode; 
    string module; 
    bool fulltime; 
    string classnumber; 
    string attendance[10]; 
    int test1; 
    int test2; 
    int tutorial; 
    int exam; 
}; 

#endif //STUDENT_Hs 

ответ

1

По всей видимости, из первой ошибки, о которой вы говорили, что ваш компилятор жалуется на создание вашей строковой переменной «код» внутри корпуса 6. Попробуйте переместить создание переменной туда, где вы делаете остальные выше , Это должно исправить первую ошибку, которую вы получили.

Что касается второй и третьей ошибки, это говорит вам о том, что функции getId и getModule являются функциями из вашего класса «module», что означает, что вы можете называть их только экземплярами класса «module». Однако вы пытаетесь называть их вектором объектов-учеников.

+0

Обе последние две ошибки могут быть решены путем удаления кода. 'id',' module' и 'name' не используются, поэтому нет смысла фиксировать код, который их получает. – user4581301

0

Это плохая идея, чтобы объявить переменный в switch заявления:

switch(i) { 
case 1: 
    int foo = 42; 
    doSomething(foo); 
    break; 
case 2: 
    // aargh `foo` is in scope but uninitialised if we jump to here 
    ... 
} 

Чтобы это исправить, либо привести int foo вне switch заявления, или положить его в локальной области видимости в switch заявления:

switch(i) { 
case 1: 
    { 
    int foo = 42; 
    doSomething(foo); 
    } // foo is destroyed 
    break; 
case 2: 
    // there is no foo, there is no problem 
    ... 
} 

С внесенными изменениями я поместил ваш код через clang-format и онлайн-компилятор Clang, потому что Clang имеет прекрасные сообщения об ошибках. Вот что Clang должен сказать:

prog.cc:69:27: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare] 
     for (int i = 0; i < list.size(); i++) { 
         ~^~~~~~~~~~~~ 
prog.cc:151:20: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings] 
     char *ft = "FT"; 
       ^
prog.cc:243:12: warning: variable 'i' is uninitialized when used here [-Wuninitialized] 
    if (s.at(i) != 'S') { 
     ^
prog.cc:237:8: note: initialize the variable 'i' to silence this warning 
    int i; 
    ^
     = 0 
prog.cc:364:23: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare] 
    for (int i = 0; i < list.size(); i++) { 
        ~^~~~~~~~~~~~ 
prog.cc:377:22: error: use of undeclared identifier 'current_module' 
    if (code.compare(current_module) == 0) { 
        ^
prog.cc:375:21: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare] 
    for (int i = 0; i < students.size(); i++) { 
        ~^~~~~~~~~~~~~~~~ 
prog.cc:385:23: error: no member named 'getId' in 'std::__1::vector<Student, std::__1::allocator<Student> >' 
    string id = student.getId(); 
       ~~~~~~~^
prog.cc:386:25: error: no member named 'getName' in 'std::__1::vector<Student, std::__1::allocator<Student> >' 
    string name = student.getName(); 
       ~~~~~~~^
prog.cc:387:27: error: no member named 'getModule' in 'std::__1::vector<Student, std::__1::allocator<Student> >' 
    string module = student.getModule(); 
        ~~~~~~~^
prog.cc:393:12: error: reference to non-static member function must be called 
    if (id.compare) 
     ~~~^~~~~~~ 

    (snipped: a lot of suggestions for what you might have meant instead) 

prog.cc:394:20: error: invalid operands to binary expression ('string' (aka 'basic_string<char, char_traits<char>, allocator<char> >') and 'int') 
     (current_id) == 0 && name.compare(current_name) == 0 && 
     ~~~~~~~~~~~~^~ 
prog.cc:384:64: warning: unused parameter 's' [-Wunused-parameter] 
bool isDuplicateStudentRecord(vector<Student> student, Student s) { 
                  ^
prog.cc:388:21: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare] 
    for (int i = 0; i < student.size(); i++) { 
        ~^~~~~~~~~~~~~~~ 
7 warnings and 6 errors generated. 

Из них некоторые незначительные (но стоит фиксации, например for(size_t i = 0... вместо int), но те, с пометкой «ошибка» более критично. Как правило, хорошая практика заключается в том, чтобы заставить компилятор предупредить обо всем, а затем убрать все предупреждения.

Вы можете увидеть код (с дополнительными скобками в switch и все лязг отформатированные в стиле LLVM) в интернет-Clang компилятором здесь: http://melpon.org/wandbox/permlink/qLnE80Hs6FJWl9Fy

В student.getID() ошибки возникают потому, что в этой функции:

bool isDuplicateStudentRecord(vector<Student> student, Student s) { 
    string id = student.getId(); 
    string name = student.getName(); 
    string module = student.getModule(); 
    ... 

Вы пытаетесь установить getID() на vector<Student> не на Student. Возможно, вы имели в виду string id = s.getID();?

+0

Привет, Джек, я внес некоторые изменения здесь. Пожалуйста, помогите изучить ошибку. http://melpon.org/wandbox/permlink/qLnE80Hs6FJWl9Fy –

0

После изменений.

case 6:{ 
      cout << "Enter Module Code: "; 
      string code; 
      cin >> code; 
      list = getStudentByModule(students, code); 
      for (int i=0; i < list.size(); i++){ 
       Student s = list.at(i); 
       cout << s.toString() << endl; 
      } 
      cout<<"List Student by Module Code"<<endl; 
      break; 
       } 

vector<Student> getStudentByModule(vector<Student> students,string code){ 
    vector<Student> list; 
    for (int i=0; i< students.size(); i++){ 
     Student s = students.at(i); 
     if (code.compare(current_module) == 0){ 
      list.push_back(s); 
     } 
    } 
    return list; 
} 

дублирует

bool isDuplicateStudentRecord(vector<Student> student, Student s){ 
    string id = s.getId(); 
    string name = s.getName(); 
    string module = s.getModule(); 
    for(int i=0; i< student.size(); i++){ 
     Student s = student.at(i); 
     string current_id = s.getId(); 
     string current_name = s.getName(); 
     string current_module = s.getModule(); 
     if(id.compare)(current_id) == 0 && 
      name.compare(current_name) == 0 && 
      (module.compare(current_module) == 0);{ 
      return true; 
     } 

ошибки шоу ниже.

1> C: \ Users \ cry83 \ Documents \ Visual Studio 2010 \ Projects \ partb \ partb \ partb.cpp (378): ошибка C2065: 'current_module': необъявленный идентификатор

1> C: \ пользователи \ cry83 \ documents \ visual studio 2010 \ projects \ partb \ partb \ partb.cpp (391): предупреждение C4018: '<': несоответствие подписанного/неподписанного

1> c: \ users \ cry83 \ documents \ visual Студия 2010 \ projects \ partb \ partb \ partb.cpp (396): ошибка C3867: 'std :: basic_string < _Elem, _Traits, _Ax> :: compare': список функций, отсутствующих в списке аргументов; использовать '& станд :: basic_string < _Elem, _Traits, _Ax> :: сравнить', чтобы создать указатель на член с [_Elem = голец, _Traits = станд :: char_traits, _Ax = станд :: распределителем]

1> partb.cpp (396): ошибка C2678: двоичный '==': оператор не найден, который принимает левый операнд типа 'std :: string' (или нет приемлемого преобразования)

1> c: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ VC \ Include \ исключение (470): может быть 'BOOL станд :: оператор == (Const станд :: _ Exception_ptr &, Const станд :: _ Exception_ptr &)'

1> c: \ program files (x86) \ microsof t visual studio 10.0 \ vc \ include \ exception (475): или 'bool std :: operator == (std :: _ Null_type, const std :: _ Exception_ptr &)'

1> c: \ program files (x86) \ microsoft visual studio 10.0 \ vc \ include \ exception (481): или 'bool std :: operator == (const std :: _ Exception_ptr &, std :: _ Null_type)'

1> c: \ program files (x86) \ Microsoft Visual Studio 10.0 \ VC \ включить \ system_error (408): или 'BOOL станд :: оператор == (Const станд :: Error_Code &, Const зЬй :: error_condition &)'

1> гр : \ program files (x86) \ microsoft visual studio 10.0 \ vc \ Включать \ system_error (416): или 'BOOL станд :: оператор == (Const зЬй :: error_condition &, Const станд :: error_code &)'

1> при попытке соответствовать список аргументов «(Std: : string, int) '

+0

Я не могу отлаживать это для вас, но когда вы видите '1> c: \ ... \ partb.cpp (378): ошибка C2065: 'current_module ': uneclared identifier', он говорит вам посмотреть в строке 378 partb.cpp, где вы используете что-то, называемое 'current_module', о котором программа не знает. Сделайте это для всех ошибок и предупреждений! –

+0

Отмечено. Позвольте мне выяснить этот вопрос. Спасибо. –

+0

Я сделал глобальную переменную для current_module .. ошибка исчезла. но появилась еще одна ошибка. –

Смежные вопросы