footballer 1

Write THREE (3) classes in a file named classA.h,
where class footballer functions as a base class,
while class divisionOne and class divisionTwo function as derived classes to
class footballer. Initialization through the constructor is done for variable name,
club and goals. Class dividionOne and class divisionTwo will inherit the
constructor of base class footballer. The function Salary() is an overloaded virtual
function that is defined differently in class dividionOne and class divisionTwo.
It calculates the value of bonusSalary of each footballer and prints the footballer’s division, name, club and bonusSalary in its respective output. The calculation in each division is shown below:
Class divisionOne:
bonusSalary = 1000.00 + (goals * 10000.00);
Class divisionTwo:
bonusSalary = goals * 5000.00;

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
#include <iostream>
#include <string>
using namespace std;
class footballer{
public: 
	footballer(string n, string c, int g); //constructor
	double salary();
private:
	string name;
	string club;
	int goals;
	double bonusSalary;
};
class divisionOne : public footballer {
public:
	string n;
	string c;
	int g;
private:
	double salary();
};
class divisionTwo : public footballer {
public:
	string n;
	string c;
	int g;

private:
	double salary();
};


Is this right?

p/s: i post this question earlier but that was a wrong question. This is the real one. Please do help me.
Last edited on
> Class dividionOne and class divisionTwo will inherit the constructor of base class footballer
not done

> The function Salary() is an overloaded virtual function
case sensitive
you did not make it virtual


¿what's the purpose of the 'n', 'c', 'g' variables in divisionOne and divisionTwo?
ne555


Could you please tell me which part do i need to fix since im new to c++ . Your help is much appreciated.
constructing PR.h

This is the part 2 from the above question.
Write ONE (1) class in a file named PR.h, which acts as a proxy class for classA.h constructed in Part 1. Declare an object pointer of class footballer named *temp, that is used to create new objects from either class divisionOne or class divisionTwo respectively. In the constructor, parameter name, club and goals are THREE (3) values to be sent to the respective constructors of derived classes in classA.h. Parameter choice is used as a conditional value where if choice = 1, a divisionOne object will be created, while if choice = 2, a divisionTwo object will be created. Function getbonussalary()is used to called function salary() in classA.h.
_________________________________________
PR
..................................................................................
- *temp : footballer
_________________________________________
<<constructor>>
+PR(name : string, club : string, goals : int, choice : int)
+getbonussalary()
....................................................................................

This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>
#include <iomanip>
#include "classA.h"
class PR {
public:
	PR(string name, string club, int goal, int choice);
	double getbonussalary();

private:
	footballer *temp;
};


Is my code is right?
Last edited on
There are 3 tables given. We must construct a header file named hidden.h.
......................................................
footballer (class)
# name : string
# club : string
#goals : int
# bonusSalary : double
____________________________
<<constructor>> +
footballer(n : string, c : string, g : int)
+
salary()
.......................................................

......................................................................
___________________________________
divisionOne
<<constructor>> +
divisionOne(n : string, c : string, g : double) -
salary()
.....................................................................

.....................................................................
___________________________________
divisionTwo
<<constructor>> +
divisionTwo(n : string, c : string, g : double) -
salary()
.......................................................................

This is my header for classA. Please correct if my code has any errors.


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
#include <iostream>
#include <string>
using namespace std;
class footballer{
public: //member function
	footballer(string n, string c, int g) //constructor
	{
		string n = name;
		string c = club;
		int g = goals;
	}
	double salary();
protected:
	string name;
	string club;
	int goals;
	double bonusSalary;
};
class divisionOne : public footballer {
public:
	string n = name;
	string c = club;
	int g = goals;
	double salary()
	{
		bonusSalary = 1000.00 + (goals*10000.00);
	}
private:
	double salary();
};
class divisionTwo : public footballer  {
public:
	string nameN;
	string clubC;
	int goalG;
	double salary()
	{
		bonusSalary = goals*5000.00;
	}
	
private:
	double salary();
};
Last edited on
Topic archived. No new replies allowed.