[ create a new paste ] login | about

Link: http://codepad.org/3r5Q0ta9    [ raw code | output | fork ]

C++, pasted on Jan 13:
#include <iostream>
#include <list>
#include <string>

using namespace std;

typedef unsigned int UINT;

struct student
{
	string Name;
	UINT Mark_Math;
	UINT Mark_Informatics;

	student() : Name("NULL"), Mark_Math(0), Mark_Informatics(0){}
	student( const char* str, UINT m_m, UINT m_i ) : Name(str), Mark_Math(m_m), Mark_Informatics(m_i){}
};

bool comp_mark_math( student &a, student &b )
{
	return a.Mark_Math < b.Mark_Math;
}

int main()
{
	list<student> arr;
	arr.push_back( student("Ivanov", 5, 4) );
	arr.push_back( student("Petrov", 2, 3) );
	arr.push_back( student("Sidorov", 3, 3) );
	arr.push_back( student("Soloveq", 5, 5) );
	arr.push_back( student("Beshen", 4, 3) );

	arr.sort( comp_mark_math );

	list<student>::const_iterator it = arr.begin();
	for (int i = 0; it != arr.end(); it++)
	{
		cout << "Student #" << ++i << endl;
		cout << "Name: " << it->Name << endl
			 << "Math: " << it->Mark_Math << endl
			 << "Informatics: " << it->Mark_Informatics << endl;
	}

	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Student #1
Name: Petrov
Math: 2
Informatics: 3
Student #2
Name: Sidorov
Math: 3
Informatics: 3
Student #3
Name: Beshen
Math: 4
Informatics: 3
Student #4
Name: Ivanov
Math: 5
Informatics: 4
Student #5
Name: Soloveq
Math: 5
Informatics: 5


Create a new paste based on this one


Comments: