-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompte.cpp
160 lines (147 loc) · 4.19 KB
/
Compte.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <cstdlib>
#include <string.h>
using namespace std;
const float COMMISION_VIREMENT=30;
const float TAUX_EPARGNE=0.025;
const float MIN_MONTANT_OUVERTURE=100;
//-------------------------------------
//-------------Compte------------------
//-------------------------------------
class Compte{
protected:
int numero;
double solde;
static int numeroComptes;
public:
Compte(){
numeroComptes++;
numero=numeroComptes;
}
int getNumero(){return numero;}
virtual void deposer(double montant)=0;
virtual bool virer(double montant,Compte& destinataire)
{return 0;}
bool retirer(double montant);
double consulterSolde();
void afficher(ostream&);
};
int Compte::numeroComptes=0;
//************** retirer ****************
bool Compte::retirer(double montant){
if(montant<solde){
solde-=montant;
return 1;
}
else
return 0;
}
//************* consulterSolde ****************
double Compte::consulterSolde(){
return solde;
}
//************* afficher ****************
void Compte::afficher(ostream& out)
{
cout<<"\tNumero: ";
out<<numero;
cout<<"\tSolde: ";
out<<solde;
}
//-------------------------------------
//-------------CompteCourant-----------
//-------------------------------------
class CompteCourant:public Compte{
public:
CompteCourant(double s=MIN_MONTANT_OUVERTURE):
Compte(){solde=s;}
void deposer(double montant);
bool virer(double montant,Compte& destinataire);
friend ostream& operator<<(ostream&,CompteCourant&);
};
//*************** deposer *******************
void CompteCourant::deposer(double montant){
solde+=montant;
}
//*************** virer *******************
bool CompteCourant::virer(double montant,Compte& destinataire){
if(montant+COMMISION_VIREMENT>solde)return 0;
solde-=montant+COMMISION_VIREMENT;
destinataire.deposer(montant);
return 1;
}
//*************** operator<< *******************
ostream& operator<<(ostream& out,CompteCourant& compte)
{
cout<<"Compte courant";
compte.afficher(out);//*************************
cout<<endl;
return out;
}
//-------------------------------------
//-------------CompteEparne-----------
//-------------------------------------
class CompteEpargne:public Compte{
private:
float taux;
public:
CompteEpargne(double s=MIN_MONTANT_OUVERTURE,float t=TAUX_EPARGNE):
Compte(){solde=s;taux=t;}
void deposer(double montant);
friend ostream& operator<<(ostream&,CompteEpargne&);
};
//*************** deposer *******************
void CompteEpargne::deposer(double montant){
solde+=montant+montant*taux;
}
//*************** operator<< *******************
ostream& operator<<(ostream& out,CompteEpargne& compte)
{
cout<<"Compte epargne" ;
compte.afficher(out);
cout<<"\tTaux: ";
out<<compte.taux;
cout<<endl;
return out;
}
/**************************
Test des classes comptes
***************************/
int main()
{
CompteCourant compteCourant1;
CompteCourant compteCourant2(1000.00);
CompteEpargne compteEpargne1;
CompteEpargne compteEpargne2(900.00,3.5);
cout<<compteCourant1;
cout<<compteCourant2;
cout<<compteEpargne1;
cout<<compteEpargne2;
compteCourant1.deposer(350);
cout<<compteCourant1;
compteEpargne1.deposer(1000);
cout<<compteEpargne1;
if(compteCourant2.retirer(2000))
cout<<"\nRetrait effectuee"<<endl;
else cout<<"\nRetrait non effectuee"<<endl;
cout<<compteCourant2;
if(compteCourant2.retirer(500))
cout<<"\nRetrait effectuee"<<endl;
else cout<<"\nRetrait non effectuee"<<endl;
cout<<compteCourant2;
CompteCourant compteCourant3(5000.);
cout<<compteCourant3;
if(compteCourant3.virer(120,compteCourant2))
cout<<"\nVirement effectuee"<<endl;
else cout<<"\nVirement non effectuee"<<endl;
cout<<compteCourant3;
cout<<compteCourant2;
CompteEpargne compteEpargne4;
cout<<compteEpargne4;
if(compteCourant3.virer(120,compteEpargne4))
cout<<"\nVirement effectuee"<<endl;
else cout<<"\nVirement non effectuee"<<endl;
cout<<compteCourant3;
cout<<compteEpargne4;
return 0;
}