#I have a problem with a file reading program. There's someone who can solve it?

3 messages · Page 1 of 1 (latest)

worn lightBOT
#

@ember solar

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

ember solar
#

using namespace std;
struct info_tut{
string codi_tutor;
string cog_nom;
string especialitat;
int proj_en_curs;
int proj_defensats;
};
const int MAX=100;
typedef info_tut vec_tut[MAX];
struct Tutors{
vec_tut vec;
int n;
};
struct info_proj{
string codi_alumne;
string cog_nom;
string titol_proj;
string especialitat;
string codi_tutor;
double nota;
};
const int MAX_ESTUDIANTS=1000;
const int MAX_PFG_TUTOR=10;
typedef info_proj vec_proj[MAX_ESTUDIANTS];

struct Projectes{
vec_proj vec;
int n;
};

void llegir_tutor(info_tut& tutor, ifstream& f_in, string codi_tutor){
tutor.codi_tutor=codi_tutor;
f_in>>tutor.cog_nom>>tutor.especialitat;
tutor.proj_defensats=0;
tutor.proj_en_curs=0;

}

void cerca_dico(const Tutors t, string codi, bool& trobat, int& pos){
pos=0;
trobat=false;
int esq=0, dreta=t.n, mig;
while(not trobat and esq<=dreta){
mig=(dreta+esq)/2;
if(t.vec[mig].codi_tutor==codi)
trobat=true;
else if(t.vec[mig].codi_tutor>codi)
dreta=mig-1;
else
esq=mig+1;
}
if(trobat==true)
pos=mig;
else
pos=esq;

}

void inserir_ordenat(Tutors& t, info_tut tutor, int pos){

    for(int i=t.n; i>pos; i--)
        t.vec[i]=t.vec[i-1];

    t.vec[pos]=tutor;
    t.n++;

}

void llegir_fitxer(ifstream& f_in, Tutors& t){
bool trobat=false;
int pos=0;
info_tut tutor;
t.n=0;
string codi_tutor;
f_in>>codi_tutor;
while(not f_in.eof() and t.n<MAX){
llegir_tutor(tutor, f_in,codi_tutor);
cerca_dico(t, tutor.codi_tutor, trobat, pos);
inserir_ordenat(t,tutor,pos);
f_in>>codi_tutor;
}
cout<< t.n<<endl;
f_in.close();
}

#

This is the code for the reading file without the main