Hi everyone, I'm a total n00b at C++, I'm still learning and I've got loads of questions to ask, here's one of them ^^.
I'm going over a past paper to practice for my upcoming C++ Exam so I'll post the question in concern and I'll post what I've come up as an answer for that question. Since there are no answer's available for the past paper exams I tend to run into brick walls when I answer questions, so here goes.
Question:
c) In this question we will develop a class for a telephone book.
i) Define a phone_number class containing a name of a person/company (as a
string) and a phone number (again as a string). Include a constructor and
appropriate selector methods.
My Answer:
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 Phone_number
{
public:
string name; //name of person/company
string phoneNumber; //phone number as string
Phone_number(string name_, string phoneNumber_);
//initializes the name and phone to argurments
/*This is a selector method to get the name.*/
string Phone_number::getName()
{
return name;
}
/*This is a selector method to get the phoneNumber.*/
string Phone_number::getNumber()
{
return phoneNumber;
}
};
int main()
{
return 0;
}
|
My answer compiles without any errors on Dev C++, I just want to know if I've hit all the points on that question, also am I right in thinking a selector method is an accessor method, because thats how I've written my code :S.
P.S. Can anyone let me know if my code structure is ok or not etc. Thank you. :)