A sports club needs a program to manage its members. Your task is to define and test a class calledÂ
Member for this purpose.
Define the Member class usingÂ
Private data members:Â
Member Number, Name, Birthday.Â
Public Methods:
Constructor with one parameter for each data member
Access methods for each data member.
The birthday is read-only.
A method for formatted screen output of all data members.
Implement the necessary methods.
Test the new Member class by creating at least two objects with the data of your choice and calling theÂ
methods you defined.Â
Add a static member called ptrBoss to the class. If no chairperson has been appointed, the pointer shouldÂ
point to NULL.
Additionally, define the static access methods getBoss() and setBoss(). Use a pointer toÂ
set and return the object in question.
Test the Member class by reading the number of an existing member, making theÂ
member the new chairperson and displaying the chairperson using getBoss().
#include <iostream>
#include <string>
using namespace std;
class Member{
    int number;
    string name, birthday;
    static int *ptrBoss;
    public:
    Member(int n, string s, string b): number(n), name(s), birthday(b){
    }
    string getname(){
        return name;
    }
    int getnumber(){
        return number;
    }
    string getbirthday() const{
        return birthday;
    }
    void display(){
        cout<<"Member number: \t"<<number<<endl;
        cout<<"Member name: \t"<<name<<endl;
        cout<<"Birthday: \t"<<birthday<<endl;
    }
    static void setBoss(int cp){
        ptrBoss = new int(cp);
    }
    static int getBoss(){
        return *ptrBoss;
    }
};
int* Member::ptrBoss = NULL;
int main(){
    Member one(187, "John", "1/1/1999"), two(252, "James", "2/2/2000");
    cout<<one.getnumber()<<endl;
    cout<<one.getname()<<endl;
    cout<<one.getbirthday()<<endl;
    one.display();Â
    cout<<endl<<two.getnumber()<<endl;
    cout<<two.getname()<<endl;
    cout<<two.getbirthday()<<endl;
    two.display();
    Member::setBoss(one.getnumber());
    cout<<"Chariperson is member number "<<Member::getBoss();
    return 0;
}
Comments
Leave a comment