need a bit of help

please look at the 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
  # include <iostream>
# include <string>

using namespace std;


class PERSONNEL
{
	public:
		PERSONNEL()
		{
		NAME;
		IDnum = 0;
		}
		
		string NAME;
		double IDnum;
		
		double FNIDnumber(double)
		{
			ID = IDnum;
		}
		string returnNAME()
		{
			return NAME;
		}
		
		double returnID ()
		{
			return ID;
		}
		
	private:
		double ID;
		
};

class STUDENT: PERSONNEL
{

	public:
	STUDENT()
	{
		CMajor;
	}
	string CMajor;
	
	string FNMajor(string PMajor)
	{
		MAJOR = CMajor;
	}
	
	string returnMajor()
	{
		return MAJOR;
	}
	
 	private:
	string MAJOR;
};


main()
{

PERSONNEL pers;
STUDENT stud;

cout << "Please type the student's name ? " << endl;
cin >> pers.NAME;


cout << "\nNow type the ID of the student ? "  << endl;
cin >> pers.IDnum;



cout << " What is the declared Major ? : " << endl;
cin >> stud.CMajor;

	cout << name() ; 
	cout << student() ;
	cout << personnel() ;



return 0;
}
Okay, I looked at it. What help do you need?

Line 63: main must be type int.

Line 12,44: What are these statements supposed to be doing? They have no effect.

Line 61: You have no function named name(). Did you mean pers.returnNAME() ?
Line 62: You have no function names student(). Did you stud.returnNAME() ?
Line 63: You have no function named personell(). Did you mean pers.returnNAME() ?
Hey! @AbstractionAnon,
thanks for the reply. I wanted the user to input the desired data and then print out the output of the user input

12-44
they are not returning any value. how can i fix it ?
Last edited on
Lines 12,44: These lines are unnecessary. Both NAME and MAJOR are strings. Strings are initialized to empty string by default, so no explicit initialization is needed.

class PERSONNEL: Why do you have ID (private) and IDnum (public)?

Line 19: What is this function supposed to be doing? You pass it an argument, but you don;t give the argument a name.

Line 21: You're setting ID to IDnum (which was initialized to 0. Again, what's the purpose of the two ID numbers?

Here's a cleaned up version of your program:
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
#include <iostream>
#include <string>
using namespace std;

class PERSONNEL
{	
protected:
	double ID;
	string NAME;	

public:
	PERSONNEL ()	
	{	ID = 0;
	}

	void set_name(const string & name)	//	setter for NAME
	{	NAME = name;
	}

	void set_id (double id)
	{	ID = id;
	}

	string get_name() const				// Does not modify instance
	{	return NAME;
	}

	double get_id () const
	{	return ID;
	}

};

class STUDENT : public PERSONNEL
{	string MAJOR;

public:
	STUDENT () 
	{}
	
	void set_major (const string & major)
	{	MAJOR = major;
	}

	string get_major() const  // does not modify instance
	{	return MAJOR;
	}

	void print () const
	{	cout << "Name = " << NAME << endl;
		cout << "Id = " << ID << endl;
		cout << "Major = " << MAJOR << endl;
	}
};


int main()
{	STUDENT stud;
	string name;
	double id;
	string major;

	cout << "Please type the student's name ? ";
	cin >> name;
	stud.set_name(name); 

	cout << "\nNow type the ID of the student ? ";
	cin >> id;
	stud.set_id(id);

	cout << "\nWhat is the declared Major ? " << endl;
	cin >> major;
	stud.set_major(major); 

	stud.print();	
	return 0;
}


Last edited on
Topic archived. No new replies allowed.