les pointeurs et les structures
Salut!!
Quelle est la différence entre ces trois programme ...
ُet comment chaque programme a travaille
-->PLZ Centrée sur la fonction void s(--)
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
| #include<iostream>
using namespace std;
struct stag
{
char nom[80];
char prenom[80];
int age;
float note;
};
void s(stag &f)
{
cout<<"ENTRER LE NOM : "<<endl;
cin>>f.nom;
cout<<"ENTRER LE PRENOM : "<<endl;
cin>>f.prenom;
cout<<"DONNEZ L'AGE : "<<endl;
cin>>f.age;
cout<<"DONNEZ LA NOTE : "<<endl;
cin>>f.note;
}
void a(stag f)
{
cout<<"LE NOM EST "<<f.nom<<endl;
cout<<"LE PRENOM EST "<<f.prenom<<endl;
cout<<"L'AGE EST "<<f.age<<endl;
cout<<"LA NOTE EST "<<f.note<<endl;
}
main()
{
cout<<"ENTRER LE NOMBRE DES STAGIAIRES "<<endl;
int n;cin>>n;
stag *fx=new stag[n];
for(int i=0;i<n;i++)
{s(fx[i]);cout<<"\t---"<<endl;}
for(int i=0;i<n;i++)
{a(*(fx+i));cout<<"\t---"<<endl;}
cout<<"\n\n";system("pause");
} |
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
| #include<iostream>
using namespace std;
struct stag
{
char nom[80];
char prenom[80];
int age;
float note;
};
void s(stag &f,int n)
{
for(int i=0;i<n;i++){
cout<<"ENTRER LE NOM : "<<endl;
cin>>f.nom;//pourquoi f.nom et pas f[i].nom ??????!!!!!
cout<<"ENTRER LE PRENOM : "<<endl;
cin>>f.prenom;
cout<<"DONNEZ L'AGE : "<<endl;
cin>>f.age;
cout<<"DONNEZ LA NOTE : "<<endl;
cin>>f.note;cout<<"\t---"<<endl;}
}
void a(stag f,int n)
{
for(int i=0;i<n;i++){
cout<<"LE NOM EST "<<f.nom<<endl;
cout<<"LE PRENOM EST "<<f.prenom<<endl;
cout<<"L'AGE EST "<<f.age<<endl;
cout<<"LA NOTE EST "<<f.note<<endl;cout<<"\t---"<<endl;}
}
main()
{
cout<<"ENTRER LE NOMBRE DES STAGIAIRES "<<endl;
int n;cin>>n;
stag *fx=new stag[n];
s(*fx,n);
a(*fx,n);
cout<<"\n\n";system("pause");
} |
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
| #include<iostream>
using namespace std;
struct stag
{
char nom[80];
char prenom[80];
int age;
float note;
};
void s(stag *f,int n)//????????!!!!!!!!!!!!!!!!
{
for(int i=0;i<n;i++){
cout<<"ENTRER LE NOM : "<<endl;
cin>>f[i].nom;
cout<<"ENTRER LE PRENOM : "<<endl;
cin>>f[i].prenom;
cout<<"DONNEZ L'AGE : "<<endl;
cin>>f[i].age;
cout<<"DONNEZ LA NOTE : "<<endl;
cin>>f[i].note;cout<<"\t---"<<endl;}
}
void a(stag *f,int n)
{
for(int i=0;i<n;i++){
cout<<"LE NOM EST "<<f[i].nom<<endl;
cout<<"LE PRENOM EST "<<f[i].prenom<<endl;
cout<<"L'AGE EST "<<f[i].age<<endl;
cout<<"LA NOTE EST "<<f[i].note<<endl;cout<<"\t---"<<endl;}
}
main()
{
cout<<"ENTRER LE NOMBRE DES STAGIAIRES "<<endl;
int n;cin>>n;
stag *fx=new stag[n];
s(fx,n);
a(fx,n);
cout<<"\n\n";system("pause");
} |
َ