my first attempt at writing code using classes - please help

Pages: 12
This is my very first attempt at using classes. I've read the primer chapters and several online tutorials. But, I'm afraid my code is a mess. So many errors at compile and I haven't even added data integretity checking yet.

Any help is greatly appreciated.

These are some of the errors:
1>------ Build started: Project: Lab8, Configuration: Debug Win32 ------
1>  Lab8.cpp
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(37): error C2511: 'Student::Student(std::string,std::string,std::string,std::string,std::string,std::string,int,int)' : overloaded member function not found in 'Student'
1>          c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(5) : see declaration of 'Student'
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(83): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]


and many many more that do not fit into this content area

and my 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
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
#include <iostream>
using namespace std;
 	
//declaration section
class Student {
      private:
              string FirstName;
              string LastName;
			  string City;
			  string State;
			  string Telephone;
			  string Year;
			  int Enrolled;			//number of credit hours currently enrolled
			  int Completed;		//number of credit hours completed prior to current semester
			  int Graduation;  		//number of credit hours needed for graduation after current semester
			  void setGraduation() {Graduation = 90 - Completed - Enrolled;}	//total hours needed for graduation are 90
//interface
      public:
			 Student();
             Student(string,string,string,string,string,string, int, int, int); //constructor                     
             void setFirstName(string);
             void setLastName(string);
             void setCity(string);
			 void setState(string);
			 void setTelephone(string);
			 void setYear(string);
			 void setEnrolled(int);
			 void setCompleted(int);
			 void setGraduation(int);
			 void printStudentDetails();
};

//implementation
Student::Student() {
}
Student::Student(string Fname, string Lname, string stdCity, string stdState, string stdTelephone, string stdYear, int stdEnroll, int stdComplete)
{
	FirstName = Fname;
	LastName = Lname;
	City = stdCity;
	State = stdState;
	Telephone = stdTelephone;
	Year = stdYear;
	Enrolled = stdEnroll;
	Completed = stdComplete;
}
void Student::setFirstName(string Fname)
{
	FirstName = Fname;
}
void Student::setLastName(string Lname)
{
	LastName = Lname;
}
void Student::setCity(string stdCity)
{
	City = stdCity;
}
void Student::setState(string stdState)
{
	State = stdState;
}
void Student::setTelephone(string stdTelephone)
{
	Telephone = stdTelephone;
}
void Student::setYear(string stdYear)
{
	Year = stdYear;
}
void Student::setEnrolled(int stdEnroll)
{
	Enrolled = stdEnroll;
}
void Student::setCompleted(int stdComplete)
{
	Completed = stdComplete;
}
void setGraduation();

void Student::printStudentDetails()
{
	cout << "Student: " << FirstName << " " << LastName<< endl
		<< "Location: " << City << ", " << State << endl
		<< "Telephone: " << Telephone << endl
		<< "Currently enrolled: " << Enrolled << " credit hours" << endl
		<< "Hours completed: " << Completed << " creit hours" << endl
		<< "Credit hours required for graduation: " << Graduation << " credit hours"
		<< endl;
}

int main ()
{
using namespace std;
	Student s;
	cout << "Enter student first name: ";
	&Student::setFirstName;
	cout << "Enter student last name:  ";
	&Student::setLastName;
	cout << "Enter student city of residence:  ";
	&Student::setCity;
	cout << "Enter student state of residence:  ";
	&Student::setState;
	cout << "Enter the student credit hours currently enrolled:  ";
	&Student::setEnrolled;
	cout << "Enter the student credit hours completed:  ";
	&Student::setCompleted;
	



	s.printStudentDetails();
	system ("pause");
}
Student(string,string,string,string,string,string, int, int, int); //constructor Six strings and three ints...

Student::Student(string Fname, string Lname, string stdCity, string stdState, string stdTelephone, string stdYear, int stdEnroll, int stdComplete)
Six strings and TWO ints.

&Student::setFirstName;
What are you trying to do with this line of code? It makes no sense and does nothing.
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
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
#include <iostream>
#include <cstdlib>

using namespace std;

//declaration section
class Student {
      private:
              string FirstName;
              string LastName;
			  string City;
			  string State;
			  string Telephone;
			  string Year;
			  int Enrolled;			//number of credit hours currently enrolled
			  int Completed;		//number of credit hours completed prior to current semester
			  int Graduation;  		//number of credit hours needed for graduation after current semester
			  void setGraduation() {Graduation = 90 - Completed - Enrolled;}	//total hours needed for graduation are 90
//interface
      public:
             Student(){};
             Student(string,string,string,string,string,string, int, int); //constructor
             void setFirstName(string);
             void setLastName(string);
             void setCity(string);
			 void setState(string);
			 void setTelephone(string);
			 void setYear(string);
			 void setEnrolled(int);
			 void setCompleted(int);
			 void setGraduation(int);
			 void printStudentDetails();
};

//implementation
Student::Student(string Fname, string Lname, string stdCity, string stdState, string stdTelephone, string stdYear, int stdEnroll, int stdComplete)
{
	FirstName = Fname;
	LastName = Lname;
	City = stdCity;
	State = stdState;
	Telephone = stdTelephone;
	Year = stdYear;
	Enrolled = stdEnroll;
	Completed = stdComplete;
}
void Student::setFirstName(string Fname)
{
	FirstName = Fname;
}
void Student::setLastName(string Lname)
{
	LastName = Lname;
}
void Student::setCity(string stdCity)
{
	City = stdCity;
}
void Student::setState(string stdState)
{
	State = stdState;
}
void Student::setTelephone(string stdTelephone)
{
	Telephone = stdTelephone;
}
void Student::setYear(string stdYear)
{
	Year = stdYear;
}
void Student::setEnrolled(int stdEnroll)
{
	Enrolled = stdEnroll;
}
void Student::setCompleted(int stdComplete)
{
	Completed = stdComplete;
}
void setGraduation();

void Student::printStudentDetails()
{
	cout << "Student: " << FirstName << " " << LastName<< endl
		<< "Location: " << City << ", " << State << endl
		<< "Telephone: " << Telephone << endl
		<< "Currently enrolled: " << Enrolled << " credit hours" << endl
		<< "Hours completed: " << Completed << " creit hours" << endl
		<< "Credit hours required for graduation: " << Graduation << " credit hours"
		<< endl;
}

int main ()
{
using namespace std;
	Student s;
	cout << "Enter student first name: ";
	&Student::setFirstName;
	cout << "Enter student last name:  ";
	&Student::setLastName;
	cout << "Enter student city of residence:  ";
	&Student::setCity;
	cout << "Enter student state of residence:  ";
	&Student::setState;
	cout << "Enter the student credit hours currently enrolled:  ";
	&Student::setEnrolled;
	cout << "Enter the student credit hours completed:  ";
	&Student::setCompleted;

	s.printStudentDetails();
	system ("pause");
}
one thing is missed, in number 19 to put {}:

Student(){};
because it is a constructor!
Hi noo,

In main{}:

1
2
3
Student s;

&Student::setFirstName;


should be:

1
2
3
4
Student s; //s is the student object

s.setFirstName; //access public functions with the dot operator


It is a common newbie mistake to provide public get & set functions for each private member variable.

The thing is - you may as well have all the member variables public.

Instead, it is better to think about how the information for your object is going to be used.

If the info is not going to be changed once it is set, then you can get away with just a constructor to set everything - no set functions at all. If you just want to print the value of all the member variables to the screen - then you can have a function to do that - no get functions.

It is a different story if the values are going to change once they have been set, or you need to do calculations using the value of the member variables.

Even so, try to think of how it might work in real life. For example you might have a function ChangeAddress which changes all the address variables, as opposed to separate functions to change each one individually.

Remember, a function that is part of the class has access to all the class private or protected members, so if you need to do a calculation involving several member variables, make it a member function.

This is all part of the idea of encapsulation.

There is a convention about naming member variables that is popular: All member variables start with m_ . This is so you can easily differentiate them from arguments in functions. Like this:

1
2
3
void Student::setYear(string Year) {
	m_Year = Year;
}


Hope all goes well.

Edit:

Also you need to #include <string> to use strings.

Edit2:

You & szandi are missing lots of semicolons. Lines 83 to 88.
Last edited on
Thank you all for your help. I made a few changes on my code and I am getting fewer errors, but still many.

I've been thinking about what you explained TheIdeasMan.

I've been working on it for a "few hours". :-|

I am under some restrictions:
data members must be private
member functions must be ppublic
use the set member function
use the get member function (which I forgot to do)
validate the data (which I haven't added yet)

so, am I using a constructor when I am not supposed to or don't need to? is it a "one or the other" thing but not both?

I had orginally tried s.set... instead of &Student, but I received an errror message indicating I should use &Student.

Also, in this piece of code, I get an error saying "no instance of overloaded function "Student::Student" matches the specified type"

1
2
3
4
//implementation
Student::Student() {
}
Student::Student(string m_FirstName, string m_LastName, string m_City, string m_State, string m_Telephone, string m_Year, int m_Enrolled, int m_Completed)


Other errors below:
1>------ Build started: Project: Lab8, Configuration: Debug Win32 ------
1>  Lab8.cpp
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(35): error C2084: function 'Student::Student(void)' already has a body
1>          c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(20) : see previous definition of '{ctor}'
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(38): error C2511: 'Student::Student(std::string,std::string,std::string,std::string,std::string,std::string,int,int)' : overloaded member function not found in 'Student'
1>          c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(6) : see declaration of 'Student'
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(96): error C2264: 'Student::Student' : error in function definition or declaration; function not called
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(98): error C3867: 'Student::setFirstName': function call missing argument list; use '&Student::setFirstName' to create a pointer to member
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(100): error C3867: 'Student::setLastName': function call missing argument list; use '&Student::setLastName' to create a pointer to member
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(102): error C3867: 'Student::setCity': function call missing argument list; use '&Student::setCity' to create a pointer to member
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(104): error C3867: 'Student::setState': function call missing argument list; use '&Student::setState' to create a pointer to member
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(106): error C3867: 'Student::setEnrolled': function call missing argument list; use '&Student::setEnrolled' to create a pointer to member
1>c:\users\fgower\documents\visual studio 2010\projects\lab8\lab8\lab8.cpp(108): error C3867: 'Student::setCompleted': function call missing argument list; use '&Student::setCompleted' to create a pointer to member
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I'll post my modified code in the next post since I know I'll run out of room here.

Again, any help is greatly appreciated.
Code (for now). I'm going to keep working on it while hoping you guys will help me move in the right direction with it.

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
#include <iostream>
#include <string>
using namespace std;
 	
//declaration section
class Student {
      private:
              string FirstName;
              string LastName;
			  string City;
			  string State;
			  string Telephone;
			  string Year;
			  int Enrolled;			//number of credit hours currently enrolled
			  int Completed;		//number of credit hours completed prior to current semester
			  int Graduation;  		//number of credit hours needed for graduation after current semester
			  void setGraduation() {Graduation = 90 - Completed - Enrolled;}	//total hours needed for graduation are 90
//interface
      public:
		  Student(){};
             Student(string,string,string,string,string,string, int, int, int); //constructor                     
             void setFirstName(string);
             void setLastName(string);
             void setCity(string);
			 void setState(string);
			 void setTelephone(string);
			 void setYear(string);
			 void setEnrolled(int);
			 void setCompleted(int);
			 void setGraduation(int);
			 void printStudentDetails();
};

//implementation
Student::Student() {
}
Student::Student(string m_FirstName, string m_LastName, string m_City, string m_State, string m_Telephone, string m_Year, int m_Enrolled, int m_Completed)
{
	FirstName = m_FirstName;
	LastName = m_LastName;
	City = m_City;
	State = m_State;
	Telephone = m_Telephone;
	Year = m_Year;
	Enrolled = m_Enrolled;
	Completed = m_Completed;
}
void Student::setFirstName(string m_FirstName)
{
	FirstName = m_FirstName;
}
void Student::setLastName(string m_LastName)
{
	LastName = m_LastName;
}
void Student::setCity(string m_City)
{
	City = m_City;
}
void Student::setState(string m_State)
{
	State = m_State;
}
void Student::setTelephone(string m_Telephone)
{
	Telephone = m_Telephone;
}
void Student::setYear(string m_Year)
{
	Year = m_Year;
}
void Student::setEnrolled(int m_Enrolled)
{
	Enrolled = m_Enrolled;
}
void Student::setCompleted(int m_Completed)
{
	Completed = m_Completed;
}
void setGraduation();

void Student::printStudentDetails()
{
	cout << "Student: " << FirstName << " " << LastName<< endl
		<< "Location: " << City << ", " << State << endl
		<< "Telephone: " << Telephone << endl
		<< "Currently enrolled: " << Enrolled << " credit hours" << endl
		<< "Hours completed: " << Completed << " creit hours" << endl
		<< "Credit hours required for graduation: " << Graduation << " credit hours"
		<< endl;
}

int main ()
{
using namespace std;
	Student s;
	cout << "Enter student first name: ";
	s.setFirstName;
	cout << "Enter student last name:  ";
	s.setLastName;
	cout << "Enter student city of residence:  ";
	s.setCity;
	cout << "Enter student state of residence:  ";
	s.setState;
	cout << "Enter the student credit hours currently enrolled:  ";
	s.setEnrolled;
	cout << "Enter the student credit hours completed:  ";
	s.setCompleted;
	



	s.printStudentDetails();
	system ("pause");
}
Dear nool!
please Do write your code "&Student::setFirstName;" instead of "s.setFirstName;"

Please try it again because it worked me well on my CodeBlocks!!

i hope you will believe in me what i told you above! :)

Good luck!
I am under some restrictions:
data members must be private
member functions must be ppublic
use the set member function
use the get member function (which I forgot to do)
validate the data (which I haven't added yet)


That is fine, but I am saying you shouldn't have a get / set function for each member. Try to group them together to reflect what might happen in the real world. I explained it in detail in my last post.

so, am I using a constructor when I am not supposed to or don't need to? is it a "one or the other" thing but not both?


No your constructor is fine - except for the error that Moschops pointed out.

Remember a constructor is only called once when the object is created. This might be all you need, but if you need to change the value of a member variable after that - then you need a function to do it.

Now for the errors:

You are still missing semicolons at the end of lines 84 to 89.

On lines 98 to 108, you are not calling the functions correctly. The function call must match the specification of the arguments in the declaration and implementation of the function. That is all 3 must match.

You also haven't got any cin statements to actually get a value from the user.

HTH

TheIdeasMan, what you posted earlier "just clicked" and I was coming back to tell you I'm scrapping this and basically starting over.

But, I found more info from you. :-)))


OK, I'm going to go change all my million sets to one setdata or something like that.

I corrected the error Moschops pointed out earlier. Thanks Moschops!

As far as the semicolons...I thought I didn't need semicolongs between the << of the cout statement. For example, isn't this correct? cout<<"Please correct"<<"me."<<endl; I only put the semicolon after the final endl right? Or does each and every endl need a semicolon even if it all belongs to the same cout statement?

OK, it's back to the drawing board for me now that I have a better direction to go in with your advice.

Thanks!!! (I'll be back with more spaghetti code soon) :-)
As far as the semicolons...I thought I didn't need semicolongs between the << of the cout statement. For example, isn't this correct? cout<<"Please correct"<<"me."<<endl; I only put the semicolon after the final endl right? Or does each and every endl need a semicolon even if it all belongs to the same cout statement?


Semicolons are used to end an ordinary statement in C / C++. Lines 84 to 89 don't have them.

szandi wrote:
please Do write your code "&Student::setFirstName;" instead of "s.setFirstName;"

Please try it again because it worked me well on my CodeBlocks!!


I don't understand that at all. What is the purpose of the leading &? Using the scope operator is not valid IMO, you don't call classes - you call member functions from objects.

Also line 80 is invalid - did you mean to define the function there instead?

Now before you start again..............

It is good practice to put the class declaration into a header file, then put the implementation of the functions into a .cpp file. Then have another .cpp file with main() in it. Include the header file whenever you want to use an object of that class type. In your case main() is where you create the objects and call their functions.

If you are using an IDE, you can do this automatically by using the class wizard. This will create the files, and skeletons of the class, plus function stubs for constructors etc. Also when you create a function in the header file, you should be able to get it to create a stub in the .cpp file.

You should also be able to get your IDE to do automatic braces, indenting, maybe background compilation so it shows errors as you type - this might help with missing semicolons.

Also Consider better names for functions / variables / objects. s is not a particularly good name for an object.

HTH
TheIdeasMan wrote:
Semicolons are used to end an ordinary statement in C / C++. Lines 84 to 89 don't have them.
Those lines are all one statement.
It is good practice to put the class declaration into a header file, then put the implementation of the functions into a .cpp file. Then have another .cpp file with main() in it. Include the header file whenever you want to use an object of that class type. In your case main() is where you create the objects and call their functions.


I was going to split things up at the end. I guess it's standard to split everything up from the beginning?

My IDE does do the indenting and it underlines in red anything that has an error. I can scroll over the red marked item and get the error description. I think everything else it turned off.

I went back to scratch with my code and got it to compile. But I feel like I am way off base from what I'm supposed to be doing.

*use classes
*create class objects to store information
*use private data members
*use public member functions
*write the set member function like setData to set the value of the data members
*write the get member function like getName to retrieve values
*validate the data from user input ( a couple of rules given)
*display all information for at least 5 objects

my new code below :-( it compiles but I don't think I'm using what I'm supposed to...

Ahh good point. My bad - one day I will learn to read !!


However I would have made them individual cout statements.
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
#include <iostream>
#include <string>
#include<conio.h>
using namespace std;
 	
//declaration section
class Student {
      private:
              string FirstName;
              string LastName;
			  string City;
			  string State;
			  string Telephone;
			  string Year;
			  int Enrolled;			//number of credit hours currently enrolled
			  int Completed;		//number of credit hours completed prior to current semester
			  int Graduation;  		//number of credit hours needed for graduation after current semester
			
//interface
      public:
		    void getData()	//request user data input
			{
				cout << "Enter student first name: ";
				cin >> FirstName;
				cout << "Enter student last name:  ";
				cin >> LastName;
				cout << "Enter student city of residence:  ";
				cin >> City;
				cout << "Enter student state of residence:  ";
				cin >> State;
				cout << "Enter student telephone number:  ";
				cout << "Enter the student credit hours currently enrolled:  ";
				cin >> Enrolled;
				cout << "Enter the student credit hours completed:  ";
				cin >> Completed;
			}
			void setGraduation()			//total hours needed for graduation are 90
			{
				Graduation = 90 - Completed - Enrolled;		//calculate how many remaining hours required for graduation
			}	
			void displayData()		
			{
				cout << "Student: " << FirstName << " " << LastName<< endl;
				cout << "Location: " << City << ", " << State << endl;
				cout << "Telephone: " << Telephone << endl;
				cout << "Currently enrolled: " << Enrolled << " credit hours" << endl;
				cout << "Hours completed: " << Completed << " credit hours" << endl;
				cout << "Credit hours required for graduation: " << Graduation << " credit hours" << endl;
			}
};


int main ()
{
	Student student;
	student.getData();
	student.setGraduation();
	student.displayData();
return 0;	
}
I was going to split things up at the end. I guess it's standard to split everything up from the beginning?


Yes, because it involves creating files - might as well do that at the start.


I went back to scratch with my code and got it to compile. But I feel like I am way off base from what I'm supposed to be doing.

*use classes
*create class objects to store information
*use private data members
*use public member functions
*write the set member function like setData to set the value of the data members
*write the get member function like getName to retrieve values
*validate the data from user input ( a couple of rules given)
*display all information for at least 5 objects


You are doing all those things except the validation - so your project is looking good so far - just need to split into files as mentioned.

Perhaps setGraduation could be called CalcGraduation?

Once that is sorted, you could move to the next step of having a class that contains a <list> or <vector> of students. Then you can have info about many student rather than just one. This class would also be responsible for calculating statistics about students, or printing out all of them for example.

It could also have functions for adding / deleting students say.
Last edited on
oh, I was trying to code an array of objects --- getting "i is undefined error" on

student[i].calcGraduation();

1
2
3
4
5
6
7
8
9
int main ()
{
	Student student[5];
	for (int i=0; i<5; i++)
	student[i].getData();
	student[i].calcGraduation();
	student[i].displayData();
return 0;	
}


edit: you think I should try a list instead?

I don't see where I'm using the set and get member functions in my code...
Last edited on
Well you could make an array of students like you are doing - that is fine for a simple application.

1
2
3
4
5
for (int i=0; i<5; i++) {  //braces for compound statements
	student[i].getData();
	student[i].calcGraduation();
	student[i].displayData();
}


I don't see where I'm using the set and get member functions in my code...


The code in the for loop uses them.

Declaring the variable i like that is OK, as long as you only need it inside the loop braces, because it goes out of scope after that. If you want access to it afterwards, declare it before the loop.

HTH

The code in the for loop uses them.


Really? I was looking for something like setFirstname and getFirstname.

Thanks for reminding me about the braces!!! My head is spinning, earlier I forgot to use #include <string> and now I forgot the braces.

I'm going back to the code to see if I can build in some data validation into the input request.

Thank you so much!!!
Really? I was looking for something like setFirstname and getFirstname.


But you don't have these functions, the getData function does all that. Actually that name is a bit confusing.

Get implies you are retrieving the member variable value, Set implies assigning a value to a member variable.

It is confusing for newbies, because you are getting the input form the user, but this is opposite to the conventional meaning.

I look forward to seeing how you get on. :)
Pages: 12