help with making array into a bubble sort

So I have an array that displays ids, scores, and corresponding grades based off the class average. It inputs the ids and scores from a external file. My goal now is to make this array into a bubble sort that will sort the students average scores from greatest to least. Can anyone help? Thanks

here is the external files (grades.txt)
3313 90 42 58 64 70 75 100
5688 88 48 79 70 79 70 94
4700 50 44 89 73 70 73 100
9561 88 69 88 87 84 63 98
3199 96 69 100 90 88 67 100
3768 78 57 80 59 57 15 60
8291 72 56 70 82 74 9 83
7754 76 62 93 100 78 41 58
8146 94 68 99 94 93 9 54
2106 98 47 96 94 70 27 100



And here is my array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// File: stugrades.cpp
// Computes a external file and compiles it into a table with 3 columns of ID numbers, scores, and corresponding scores.

#include <iostream>  
#include <fstream> // re. ifstream object  
#include <iomanip> // re. setw, setprecision, fixed in formatted output 
 

    
using namespace std;
  
   
int main()
{  

	ifstream fin( "grades.txt" );   // construct ifstream object fin 

	if( fin ) 			// if opened ok ...  

	{  

		cout << "Student ID" << "      " << "Average Score" << "       " << "Corresponding Grade" << endl;  

		int id; 
		string grade; 
		int count = 7;
		float average;
		
		int mean = 72.8;
		
		while( fin >> id )  
		{  

			int sum = 0, score[7];
			//int mean = 0, average[7];  

			for( int i = 0; i < 7; ++ i )  

		{  

			fin >> score[i];  

			sum += score[i]; 
					

			average = (sum / count); 

	
			
			

		
				
				
					
				
					if (average > mean + 10)
					{
						grade = "outstanding";
					}
					else if (average < mean - 10)
					{
						grade = "unsatisfactory";
					}
					else if ((average <= mean + 10) && (average >= mean - 10))
					{
						grade = "satisfactory";
					}
				
		} 
			 

		cout << "   " << id << "       " << "       " << average << "         " << "       " << grade << endl;
        

	}  

	fin.close(); // since done with file now ...  

	} 

}
Last edited on
Topic archived. No new replies allowed.