how can i use this fonction ??

Dec 30, 2010 at 9:18pm
this is the code
1
2
3
4
5
6
7
8
9
void vierementgab(objet co, objet co1, int x)
                       {
                           
                           co.solde = co.solde + x;
                           co1.solde = co1.solde - 10;
                          
                           return 0;
                       }
             };

i mean i can't write for exemple p.vierementgab(p,p1,200);
how can i use this fonction ??
help plzz
Last edited on Dec 30, 2010 at 9:19pm
Dec 30, 2010 at 10:17pm
viermentgab isn't a member function of p, so there's no need for the p. at the beginning. Assumng that p and pl are of type objet, just delete the first two characters and you should be alright!

-Albatross
Dec 30, 2010 at 10:23pm
here is the full source 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
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
#include <iostream>
#include <string>
using namespace std;
        class compte

             {
                 public :
                  char nom_client[100],date_creation[100],adresse[100],Cin[100],num_compt[10];
               int gsm,solde;
               compte()
               {
                   cout<<"\n";
                 cout<<"--- la solde initiale du client en Dh  :   ";
                 cin>>solde;
                 cout<<"--- entrer le nom du client            :   ";
                 cin>>nom_client;
                 cout<<"--- entrer la date de creation         :   ";
                 cin>>date_creation;
                 cout<<"--- entrer l'adresse                   :   ";
                 cin>>adresse;
                 cout<<"--- entrer votre cin                   :   ";
                 cin>>Cin;
                 cout<<"--- entrer le numero du compte         :   ";
                 cin>>num_compt;
                 cout<<"--- entrer le numero du gsm            :   ";
                 cin>>gsm;
                  cout<<"\n";
               }
               void affiche()
               {
                   cout<<"\n\n";
                   cout<<"   le solde du client est              :  "<<solde<<"\n";
                   cout<<"   le nom du client est                :  "<<nom_client<<"\n";
                   cout<<"   la date du creation du compte est   :  "<<date_creation<<"\n";
                   cout<<"   l'adresse du client est             :  "<<adresse<<"\n";
                   cout<<"   le numero de Cin du client est      :  "<<Cin<<"\n";
                   cout<<"   le numero de compte du client est   :  "<<num_compt<<"\n";
                   cout<<"   le numero de gsm du client est      :  "<<gsm<<"\n";
                   cout<<"\n\n";
               }
               void verser(int n)
               {
                   solde = solde -1 + n;
               }
              void retrait(int m)
             {
                 solde = solde - m;
             }
             };
             class courant : public compte

             {
                 public :
                       void recharger_gsm()
                       {
                           int gs,n;
                          cout<<"entrer le num de gsm que vous voulez recharger\n";
                          cin>>gs;
                          cout<<"combien voulez-vous recharger ??\n";
                          cin>>n ;

                            do
                            {
                              cout<<"\n entrer un numero de recharge valable!!!!!!!!!  \n";
                              cin>>n;
                              cout<<"\n";
                              }
                              while(n != 5 & n != 10 & n != 20 & n != 30 & n != 50 & n != 100 & n != 200  );

                          solde = solde - n ;
                          cout<<"rechargment de "<<n<<" reussite\n\n";
                          cout<<"Votre nouveau solde est :\n\n"<<solde;
                       }


                       void vierementgab(courant co1,courant co1, int x)
                       {

                           co1.solde = co1.solde + x;
                           co.solde = co.solde - 20;
                       }
             };



             int main()
             {
                 int c,i;
               courant p,p1;
               p.vierementgab(p1,30);
               return 0;

             }



how to use that fonction so i can have (p.solde = p.solde-20) and (p1.solde = p1.solde + 30)
:) :)
Last edited on Dec 30, 2010 at 10:25pm
Dec 30, 2010 at 10:46pm
...I take back what I said about vierementgab not being a member function.

I would suggest moving the entire function (lines 76 to 81) to line 84, changing the name of the first argument to co, and making the function's variables pass by reference. Also delete the p. at line 90, and add your p as the first argument.

I probably should look around for other tiny slip-ups, but... :P

-Albatross
Last edited on Dec 30, 2010 at 10:47pm
Dec 30, 2010 at 11:00pm
ty so much friend it worked :) , but the question said that vierementgab is a member function
any ideas ??
Dec 30, 2010 at 11:10pm
They insisted, eh? Somehow I got the feeling that it wouldn't be that simple. >_>

Starting with the original code, at line 76, delete the first argument.

Then at line 80... I originally suggested that you use this, but instead I think I'll just state that for the purposes of this program you can delete the co.s and it should work just fine, as the compiler will know that you're accessing with the member of the object whose function is being called (in your case p). :)

Don't change line 90. Have fun!

-Albatross
Last edited on Dec 30, 2010 at 11:19pm
Topic archived. No new replies allowed.