C++ class HelP

How can i do this?

Create a Friend class that contains a first name, last name, a birthday, and a telephone number. Create a Contacts class that contains an array of Friend as well as the owner's name and cell phone Number.
What exact part are you stuck on, we can't help until you show us some code. Do you know how to create a class? Do you know how friends work in C++?

http://www.cplusplus.com/doc/tutorial/classes/
http://www.cplusplus.com/doc/tutorial/inheritance/
i did this but not sure if its correct


class Friend
{
public:
string f_name;
string l_name;
int birthday;
int tel_num;
}

class Contacts
{
public:
string f_name;//ALL CLASS VARIABLES ARE PUBLIC
string l_name;
int tel_num;
int birthday;

Contacts()
{
f_name= NULL;
l_name=NULL
tel_num= NULL;
birthday =NULL;
}

void input_contacts_name(string f){//function to take contact name
f_name=f;
}
void input_contacts_name(string l){//function to take contact name
l_name=l;
}
void input_contacts_number(int x){//function to take contact number
tel_num=x;
}
void inut_contacts_birthday(int b){//function to take contact birthday
birthday=b;
}
}
1) Your problem description says that Contacts shoud contain an array of Friend. I don't see that anywhere in your Contacts class.

2) Why are you making all your data members public? That completely destroys encapsulation, which is one of the fundamental principle of OOP. If your data members are all public, then what's the point of using classes at all?

3) What sort of string are you using? The standard library std::string? If so, then f_name and l_name aren't pointers, so it's impossible to set them to NULL.

4) If you want to initialise integers to 0, then initialise them to 0. Don't try initialising them to NULL, because that's counterintuitive and confusing.

5) If you want to initialise your data members, use an initialisation list, rather than assigning values insde the constructor after they've been initialised to default values.

6) Your specification doesn't say anything about Contacts storing the owner's birthday, yet you've given Contacts a birthday data member.
Topic archived. No new replies allowed.