Answer to Question #317961 in C++ for Muhammad Usman

Question #317961

Create Class (PSL), having





1. Data items: M , W , L, T, P





2. Constructors: Defualt, Parameterized, Copy





3. Member functions: getdata(), setData(), showdata() const





4. Static class data: total number of teams (objects) created





5. Constant Object : e.g LQ







1
Expert's answer
2022-03-25T12:10:02-0400
#include <iostream>


class Object {
    int id;
public:
    Object(int i) : id(i) {}
    int getID() const { return id; }
};


class PSL {
    int M;
    int W;
    int L;
    int T;
    int P;
    static int number;
    const Object LQ;


public:
    PSL() : M(0), W(0), L(0), T(0), P(0), LQ(number)
    {
        number++;
    }
    PSL(int m, int w, int l, int t, int p) 
        : M(m), W(w), L(l), T(t), P(p), LQ(number)
    {
        number++;
    }
    PSL(const PSL& other)
        : M(other.M), W(other.W), L(other.L), 
          T(other.T), P(other.P), LQ(number)
    {
        number++;
    }
    void getData (int& m, int& w, int& l, int& t, int& p) const
    {
        m = M;  w = W;  l = L;  t = T;  p = P;
    }
    void setData(int m, int w, int l, int t, int p) 
    {
        M = m;  W = w;  L = l;  T = t;  P = p;
    }
    void showData() const
    {
        std::cout << "ID: " << LQ.getID() << ": "
                  << " M = " << M << ", W = " << W << ", L = " << L
                  << ", T = " << T << ", P = " << P << std::endl;
    }
};


int PSL::number = 0;


int main() {
    PSL psl1;
    PSL psl2(1, 2, 3, 4, 5);
    PSL psl3 = psl2;


    psl1.showData();
    psl2.showData();
    psl3.showData();


    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