Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Putting it all together, Classes, Objects, Inheritance: Assignment Create a

ID: 3697949 • Letter: C

Question

C++

Putting it all together, Classes, Objects, Inheritance: Assignment

Create a class called FitnessMember that has only one instance variable, called name. The person class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name.

Define a class called Athlete which is derived from FitnessMember. An Athlete class has the Athlete's name (inherited from the FitnessMember class) and ID number of type String.

Define a class called Trainer whose objects represent fitness centers trainers. Derive this class from the class FitnessMember as well. A Trainer object has the Trainer's name (inherited from the FitnessMember class) and a specialty as a String (for example, Weight, Aquatics, Cardio, Nutrition, etc.), and an training session fee (use the type double).

A Billing class will contain an Athlete object and a Trainer object.

Give all your classes a reasonable complement of constructors, and accessor and mutator functions.

Write a main test program that creates at least two Athletes, at least two Trainers, and at least two Billing records and displays the total income from the Billing records. Your tests should test all the functions and constructors defined in your program.

Explanation / Answer

#include <string>
#include <vector>
#include <iostream>

class FitnessMember
{
   public:
       std::wstring name;

       virtual void setName(const std::wstring &name)
       {
               this->name = name;
       }

       virtual std::wstring getName()
       {
               return name;
       }
};

class Athelete : public FitnessMember
{
   public:
       std::wstring ID;

       Athelete(const std::wstring &name)
       {
               FitnessMember::name = name;
       }

       virtual void setID(const std::wstring &ID)
       {
               this->ID = ID;
       }

       virtual std::wstring getID()
       {
               return ID;
       }
};

class Trainer : public FitnessMember
{
   public:
       std::wstring speciality;

       Trainer(const std::wstring &name)
       {
               FitnessMember::name = name;
       }

       virtual void setSpeciality(const std::wstring &sp)
       {
               speciality = sp;
       }

       virtual std::wstring getSpeciality()
       {
               return speciality;
       }
};

class Billing
{
   public:
       int amt = 0;

       virtual void generateBill(Athelete *a, Trainer *t)
       {
               if (t->speciality.equalsIgnoreCase(L"weight") || t->speciality.equalsIgnoreCase(L"cardio"))
               {
                       amt = 300;
                       std::wcout << std::wstring(L"BILL FOR : ") << a->name << std::wstring(L" IS : $") << amt << std::endl;
               }
               else
               {
                           amt = 350;
                       std::wcout << std::wstring(L"BILL FOR : ") << a->name << std::wstring(L" IS : $") << amt << std::endl;
               }
       }
};

class AtheleteTest
{
       static void main(std::vector<std::wstring> &args)
       {
               Athelete *a1 = new Athelete(L"XXX");
               Athelete *a2 = new Athelete(L"YYY");

               a1->setID(L"A123");
               a2->setID(L"A456");

               Trainer *t1 = new Trainer(L"AAA");
               Trainer *t2 = new Trainer(L"BBB");

               t1->setSpeciality(L"cardio");
               t2->setSpeciality(L"nutrition");

               Billing *b1 = new Billing();
               Billing *b2 = new Billing();

               b1->generateBill(a1, t1);
               b2->generateBill(a2, t2);

               std::wcout << std::wstring(L"TOTAL BILL IS : $") << (b1->amt << b2->amt) << std::endl;
       }
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote