pointers and inherit classes

Hi guys, I am brand new here. I am having a problem with pointers in c++. I want to set a random wage for a class object, but I don't understand how to change the value. All my classes (Gerente, Programador, Analista) inherit from Funcionario, but I just can't set their wage and I am a little lost where is my mistake. If someone could give some light that would be great

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  void main()
{
	Gerente *gerente; 
	gerente = new Gerente[3];
	Programador *programador;
	programador = new Programador[10];
	Analista *analista;
	analista = new Analista[5];
	srand(time(NULL));

	for (int i = 0; i < 10; i++)
	{
		programador[i].setDinheiro(rand() % 501 + 2000.00);
		programador[i].getDinheiro();
		//cout << programador[i];
		//&programador[i].setDinheiro;
		//*(programador + i);
		//cout << &programador[i] << endl;
	}
cout << programador[i].getDinheiro();
this is giving me a same pattern of number
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <iostream>
 #include <cstdlib>
 
 struct Programador
 {
     int x;
     void setDinheiro(int val){x = val;};
     int getDinheiro(){return x;};
 };
 
 int main()
{
	Programador programador[10];
	srand(time(NULL));

	for (int i = 0; i < 10; i++)
	{
		programador[i].setDinheiro(rand() % 501 + 2000.00);
		
		std::cout << programador[i].getDinheiro() << '\n';
	}
}
Topic archived. No new replies allowed.