basic polymorphism help

I am making a very basic parent/child class based program that shows polymorphism. It does not compile due to a few syntax errors reading "function call missing argument list. Lines 76 and 77, 81 and 82, and 86 and 87.

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
#include<iostream>

using namespace std;

class people
{
public:
	virtual void height(double h) = 0;
	virtual void weight(double w) = 0;

private:
	double h, w;
};

class students : public people
{
	void height(double h) override
	{
		cout << "Enter Height of Student:\n";
		cin >> h;
	}

	void weight(double w) override
	{
		cout << "Enter Weight of Student:\n";
		cin >> w;
	}
};

class faculty : public people
{
	void height(double h) override
	{
		cout << "Enter Height of Faculty:\n";
		cin >> h;
	}

	void weight(double w) override
	{
		cout << "Enter Weight of Faculty:\n";
		cin >> w;
	}
};

class staff : public people
{
	void height(double h) override
	{
		cout << "Enter Height of Staff:\n";
		cin >> h;
	}

	void weight(double w) override
	{
		cout << "Enter Weight of Staff:\n";
		cin >> w;
	}
};

int main()
{
	int choice;

	students studObj;
	faculty facObj;
	staff staffObj;

	cout << "Who would you like to input information for?\n";
	cout << "      1 - Student\n";
	cout << "      2 - Faculty\n";
	cout << "      3 - Staff\n";
	cin >> choice;

	if (choice == 1)
	{
		studObj.height;
		studObj.weight;
	}
	else if (choice == 2)
	{
		facObj.height;
		facObj.weight;
	}
	else if (choice == 3)
	{
		staffObj.height;
		staffObj.weight;
	}
	return 0;
}
Last edited on
Well you can't call a function without giving it arguments....

Also it seems that your parameters have the same name as the variables in your class, that means "cin>>h;" will not save the value in your object's variable, but in the argument variable of the function.
And you are only inheriting the public part of "people" class and considering that the variables of your objects are in the private part you will not be able to save your values in anything.
does this suite your pleasures:
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
#include<iostream>

using namespace std;

class people
{
public:
	virtual void height() = 0;
	virtual void weight() = 0;
	
	virtual int getHeight() = 0;
	virtual int getWeight() = 0;

	double h, w;
};

class students : public people
{
    private:
    double h, w;
    public:
	void height()
	{
		cout << "Enter Height of Student:\n";
		cin >> h;
	}

	void weight()
	{
		cout << "Enter Weight of Student:\n";
		cin >> w;
	}
	
	int getHeight(){return h;}
	int getWeight(){return h;}
};

class faculty : public people
{
    private:
    double h, w;
    public:
	void height()
	{
		cout << "Enter Height of Faculty:\n";
		cin >> h;
	}

	void weight()
	{
		cout << "Enter Weight of Faculty:\n";
		cin >> w;
	}
	
	int getHeight(){return h;}
	int getWeight(){return h;}
};

class staff : public people
{
    private:
    double h, w;
    public:
	void height()
	{
		cout << "Enter Height of Staff:\n";
		cin >> h;
	}

	void weight()
	{
		cout << "Enter Weight of Staff:\n";
		cin >> w;
	}
	
	int getHeight(){return h;}
	int getWeight(){return h;}

	
};

int main()
{
	int choice;
	
	people *Person = NULL;

	cout << "Who would you like to input information for?\n";
	cout << "      1 - Student\n";
	cout << "      2 - Faculty\n";
	cout << "      3 - Staff\n";
	cin >> choice;

	if (choice == 1)
	{
	    Person = new students();
		Person->height();
		Person->weight();
	}
	else if (choice == 2)
	{
	    Person = new faculty();
		Person->height();
		Person->weight();
	}
	else if (choice == 3)
	{
	    Person = new staff();
		Person->height();
		Person->weight();
	}
	return 0;
}
hmmm... well the idea is to be able to override the information based on the users input. I'm not sure what arguments I am supposed to give the functions if it is not returning anything. Its just simply taking the information provided by the user and regurgitating it. Nothing fancy. I figured just calling the object type of the class would essentially call that that particular function where it would then ask the user to input data.

edit: I did not see your post until just now poteto. I am about to review it and see if this works for what I am doing.
Last edited on
Pretty much sums it all up. Thanks poteto.
Topic archived. No new replies allowed.