El usuario ingresa la información sobre las fechas de nacimiento de la muestra de población en formato mes dia (MMDD). El programa basado en C++ (ROOT) genera tres histogramas (TH1F, TH2F) y guarda la información en un archivo de texto.
//////////////////////////////////////////////////////////////////////////////
// \file cumple.C
// \brief User inputs string data in MMDD format. Histrograms of some
// distros are genrated. Output file is saved in same folder.
// \version 2014-08-24 00:40
// \authors jasq
//////////////////////////////////////////////////////////////////////////////
#include // std::cout
#include // std::string, std::stof
#include // vector lib
#include // atof??
#include // for TH1F objects
#include // for TH2F objects
using namespace std;
void cumple()
{
//============================================================
// DEFINITIONS
int counter; // counter for the total number of people
std::string input; // HOW DO YOU RESTRIC TO BE 4 CHARACTERS LONG ONLY??
std::string entry;
std::vector numbers; // create a vector of strings called numbers with size zero initially
TH1F *hMonthVsFreq = new TH1F("MonthVsFreq","Mes Vs Frecuencia;Mes;Frecuencia",12,0.5,12.5);
TH1F *hDayVsFreq = new TH1F("DayVsFreq","Dia Vs Frecuencia;Dia;Frecuencia",31,0.5,31.5);
TH2F *hDayVsMonth = new TH2F("MonthVsDay","Dia Vs Mes (Frecuencia);Dia;Mes",31,0.5,31.5,12,0.5,12.5);
////////////////////////////////////////////////////////////
std::cout<<std::endl;
std::cout<<"|------ Birthday Analysis -------|"<<std::endl;
std::cout<<"| How many people share birthdays? |"<<std::endl;
std::cout<<"| You'll find out with this game! |"<<std::endl;
std::cout<<"| **** INSTRUCTIONS **** |"<<std::endl;
std::cout<<"| Type birthday in MMDD format |"<<std::endl;
std::cout<<"| Terminating with ctrl-d or 'end0'|"<<std::endl;
std::cout<<"| Type 'err0' for eliminate entry |"<<std::endl;
std::cout<<"|----------------------------------|"<<std::endl;
std::cout<<std::endl;
std::cout<<"Start typing below"<<std::endl;
std::cout<<"MMDD"<> input){
//std::cin >> input;
numbers.push_back(input);
++counter;
if(input == "err0") {
//std::cout<<"SCREAM!"<<" , "<<counter<<std::endl;
numbers.pop_back(); // eliminates 'err0' entry
--counter;
numbers.pop_back(); // eliminates real error entry
--counter;
}
if(input == "end0") {
numbers.pop_back(); // eliminates 'end0' entry
--counter;
break;
}
}
//============================================================
// SAVING RESULTS IN TEXT FILE
std::ofstream out;
out.open("data.txt");
if(!out){
cerr <<"Unable to open output data text file\n";
}
out <<"MMDD"<< endl;
//============================================================
// FILLING HISTOGRAMS
for (unsigned int k = 0; k Fill(m);
hDayVsFreq->Fill(d);
hDayVsMonth->Fill(d,m);
// COMPARE IF TWO ENTRIES OF VECTOR ARE EQUAL
// WRITES INFO ON data.txt OUTPUT FILE
out <<numbers[k] <<endl;
}
std::cout << "You entered: "<<numbers.size()<<","<<counter<Draw();
TCanvas* c2 = new TCanvas("c2","Test2");
hDayVsFreq->Draw();
TCanvas* c3 = new TCanvas("c3","Test3");
hDayVsMonth->SetStats(kFALSE);
hDayVsMonth->Draw("colz");
////////////////////////////////////////////////////////////
}