![]() |
![]() | #1 |
Младенец Join Date: 03 2006 Location: san fan Age: 39
Posts: 15
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
hi guys how would i sort this in ascending order im not understanding the *Ptr // This program Enter test scores and sort them in oder and Averages them #include <iostream> #include <iomanip> using namespace std; int main() { double *score, total = 0, average; int TestScores, count; cout << "How many Test Scroes do you wish to enter "; cin >> TestScores; score = new double[TestScores]; // Allocate memory // Get the Test Scores cout << "Enter each students test scores.\n"; for (count = 0; count < TestScores; count++) { cout << "Student " << (count + 1) << ": "; cin >> score[count]; } // Calculate the total Scores for (count = 0; count < TestScores; count++) { total += score[count]; } // Calculate the average Test Scores average = total / TestScores; // Display the results cout << fixed << showpoint << setprecision(2); cout << "Average Score: " << average << endl; // Free dynamically allocated memory delete [] score; return 0; } |
![]() |
![]() | #2 |
Easy rider Join Date: 11 2005 Location: tristeza Age: 36
Posts: 1,082
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]() Code: for (int i=0; i<TestScores; ++i) for (int j=i; j<TestScores; ++j) if (score[i] < score[j]) { double tmpscore = score[i]; score[i] = score[j]; score[j] = tmpscore; } Last edited by Silver; 12.04.2006 at 10:31. |
![]() |
![]() | #3 |
Профессор Join Date: 07 2004 Location: Own world Age: 39
Posts: 3,656
Downloads: 22 Uploads: 0
Reputation: 228 | 4 | ![]() Code: std::sort(source, source+TestScores-1); p.s.: I have a feeling that bubble sort needs n^2/2 comparisons not n^2. |
![]() |
![]() | #5 |
Младенец Join Date: 03 2006 Location: san fan Age: 39
Posts: 15
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
how would i got about displaying the sort ?
|
![]() |