/******************************************************************************************************************** * * * This program is to adjust marks of students, which are divided into many sections, using Z-score method. * * The program needs to read input data from file "Data.txt". * * It will adjust the original marks and write the adjusted marks to a new file named "AdjustedData.txt". * * * ******************************************************************************************************************** * * * Author: Kachanon Nirunpong * * Created: 28 May 2015 * * Last update: 18 September 2015 * * * ******************************************************************************************************************** * * * Version Note: * * This alphaRoot version is a Root Macro of the alpha version. * * It can make and plot histograms of the original and the adjusted marks * * * ********************************************************************************************************************/ #include #include #include #include #include "StudentMark.h" using std::cout; using std::cin; using std::endl; using std::string; using std::ifstream; using std::ofstream; double **Xbar(std::vector, int n_item, int n_section); double **SD(std::vector student, int n_section, int n_item); int Z_Adjustment_alphaRoot() { const int N_SECTION(5); const int N_ITEM(4); std::vector student; /********** Read data from file **********/ string line; ifstream dataFile; dataFile.open("Data.txt"); if(dataFile.is_open()) { StudentMark tempStudent; int iLine(0); while(!dataFile.eof()) { std::vector tempMark; for(int j=0; j<=N_ITEM+1; j++) { double a; dataFile >> a; if(j==0) { tempStudent.SetSection(a); } else if(j==1) { tempStudent.SetNumber(a); } else { tempMark.push_back(a); } } tempStudent.SetMark(tempMark); student.push_back(tempStudent); } dataFile.close(); student.erase(student.end()); } else cout << "Unable to open file."; /*****************************************/ /************ Get mean and SD ************/ // Get number of students in each section. int n_studentsInSec[N_SECTION+1]; for(int i=0; i<=N_SECTION; i++) { n_studentsInSec[i] = 0; } for(int i=0; i student_adjusted; student_adjusted = student; for(int i=0; i tempMark; int sec(student_adjusted.at(i).Section()); for(int j=0; j::iterator it=student.begin(); it != student.end(); ++it) { cout << (*it).Section() << "-" << (*it).Number() << " "; for(int i=0; i<(*it).Mark().size(); ++i) { cout << (*it).Mark().at(i) << " "; } cout << endl; } cout << endl; // Original xbar for(int i=0; i::iterator it=student_adjusted.begin(); it != student_adjusted.end(); ++it) { cout << (*it).Section() << "-" << (*it).Number() << " "; outputFile << (*it).Section() << "-" << (*it).Number() << " "; for(int i=0; i<(*it).Mark().size(); ++i) { cout << (*it).Mark().at(i) << " "; outputFile << (*it).Mark().at(i) << " "; } cout << endl; outputFile << endl; } cout << endl; outputFile << endl; // Adjusted xbar for(int i=0; i