Classes

I have to create a program using classes, derived classes and inherited classes. The program should contain at least 5 classes and it has to be about computers, such as peripheral components and so on. I let this example here to make an idea of what i want, sorry for not being in english. Can you help me? Thanks

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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

class Persoana
{
 protected:
  char *nume,*pren;
  int varsta;
  int salariu;
 public:
  Persoana();
  Persoana(char*,char*,int,int);
  int get_sal();
  friend int get_adaug(Persoana,int);
  void get_majorare(Persoana) ;
  void afisare();
 };

Persoana::Persoana()
{
 strcpy(nume," ");
 strcpy(pren," ");
 varsta=0;
 salariu=0;
}

Persoana::Persoana(char *N,char *P,int V,int Sal)
{
 nume=new char(strlen(N)+1);
 strcpy(nume,N);
 assert(nume!=0);
 pren=new char(strlen(P)+1);
 strcpy(pren,P);
 assert(pren!=0);
 varsta=V;
 salariu=Sal;
}
int Persoana::get_sal()
{
 return salariu;
}
int get_adaug(Persoana p,int x)
{
 p.salariu=p.salariu+x;
 return 1;
}
void Persoana::get_majorare(Persoana p)
{
 int x=20;
 if(get_adaug(p,x)==1)
       cout<<"\salariu curent="<<salariu;
}
void Persoana::afisare()
{
 cout<<nume<<" "<<pren<<" "<<varsta<<" "<<salariu<<"\n";
}

class Turist:public Persoana
{
 protected:
  char *nationalitate,*preferinta_locatie,*sport_practicat;
 public:
  Turist(char *,char*,int,int,char *,char *,char *);
  ~Turist();
  void afisare();
  friend char *get_nationalitate(Turist);
  friend void set_nationalitate(char *,Turist);
  friend void set_preferinta_locatie(char *,Turist);
  friend void set_sport_practicat(char *,Turist);
  inline int get_v();
};
Turist::Turist(char *N,char *P,int V,int Sal,char *Natio,char *Pre_loc,char *Sport):Persoana(N,P,V,Sal)
{
 nationalitate=new char(strlen(Natio)+1);
 strcpy(nationalitate,Natio);
 assert(nationalitate!=0);
 preferinta_locatie=new char(strlen(Pre_loc)+1);
 strcpy(preferinta_locatie,Pre_loc);
 assert(preferinta_locatie!=0);
 sport_practicat=new char(strlen(Sport)+1);
 strcpy(sport_practicat,Sport);
 assert(sport_practicat!=0);
}
Turist::~Turist()
{
 delete nationalitate;
 delete preferinta_locatie;
 delete sport_practicat;
}
 void Turist::afisare()
{
 cout<<"\Datele turistului:\n";
 Persoana::afisare();
 cout<<nationalitate<<" "<<preferinta_locatie<<" "<<sport_practicat<<"\n";
}
char *get_nationalitate(Turist T)
{
 return T.nationalitate;
}
void set_nationalitate(char *Natio,Turist T)
{
 strcpy(T.nationalitate,Natio);
}
void set_preferinta_locatie(char *Pre_loc,Turist T)
{
 strcpy(T.preferinta_locatie,Pre_loc);
}
void set_sport_practicat(char *Sport,Turist T)
{
 strcpy(T.sport_practicat,Sport);
}
int Turist::get_v()
{
return varsta;
}
class Agent_turism:public Persoana
{
 protected:
  int cod_agent;
  char *firma_agent;
 public:
  Agent_turism(char *,char *,int ,int,int,char *);
 ~Agent_turism();
 void afisare();
 inline int get_cod_a();
 void set_sal(int);
};
Agent_turism::Agent_turism(char *N,char *P,int V,int Sal,int C,char *F):Persoana(N,P,V,Sal)
{
 firma_agent=new char(strlen(F)+1);
 strcpy(firma_agent,F);
 assert(firma_agent!=0);
 cod_agent=C;
}
Agent_turism::~Agent_turism()
{
 delete firma_agent;
}
void Agent_turism::afisare()
{
 cout<<"\Datele agentului de turism:\n";
 Persoana::afisare();
 cout<<cod_agent<<" "<<firma_agent<<"\n";
}
int Agent_turism::get_cod_a()
{
 return cod_agent;
}
void Agent_turism::set_sal(int S)
{
 salariu=S;
}
class Situatie_contracte_agent:public Agent_turism,Turist
{
 private:
  char * tip_oferta;
  int nr_contracte_incheiate;
  int nr_turisti_straini;
  int nr_turisti_romani;
 public:
  Situatie_contracte_agent(char*,char*,int ,int,char *,char *,char *,int,char *,char *,int,int,int);
 ~Situatie_contracte_agent();
 int get_nr_contracte_incheiate();
 virtual void afisare();
};
Situatie_contracte_agent::Situatie_contracte_agent(char*N,char*P,int V,int Sal,char *Natio,char *Pre_loc,char *Sport,int C,char *F,char *T,int C_A,int Romani,int Straini):Turist(N,P,V,Sal,Natio,Pre_loc,Sport),Agent_turism(N,P,V,Sal,C,F)
{
 tip_oferta=T;
 nr_contracte_incheiate=C_A;
 nr_turisti_straini=Straini;
 nr_turisti_romani=Romani;
}
Situatie_contracte_agent::~Situatie_contracte_agent()
{
}
int Situatie_contracte_agent::get_nr_contracte_incheiate()
{
 return nr_contracte_incheiate;
}
void Situatie_contracte_agent::afisare()
{
 Agent_turism::afisare();
 cout<<tip_oferta<<" "<<nr_contracte_incheiate<<" "<<nr_turisti_straini<<" "<<nr_turisti_romani;
}
void main()
{
 clrscr();
 Turist p1("Mihai","Marius",20,10000,"roman","mare","fotbal");
 Agent_turism p2("Ionescu","Laurentiu",21,14000,2,"vodafone");
 Situatie_contracte_agent p3("Popescu","Florin",22,20000,"roman","mare","fotbal",3,"Orange","3 stele",10,1,1);
 p1.afisare();
 p2.afisare();
 p3.afisare();
 getch();
 }
Last edited on
sorry for double post.. but can anyone help me out?
Well, base-derived classes have a is-it relationship, so a base class should be a more "abstract" type (even an abstract class). Just think the PC as parts of certain types.

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

class Tinichea_Electrica
{
 public:

   Tinichea_Electrica();
   Tinichea_Electrica(const Tinichea_Electrica & alta_Tinichea);
  ~Tinichea_Electrica();
   
   Tinichea_Electrica & operator=(const Tinichea_Electrica & alta);
 
   friend std::ostream operator(std::ostream & op,const Tinichea_Electrica & tin);
   virtual void Aprinde()=0;
   
   //definitiile astea se fac in header
}
class Calculator:public Tinichea_Electrica
{
    public:
 
     //chestii faine si interesante

    void Aprinde() override
    {
        std::wcout<<L"Calculatorul s-a aprins!";
    }
    /*am scris aici doar ca exemplu, dar tot in header o bagi*/
};

int main(int argc,char **argv)
{
     Tinichea_Electrica * Vechitura=new Calculator();
     Vechitura->Aprinde();
    
     return EXIT_SUCCESS;
};


Output:
Calculatorul s-a aprins!
Last edited on
that helps a little, thanks!
Topic archived. No new replies allowed.