2016-10-06 3 views
0

私は助けが切望されています。私は構造体とベクトルを使用して生徒記録を作成することになっています。プログラムで は、私が持っている必要があります。名前や学生数 のいずれかによって識別される特定の学生のため C++:Student Record Program

  1. は、(a)のレコードに新しい学生を入力します。 (完成なしのコースを負いません。) (b)のグレードポイント平均 (c)のトランスクリプトは、クレジット値とグレードを含め、撮影したコースのリスト、つまり (d)の録音新たに完成したコース

  2. リストを獲得し、与えられたコースを受講したすべての生徒の名前でソートされています。

  3. すべての生徒の成績平均とその成績の平均値で除したリスト 保護観察中の成績、つまり成績平均は<です。

これは私がこれまで持っているものでは...と私は私の構造体にそれを読んでどのようにユーザーの入力でトラブルを抱えているように見える

using namespace std; 

struct courses { 
    string courseName; 
    int courseNum; 
    double credit; 
    char grade; 
}; 

struct students { 
    string name; 
    int id; 
    vector<courses> c; 
}; 

int main() { 

    // variables 
    string name; 
    char selector; 
    students s; 
    courses d; 
    vector<students> student; 
    vector<courses> course; 

    // (1) create a menu: (a) user input, (b) echo record (with overall gpa), (c) failed students 
    do { 
     // prompt for user input 
     cout << "Enter Q to (Q)uit, (C)reate new student record, (S)how all record(s) on file, show students on (P)robation: "; 
     cin >> selector; 

     selector = toupper(selector); 
     switch (selector) { 



      // (a) ask and get for user input: 
      // student info first 
      // courses second 
     case 'C': 

      // variables within case C 
      char answer; 
      char answerAddAnotherCourseEntry; 
      char answerToAnotherStudentRecord; 

      do { 


       cout << "Enter your name and student ID number: "; 
       cin >> s.name >> s.id; 
       student.push_back(s); 

       do { 
        cout << "Do you want to create a student course entry ('y' or 'n')? "; 
        cin >> answer; 
        answer = toupper(answer); 

        cout << "Enter your course number, course name, grade received and credit worth: "; 
        cin >> d.courseNum >> d.courseName >> d.grade >> d.credit; 
        course.push_back(d); 


        cout << "Add another student course entry ('y' or 'n'): "; 
        cin >> answerAddAnotherCourseEntry; 
        answerAddAnotherCourseEntry = toupper(answerAddAnotherCourseEntry); 


       } while (answer == 'N'); 

       cout << "Add another student record ('y' or 'n'): " << endl; 
       cin >> answerToAnotherStudentRecord; 
       answerAddAnotherCourseEntry = toupper(answerToAnotherStudentRecord); 
      } while (answerToAnotherStudentRecord == 'N'); 
      break; 


      // (b) echo record of vectors 
      // sort by name 
     case 'S': 
      if (student.empty()) { 
       cout << "\nSorry, no records exist in the database."; 
      } 
      else 
       for (int count = 0; count < student.size(); count++) {   //For Loop to Display All Records 

        cout << "Student name: " << student[count].name << "ID Number: " << student[count].id << endl; 
        count++; 

        // another for loop i think 
        for (int i = 0; i < course.size(); i++) { 
         cout << "Course info: " << " " << course[i].courseNum << " " << course[i].courseName << " " << course[i].credit << " " << course[i].grade << endl; 
         i++; 
        } 
       } 
      cout << endl; 
      break; 


      // (c) separate failed student into another vector 
      // sort by gpa 
     case 'P': 
      break; 




     } // bracket closing switch 
    } // bracket closing do while 
    while (selector != 'q' && selector != 'Q');  // first do while 
+1

編集コード:char配列に文字列を変換する

cout << "Student name: " << student[count].name << "ID Number: " << student[count].id << endl; 

は、最初にこのコンパイルを行いポストへ。それのためのボタンがあります。 – Incomputable

+0

申し訳ありませんが、まだこれに新しいスーパー!ちょうどそれを、ありがとう! :) – 2lnk

+0

次のステップは、問題をローカライズして解決することです。後者をすることができなければ(自分で解決することができれば)それは大丈夫ですが、多分、非常に少数の人々がその多くのコードを通過します。だから、あなたが直面している問題を再現し、あなたが何を期待して何を試したのかを書くために、コードを最小限に抑えるようにしてください。 – Incomputable

答えて

0

私はあなたの入力を参照して問題があることですユーザー入力を直接文字列に格納しようとしています。ここでは例を示します。構造体sの変数nameに:

cout << "Enter your name and student ID number: "; 
cin >> s.name >> s.id; 

これはコンパイルされません。代わりに、最初に一時的なchar配列に名前を格納してから、s.nameにコピーすることができます。

char studentName[128]; 
cout << "Enter your name and student ID number: "; 
cin >> studentName >> s.id; 
s.name = studentName; 

入力を直接文字列に保存する場合は、getline()を使用することもできます。

は、さらにあなたは、coutに文字列をある変数student[count].nameを、直接出力してみてください:

cout << "Student name: " << student[count].name.c_str() << "ID Number: " << student[count].id << endl;