Exercice 5 l’héritage en programmation C++

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream.h>
#include <string>
#include <stdlib.h>
using namespace std;
class date{
protected:
int jour;
int mois;
int annee;
public:
date(int jr=0, int ms=0, int an=0);
void getday();
void getmonth();
void getyear();
void setday();
void setmonth();
void setyear();
virtual string datetostring();
};
class datefr:public date{
public:
datefr(int jr=0, int ms=0, int an=0);
string datetostring();
};
datefr::datefr(int jr, int ms, int an):date(jr,ms,an){}
string datefr::datetostring(){
char tab1[60]="";
char tab2[20]="";
char tab3[20]="";
cout<<"date en version europeenne"<<endl;
itoa(jour,tab1,10);
itoa(mois,tab2,10);
itoa(annee,tab3,10);
strcat(tab1,tab2);
//cout<<tab1<<endl;
strcat(tab1,tab3);
//cout<<tab1<<endl;
return tab1;
}
date::date(int jr, int ms, int an){
jour=jr;
mois=ms;
annee=an;
}
void date::getday(){
cout<<"Jour :"<<jour;
}
void date::getmonth(){
cout<<"Mois :"<<mois;
}
void date::getyear(){
cout<<"Annee :"<<annee<<endl;
}
void date::setday(){
cout<<"Entrer le jour"<<endl;
cin>>jour;
}
void date::setmonth(){
cout<<"Entrer le mois"<<endl;
cin>>mois;
}
void date::setyear(){
cout<<"Entrer l' annee"<<endl;
cin>>annee;
}
string date::datetostring(){
char tab1[60]="";
char tab2[20]="";
char tab3[20]="";
itoa(annee,tab1,10);
itoa(mois,tab2,10);
itoa(jour,tab3,10);
strcat(tab1,tab2);
//cout<<tab1<<endl;
strcat(tab1,tab3);
//cout<<tab1<<endl;
return tab1;
}
void main(){
date a;
a.setday();
a.setmonth();
a.setyear();
a.getday();
a.getmonth();
a.getyear();
string tab= a.datetostring();
for(int i=0;i<20;i++)
cout<<tab[i];
cout<<endl;
datefr b(22,9,81);
string tab1=b.datetostring();
for(int j=0;j<20;j++)
cout<<tab1[j];
cout<<endl;
}

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Besoin d'aide ?