Note that there are some explanatory texts on larger screens.

plurals
  1. POpass by reference and const function
    primarykey
    data
    text
    <p>Basically I need to change the Two StudentType* functions to const but i know its not letting me because of the &amp;ampersand sign on the ReadStudentData function, is there anyway around this?</p> <p>I am not asking for someone to do my hw just point me in right direction</p> <p>it brings up a whole bunch of errors when I try to throw const in it</p> <p>this is what i am trying to get:</p> <pre><code>StudentType * SortStudentByName(const StudentType* student, int size); void ReadStudentData(ifstream&amp; infile, StudentType*&amp; student, int&amp; numOfStudents) { string firstName, lastName; int testScore; int count = 0; infile &gt;&gt; numOfStudents; try { student = new StudentType[numOfStudents]; while (infile &gt;&gt; firstName &gt;&gt; lastName &gt;&gt; testScore) { if (testScore &gt;= 0 &amp;&amp; testScore &lt;=100) { student[count].studentName = lastName + ", " + firstName; student[count].testScore = testScore; count++; } } numOfStudents = count; } catch (bad_alloc) { cout &lt;&lt; "Failed to allocate memory" &lt;&lt; endl; numOfStudents = 0; student = NULL; } } StudentType* SortStudentsByName(StudentType* student, int numStudents) { int startScan, minIndex; for (startScan = 0; startScan &lt; (numStudents-1); startScan++) { minIndex = startScan; for (int index = startScan; index &lt; numStudents; index++) { if (student[index].studentName &lt; student[minIndex].studentName) minIndex = index; } StudentType temp = student[minIndex]; student[minIndex] = student[startScan]; student[startScan] = temp; } cout &lt;&lt; endl; cout &lt;&lt; "List of Students sorted Alphabetically "&lt;&lt; endl; DisplayAllStudents(student, numStudents); return student; } StudentType* SortStudentsByScore(StudentType* student, int numStudents) { int startScan, minIndex; for (startScan = 0; startScan &lt; (numStudents-1); startScan++) { minIndex = startScan; for ( int index = startScan; index &lt; numStudents; index++) { if( student[index].testScore&gt;student[minIndex].testScore) minIndex = index; } StudentType temp = student[minIndex]; student[minIndex] = student[startScan]; student[startScan] = temp; } cout &lt;&lt;"List of Students sorted by Score from Highest to Lowest" &lt;&lt; endl; DisplayAllStudents(student, numStudents); return student; } </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.
 

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