Help

Hello
I need help.

I need to write code that outputs the data groups of students.
Code must output
Student name, age, subjects, grades and grades matrix,
each student's grade point average.
I have done all this issues,

At the end
it must sorting students by the rating
from the student which has highest grade average to the lowest one.
And here I don't know how to do this sorting
In function double getBendrasVidurkis(const int); //get total student average
I calculate the student total average, but how I can sorting it and bind with name?
Thanks

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
  #include <iostream>
#include <string>
#include <iomanip>

using namespace std;
class studentas
{

public:
// const of the total grades for each subjects
	static const int PAZYMIS = 3; 
	static const int DALYKAS = 4;// const of subject 
	
	studentas() {}; //tuscias konstruktorius
	/*konstruktorius inicializuoti varda, pavarde, amziu, dalyku skaiciu,
	pazymiu skaiciu*/
	studentas(string vardas, string pavarde, int amzius, int dalykai,
	int pazymiai, const int[DALYKAS][PAZYMIS]);

	string getVardas();
	string getPavarde();
	int getAmzius();
	int getDalykai();
	int getPazymis();
	// apsakaiciuoja koks yra dalyko vidurkis
	double getVidurki(const int[], const int); //get every subject average
	double getBendrasVidurkis(const int); //get total  student average
	void getData();
	void isvestiMasyva(); // show the grade matrix
	
private:
	string vardas; //first name
	string pavarde; //last name
	int amzius; // age
	int dalykai; // subjects 
	int pazymiai; // grades
	int masyvasPaz[DALYKAS][PAZYMIS];// grades array [subject][grade]
};
/////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////

//////////////////////////////////////////////////////
//konstruktorius inicializuoja varda, pavarde, amziu,dalyku skaiciu
//pazymiu skaiciu
studentas::studentas(string vardas, string pavarde, int amzius,
	int dalykai, int pazymiai, const int masyvasPazimiu[DALYKAS][PAZYMIS])
{
	this-> vardas = vardas;
	this->pavarde = pavarde;
	this->amzius = amzius;
	this->dalykai = dalykai;
	this->pazymiai = pazymiai;

	for (int dal = 0; dal < DALYKAS; dal++)
		for (int paz = 0; paz < PAZYMIS; paz++)
			masyvasPaz[dal][paz] = masyvasPazimiu[dal][paz];

}

/*pazymiu masyvo konstruktorius*/
/*studentas::studentas(const int masyvasPazimiu[DALYKAS][PAZYMIS])
{
	for (int dal = 0; dal < DALYKAS; dal++)
		for (int paz = 0; paz < PAZYMIS; paz++)
			masyvasPaz[dal][paz] = masyvasPazimiu[dal][paz];
}*/


string studentas::getVardas()
{
	cout << "Studento vardas, pavarde: ";
	return vardas;
}
string studentas::getPavarde()
{
	cout << " ";
	return pavarde;
}
int studentas::getAmzius()
{
	cout << "Studento amzius: ";
	return amzius;
}
int studentas::getDalykai()
{
	cout << "Mokomieji dalykai = ";
		return dalykai;
}
int studentas::getPazymis()
{
	cout << "Iskaitu skaicius = ";
		return pazymiai;
}


void studentas::getData()
{

	cout << getVardas();
	cout << getPavarde() << endl;
	cout << getAmzius() << endl;
	cout << getDalykai() << endl;
	cout << getPazymis() << endl;
	isvestiMasyva();
	
}

// metoda kuris apskaiciuoja studnto kiek vieno dalyko vidurki
double studentas::getVidurki(const int pazymiuVidurkis[], const int pazymiai)
{
	int viso = 0;

	for (int pazymys = 0; pazymys < pazymiai; pazymys++)
		viso += pazymiuVidurkis[pazymys];

	return static_cast<double> (viso) / pazymiai;
}
//the grade average of students
double studentas::getBendrasVidurkis(const int BendrasVidurkis)
{
	return static_cast<double> (BendrasVidurkis) / DALYKAS;
}
// metodas sudeda ir isveda studento paziymius lenteles pavidalu
void studentas::isvestiMasyva()
{
	double bendrasLaikinas = 0;

	cout << "Dalyku numeracija: Matematika (1), Fizika(2), Chemija(3),";
	cout << " Anglu(4)";
	cout << "\nDalyku pazymiai: \n\n";
	cout << "		";

	// sukuriamas atsiskatymu skaiciaus numeracija
	for (int test = 0; test < PAZYMIS; test++)
		cout << "Testas " << test + 1 << "  ";
		cout << "Vidurkis " << endl;


	// ciklas dalyku numeracijos isvedimui
	for (int dal = 0; dal < DALYKAS; dal++)
	{
		cout << "Dalykas " << setw(3) << "(" << dal+1 << ")";

		for (int test = 0; test < PAZYMIS; test++)
			cout << setw(9) << masyvasPaz[dal][test];

		double vidurkis = getVidurki(masyvasPaz[dal], PAZYMIS);
		bendrasLaikinas += vidurkis;
		//getBendrasVidurkis(bendrasLaikinas);
		cout << setw(10) << setprecision(2) << fixed << vidurkis << endl;
		cout << endl;

	}

	cout << "Bendras studento " << pavarde
		<< " vidurkis: " << getBendrasVidurkis(bendrasLaikinas);
	cout << endl;
}



///////////////////////////////////////
///////////////////////////////////////
///////////////////////////////////////
const int STUDENTU = 5;
int main()
{
	/*masyvas aprasantys 1-o studento pazimius
	4 eilutes tai yra 4 dalykai
	3 pazymiai eiluteje vieno dalyko atsiskaitymo pazymiai */
	int masyvasJonaitis[studentas::DALYKAS][studentas::PAZYMIS] =
	{ { 4,8,9 },
	{ 10,6,5 },
	{ 9,8,7 },
	{ 7,6,5 } };
	int masyvasPetraitis[studentas::DALYKAS][studentas::PAZYMIS] =
	{ { 5,6,10 },
	{ 9,7,8 },
	{ 6,5,4 },
	{ 8,4,6 } };
	int masyvasTomaitis[studentas::DALYKAS][studentas::PAZYMIS] =
	{ { 7,4,8},
	{ 9,9,10 },
	{ 6,8,9 },
	{ 8,5,9 } };
	int masyvasDonataitis[studentas::DALYKAS][studentas::PAZYMIS] =
	{ { 4,8,6 },
	{ 10,5,7 },
	{ 4,4,6 },
	{ 10,4,9 } };
	int masyvasRimaitis[studentas::DALYKAS][studentas::PAZYMIS] =
	{ { 9,9,9 },
	{ 9,6,6 },
	{ 8,8,6 },
	{ 7,7,5 } };


	//studentMasyvas saugo duomenys apie studena
	// vardas, pavarde, amzius, mokomuju dalyku skaicius
	// pazymiu skaicius
	studentas studentuMasyvas[STUDENTU] = {
		studentas("Jonas", "Jonaitis", 21, 4, 3, masyvasJonaitis),
		studentas("Petras", "Petraitis", 23, 4, 3, masyvasPetraitis),
		studentas("Tomas", "Tomaitis", 21, 4, 3, masyvasTomaitis),
		studentas("Donatas", "Donataitis", 22, 4, 3, masyvasDonataitis),
		studentas("Rimas", "Rimaitis", 22, 4, 3, masyvasRimaitis)
	};

	

	//ciklas pereinantis per visa studentuMasyvas
	//ir isveda visu studentu duomenys is masyvo
	for (int i = 0; i < STUDENTU; i++)
	 {
		studentuMasyvas[i].getData();
		cout << endl;
	}

	//rikiavimas.studentuRikiavimas();
	cout << endl;

	return 0;
}
You can use the std::sort function - if you are allowed.
http://www.cplusplus.com/reference/algorithm/sort/
Sveiki

stas76 wrote:
it must sorting students by the rating
from the student which has highest grade average to the lowest one.
And here I don't know how to do this sorting


For making the code you may take the rating of individual student and then sort them into new array

1
2
3
4
5
6
7
8
//a big for loop

//get their rating

//if its largest 
      //input it into other array

//keep on with the loop till end 


Hope it helps
closed account (48T7M4Gy)
And the sorted array, if just printing the details out is not sufficient, need only be the index number in the student array. (Or even better a StudentID)
Topic archived. No new replies allowed.