mettre une class dans une autre
bonjour j'essaye un exercice qui consiste a crée une class bibliotheque et une class livre , ensuite je doit pouvoir ajouter des livre dans une bibliotheque.
j'auraiss voulu savoir si ma méthode étais bonne?
je vouss met le code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include "bibliothque.h"
using namespace std;
livre::livre(string t, string a, int is)
{
titre=t;
auteur=a;
isbn=is;
}
Bib::Bib(string v, string a, int c)
{
cout<<"constructeur de bibliotheque"<<endl;
i=0;
ville=v;
adresse=a;
code=c;
}
void Bib::afficher()
{
cout<<ville <<" " <<adresse <<" " <<code<<endl;
}
void livre::afficher()
{
cout<<titre<<" " <<auteur<<" " <<isbn <<endl;
}
void Bib::ajouterlivre(string t, string a, int is)
{
tab[i].modifier(t,a,is);
i++;
}
void livre::modifier(string t, string a, int is)
{
titre=t;
auteur=a;
isbn=is;
}
void Bib::affichertous()
{
for (int j=0;j<i;j++)
{
tab[j].afficher();
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| #include "bibliothque.h"
void main()
{
Bib b1("comines","chaussée de ten brielen",7780);
b1.afficher();
b1.ajouterlivre("proutttt","jeanlol",1000);
b1.affichertous();
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <iostream>
#include <string>
#define MAX 10
using namespace std;
class livre{
string titre;
string auteur;
int isbn;
public:
livre(string t="",string a="",int is=0);
void afficher();
void modifier(string t="",string a="",int is=0);
};
class Bib{
string ville;
string adresse;
int code;
int i;
livre tab[MAX];
public:
Bib(string v,string a,int c);
void afficher();
void ajouterlivre(string t="",string a="",int is=0);
void affichertous();
}; |
mon prog fonctionne mais jee ne sais pas si c'est bon.
et est ce que ça un nom de faire ce genree de chose en c++ ?