i have this question i dont know how to access to display function and make it friend in member class.and i dont know if my const id number is correct or not ?.
Display() function , which is a friend function that prints the member's information.
Note that:
oEach member has a unique membership number which is generated at the first time when a member joins the club and doesn’t not change after that.
oMembership period is the number of years since a member joined the club until 2015.
thank you so much and this is my try and i didnot finish yet.
I don't see why you would want to create a friend display function to print the public attributes of the Member class. I would just make a public: display function for the Member class directly. But if you're trying to make a friend function then you'll need to create its prototype like this:
class Member
{
friendvoid display(Member&); // Reference a Member object
private: // or protected:
string Members_name;
constint Membership_number;
Date Membership_date;
int Membership_period;
public:
Member(string n,Date d,int p):Members_name(n),Membership_number(1),Membership_date(d),Membership_period(p){}
string getmembersname(){return Members_name; }
void setmembersname(string n){Members_name=n;}
int getmembershipnumber(){return Membership_number;}
Date getmembershipdate(){return Membership_date;}
void setmembershipdate(Date d){Membership_date=d;}
int getmembershipperiod(){return Membership_period; }
void setmembershipperiod(int p){Membership_period=p;}
} // you forgot to put a closing curly brace
Then you can define your prototype in a .cpp file and #include your class.h file.
thank you so much for your help ,but what i mean is diffrenet ,i put commants on my code which i need to print but i dont know how to print this fnction once , ihop you can help me with it
#include<iostream>
#include<string>
usingnamespace std;
class Date {
private:
int day;
int month;
int year;
public:
Date(int d, int m, int y)
{
setDay(d);
setMonth(m);
setYear(y);
}
int getDay() {
return day;
}
int getMonth() {
return month;
}
int getYear() {
return year;
}
void setDay(int d){
day = d;
}
void setMonth(int m){
if(m < 1||m >12)
{
month =1;
cout << "Month set as 1" << endl;
}
else
month = m;
}
void setYear(int y){
year = y;
}
// display date function
void displayDate()
{
cout << getMonth() << "/" << getDay() << "/" << getYear() << endl;
}
};
class Member{
friendvoid display(Member&);
private:
string Members_name;
constint Membership_number;
Date Membership_date;
int Membership_period;
public:
Member(string n,Date d,int p):Members_name(n),Membership_number(1),Membership_date(d),Membership_period(p){}
string getmembersname(){return Members_name; }
void setmembersname(string n){Members_name=n;}
int getmembershipnumber(){return Membership_number;}
Date getmembershipdate(){return Membership_date;}
void setmembershipdate(Date d){Membership_date=d;}
int getmembershipperiod(){return Membership_period; }
void setmembershipperiod(int p){Membership_period=p;}
friendvoid display(Member& b){
cout << b.getMonth() << "/" << b.getDay() << "/" << b.getYear() << endl;
//cout<<"the name is :"<<getmembername();
//cout<<"the member is :"<<getmembershipnumber();
//cout<<"the member ship period:"<<getmembershipperiod();
}
};
int main(){
Member obj("savanh",4,7,2015,56);
obj.display();//which is print all the information in Member class and the date in display fun in Date class together.
system("pause");
return 0;
}