선택 정렬에 문제가 있습니다. 알파벳순으로 학생 이름을 정렬하려고합니다. 컴파일하고 VS에서 전체 오류를 보여줍니다.구조체 배열을 사용하여 선택 정렬
나는 내 디스플레이 모든 학생들 기능을 수행 할 수 있다고 생각 해달라고, 나는 그것을 감사 SortByName 및 SortByScoreFunctions
도움과 더 있다고 생각 감사합니다!
여기 내 프로그램의 구조체입니다.
struct StudentType
{
string studentName;
int testScore;
char grade;
};
void SortStudentsByName(StudentType student[], int numStudents)
{
int startScan, minIndex, FirstInAlphabet;
for (startScan = 0; startScan < (NUM_STUDENTS-1); startScan++)
{
minIndex = startScan;
FirstInAlphabet = student[0];
for(int index = startScan+1; index < NUM_STUDENTS; index++)
{
if (student[index] > FirstInAlphabet)
{
FirstInAlphabet = student[index];
minIndex = index;
}
}
}
}
void SortStudentsByScore(StudentType student[], int numStudents)
{
int startScan,
minIndex,
lowest;
for (startScan = 0; startScan < (NUM_STUDENTS-1); startScan++)
{
minIndex = startScan;
lowest = student[0].testScore;
for (int index = startScan+1; index < NUM_STUDENTS; index++)
{
if(student[index].testScore < lowest)
{
lowest = student[index].testScore;
minIndex = index;
}
}
student[minIndex].testScore = student[startScan].testScore;
student[startScan].testScore = lowest;
cout <<"List of Students sorted by Score from Highest to Lowest" << endl;
DisplayAllStudents(student, numStudents);
}
}
void DisplayAllStudents(const StudentType student[], int numStudents)
{
cout << endl;
FormatNameScoreGrade(cout);
for(int i = 0; i < numStudents; i++)
{
cout << setw(20) << student[i].studentName << setw(10) << student[i].testScore << setw(10) << student[i].grade << endl;
}
cout << endl;
EndOfList(cout);
}
내가 여기에 컴파일
내가이 이름으로 정렬 내 출력 결과입니다
를받는 출력Fibonacci, Leonardo 63 D
Huffman, David 79 C
Augusta, Ada 91 A
Goldbach, Christian 81 B
Venn, John 100 A
Church, Alonzo 72 C
Fermat, Pierre 84 B
Kruskal, Joseph 66 D
Cantor, Georg 67 D
Turing, Alan 85 B
Chebysheva, PL 100 A
DeMorgan, Augustus 79 C
Karnaugh, Maurice 72 C
Babbage, Charles 98 A
Hooper, Grace 95 A
는 여기
작업이 출력하지 내 고등 학년의 경우
Student Name Test Score Grade
------------------------------------------
-858993460 D
Huffman, David-858993460 C
Augusta, Ada-858993460 A
Goldbach, Christian-858993460 B
Venn, John-858993460 A
Church, Alonzo-858993460 C
Fermat, Pierre-858993460 B
Kruskal, Joseph-858993460 D
Cantor, Georg-858993460 D
Turing, Alan-858993460 B
Chebysheva, PL-858993460 A
DeMorgan, Augustus-858993460 C
Karnaugh, Maurice-858993460 C
Babbage, Charles-858993460 A
Hooper, Grace-858993460 A
오류를 정렬하고 첫 번째 오류를 표시하십시오. –
'sort'가 엔트리를 전혀 바꾸지 않습니다. 점수 별 정렬은 점수를 움직이는 것처럼 보이지만 이름이나 성적은 아닙니다. –
용의자 인'SortStudentsByX' 함수를 디버깅하기 위해 수행 한 작업은 무엇입니까? * 여기에 게시하는 것 외에 * 여기에 게시 하시겠습니까? – WhozCraig