Note that there are some explanatory texts on larger screens.

plurals
  1. POSelection sort with arrays of structs
    primarykey
    data
    text
    <p>I am having problem with selection sort, I am trying to sort the students name alphabetically.I compile it and it shows me whole bunch of errors in VS.</p> <p>I dont think it has do to do with my display all students function, I think it has more to do with SortByName and SortByScoreFunctions</p> <p>any help is appreciated thank you!</p> <p>here is the struct for my program.</p> <pre><code>struct StudentType { string studentName; int testScore; char grade; }; void SortStudentsByName(StudentType student[], int numStudents) { int startScan, minIndex, FirstInAlphabet; for (startScan = 0; startScan &lt; (NUM_STUDENTS-1); startScan++) { minIndex = startScan; FirstInAlphabet = student[0]; for( int index = startScan+1; index &lt; NUM_STUDENTS; index++) { if ( student[index] &gt; FirstInAlphabet) { FirstInAlphabet = student[index]; minIndex = index; } } } } void SortStudentsByScore(StudentType student[], int numStudents) { int startScan, minIndex, lowest; for (startScan = 0; startScan &lt; (NUM_STUDENTS-1); startScan++) { minIndex = startScan; lowest = student[0].testScore; for ( int index = startScan+1; index &lt; NUM_STUDENTS; index++) { if( student[index].testScore &lt; lowest) { lowest = student[index].testScore; minIndex = index; } } student[minIndex].testScore = student[startScan].testScore; student[startScan].testScore = lowest; cout &lt;&lt;"List of Students sorted by Score from Highest to Lowest" &lt;&lt; endl; DisplayAllStudents(student, numStudents); } } void DisplayAllStudents(const StudentType student[], int numStudents) { cout &lt;&lt; endl; FormatNameScoreGrade(cout); for(int i = 0; i &lt; numStudents; i++) { cout &lt;&lt; setw(20) &lt;&lt; student[i].studentName &lt;&lt; setw(10) &lt;&lt; student[i].testScore &lt;&lt; setw(10) &lt;&lt; student[i].grade &lt;&lt; endl; } cout &lt;&lt; endl; EndOfList(cout); } </code></pre> <p>when I compile here is the output I receive</p> <p>these are my output results for the Sort by Name</p> <pre><code>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 </code></pre> <p>its not working here</p> <p>and this is the output for my sort by highest grade</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload