S
stephane
Hi again, I would like to make sure I am right (if I am). This is the last
time I'll bother you with this code I promise! It's just that I don't have a
teacher and I have to prepare an exam. I would really be grateful if someone
could have a quick look at it!
I had to implement the surcharge of the operator+ and its utilization too.
Thoraire Thoraire:
perator+(const Thoraire& hor)const throw
(TenseignantError,Toverflow)
{
if(hor.m_nomEnseignant != m_nomEnseignant)
throw TenseignantError();
for(int i=0;i<hor.m_nbCases;i++)
{
if(m_nbCases>CcasesMax)
throw Toverflow();
m_cases[m_nbCases] = hor.m_cases;
m_nbCases++;
}
return *this;
}
// in the main file
Thoraire horaireSemestre1("Lambert");
Thoraire horaireSemestre2("Lambert");
Thoraire horaireAnnuel("Lambert");
try{
horaireAnnuel = horaireSemestre1 + horaireSemestre2;
}
catch (Toverflow){
cout<<"depassement de capacity de l'horaire"<<endl;
}
catch(TenseignantError){
cout<<"le nom de l'enseignant ne correspond pas"<<endl;
}
....
Here are my tow classes
/--
# ifndef CASE_H
# define CASE_H
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std ;
const int Clundi = 1 ;
const int Cmardi = 2 ;
const int Cmercredi = 3 ;
const int Cjeudi = 4 ;
const int Cvendredi = 5 ;
const int Csamedi = 6 ;
const int Cdimanche = 7 ;
class Tcase{
public :
Tcase (int numSemaine, int numJour, double heureDebut, double duree,char
matiere[], char classe[]= " ", char salle[]= " ") ;
int getNumSemaine() const ;
double getDuree() const ;
void printLn() const ;
private :
int m_numSemaine ; //1..53
int m_numJour ; //1..7
double m_heureDebut ; //13h30 = 13.5
double m_duree ; //2h45 = 2.75
char m_matiere[10] ; //p ex. prog7
char m_classe[10] ; //p. ex. 3IG-EE
char m_salle[10] ; //p. ex A46A
}
#endif
# ifndef HORAIRE_H
# define HORAIRE_H
# include <iostream>
# include <cstring>
using namespace std ;
#include « case.h »
class TenseignantError{} ; // the teacher is not matching
class Toverflow{} ; //capacity overflow
const int CcasesMax = 1000 ;
class Thoraire{
public :
//create a new hours schedule
Thoraire (const char nomEnseignant[]) ;
//add a case in the hours schedule
void ajouteCase (Tcase* caseHor) throw (Toverflow) ;
//calculate the total hours
double chargeHoraire() const ;
//return a sample of the schedule
//return an empty schedule if the number of the week doesn't
exist
Thoraire horaireHebdomadaire (int numSem) const ;
/*
Create a new hours schedule by fusionning both schedule, throw an exception
of class TenseignantError when the schedules don't have the same teacher
(enseignant) name.
Throw an exception of class Toverflow when the fusion create an overflow of
capacity (>CcasesMax)
*/
Thoraire operator+ (const Thoraire & hor) const throw (TenseignantError,
Toverflow) ;
Void printLn() ;
Private :
Char m_nomEnseignant [30] ; // obligatory
Tcase* m_cases[CcasesMax] ;
Int m_nbCases ;
} ;
#endif
time I'll bother you with this code I promise! It's just that I don't have a
teacher and I have to prepare an exam. I would really be grateful if someone
could have a quick look at it!
I had to implement the surcharge of the operator+ and its utilization too.
Thoraire Thoraire:
(TenseignantError,Toverflow)
{
if(hor.m_nomEnseignant != m_nomEnseignant)
throw TenseignantError();
for(int i=0;i<hor.m_nbCases;i++)
{
if(m_nbCases>CcasesMax)
throw Toverflow();
m_cases[m_nbCases] = hor.m_cases;
m_nbCases++;
}
return *this;
}
// in the main file
Thoraire horaireSemestre1("Lambert");
Thoraire horaireSemestre2("Lambert");
Thoraire horaireAnnuel("Lambert");
try{
horaireAnnuel = horaireSemestre1 + horaireSemestre2;
}
catch (Toverflow){
cout<<"depassement de capacity de l'horaire"<<endl;
}
catch(TenseignantError){
cout<<"le nom de l'enseignant ne correspond pas"<<endl;
}
....
Here are my tow classes
/--
# ifndef CASE_H
# define CASE_H
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std ;
const int Clundi = 1 ;
const int Cmardi = 2 ;
const int Cmercredi = 3 ;
const int Cjeudi = 4 ;
const int Cvendredi = 5 ;
const int Csamedi = 6 ;
const int Cdimanche = 7 ;
class Tcase{
public :
Tcase (int numSemaine, int numJour, double heureDebut, double duree,char
matiere[], char classe[]= " ", char salle[]= " ") ;
int getNumSemaine() const ;
double getDuree() const ;
void printLn() const ;
private :
int m_numSemaine ; //1..53
int m_numJour ; //1..7
double m_heureDebut ; //13h30 = 13.5
double m_duree ; //2h45 = 2.75
char m_matiere[10] ; //p ex. prog7
char m_classe[10] ; //p. ex. 3IG-EE
char m_salle[10] ; //p. ex A46A
}
#endif
# ifndef HORAIRE_H
# define HORAIRE_H
# include <iostream>
# include <cstring>
using namespace std ;
#include « case.h »
class TenseignantError{} ; // the teacher is not matching
class Toverflow{} ; //capacity overflow
const int CcasesMax = 1000 ;
class Thoraire{
public :
//create a new hours schedule
Thoraire (const char nomEnseignant[]) ;
//add a case in the hours schedule
void ajouteCase (Tcase* caseHor) throw (Toverflow) ;
//calculate the total hours
double chargeHoraire() const ;
//return a sample of the schedule
//return an empty schedule if the number of the week doesn't
exist
Thoraire horaireHebdomadaire (int numSem) const ;
/*
Create a new hours schedule by fusionning both schedule, throw an exception
of class TenseignantError when the schedules don't have the same teacher
(enseignant) name.
Throw an exception of class Toverflow when the fusion create an overflow of
capacity (>CcasesMax)
*/
Thoraire operator+ (const Thoraire & hor) const throw (TenseignantError,
Toverflow) ;
Void printLn() ;
Private :
Char m_nomEnseignant [30] ; // obligatory
Tcase* m_cases[CcasesMax] ;
Int m_nbCases ;
} ;
#endif