<file_sep>#include <iostream>
#include <fstream>
#include "lab2.h"
using namespace std;

int main()
{
	int k, realA, realB;
	double as_a,as_b;
	string start;
	Game score_cal, rate_cal;
	ifstream inFile("file.in",ios::in);
	ofstream outFile("file.out", ios::out);
	inFile >> k >> realA >> realB;
	outFile << realA << "\t" << realB << "\t" << endl;
	while(inFile >> as_a)
	{
		if(as_a == 1) as_b = 0;
		else if(as_a == 0) as_b = 1;
		else if(as_a == 0.5) as_b = 0.5;
		double ex_a = score_cal.Expected_scoreA(realA,realB);
		double ex_b = score_cal.Expected_scoreB(realA,realB);
		int R_A = rate_cal.RatingA(realA, k, as_a, ex_a);
 		int R_B = rate_cal.RatingB(realB, k, as_b, ex_b);
 		realA = R_A;
  		realB = R_B;
  		outFile << R_A << "\t" << R_B << endl;
	}
	return 0;
}
<file_sep># lab2

# g++ -c main.cpp

# g++ -c lab2.cpp

#g++ -o lab2 lab2.cpp main.cpp

#make

#./lab2


<file_sep>using namespace std;

class Game
{
	public:
		double Expected_scoreA(int r_a,int r_b);
		double Expected_scoreB(int r_a,int r_b);
		int RatingA(int r_a, int k, double a_a, double e_a);
		int RatingB(int r_b, int k, double a_b, double e_b);
	private:
		int r_a, r_b;
		double e_a, e_b,a_a,a_b;
};

<file_sep>#include "lab2.h"
#include <cmath>
using namespace std;

double Game::Expected_scoreA(int r_A,int r_B)
{
	double E_a = 1/ (1+ pow(10, ((double)r_B-r_A)/400));
	return E_a;
}

double Game::Expected_scoreB(int r_A, int r_B)
{
	double E_b = 1/ (1+ pow(10, ((double)r_A-r_B)/400));
	return E_b;
}

int Game::RatingA(int r_A, int k, double as_a, double E_a)
{
	double rate_A = r_A + k * (as_a - E_a) + 0.5;
	return rate_A;
}

int Game::RatingB(int r_B, int k, double as_b, double E_b)
{
	double rate_B = r_B + k * (as_b - E_b)+ 0.5;
	return rate_B;
}

