Answer to Question #201313 in C++ for Prathamesh Sawant

Question #201313

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().


1
Expert's answer
2021-05-31T12:50:03-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog