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

C++ assignment...not java. Please read the below carefully: For this assignment,

ID: 3766219 • Letter: C

Question

C++ assignment...not java.

Please read the below carefully:

For this assignment, we will write an application that uses the three design patterns discussed in this weeks lecture. Specifically, you are a professor and you are writing an application to help you manage information about your students. The class of interest is called ClassRecord. It has a method called buildClassBookthat takes an array of strings. This method, supposedly, does many things, including sorting the names in the array.

Download file firstClassRecord.cpp. It uses a bubble sort algorithm to sort and print the names. There are many ways to sort an array, and bubble sort is the slowest. Let’s design ClassRecord so that it could use different sorting algorithms for the students array.

Reify method sort. Use the Strategy Design Pattern to allow ClassRecord to seamlessly use one of several possible sort strategies including QuickSort, MergeSort, and HeapSort.

Add another class called CompositeSort. Use the Composite Design Pattern that somehow combines different sort methodologies based on some heuristic of the array. (No complex heuristic algorithm need be implemented)

Implement ClassRecord as a Singleton class.

**** Note: This exercise is a vehicle for experimenting with three design patterns, not producing an application.   Do not spend time researching the above sorting algorithms. It is not required that you implement any sort code. All of your sort algorithms can be implemented as skeletons:

      void sort (string names []) {

            cout << “sorting with merge sort” << endl;

     }

Your final source will include all the classes and a main program that acts as a small driver for the application. Submissions that do not compile will receive a grade of zero.  

Here is the source code, firstClassRecord.cpp.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

class ClassRecord {
public:
   void buildClassBook (string students[100]) {

       // sort students alphabetically

       sort (students) ;

       // do other things to prep class book

   }
   void sort (string students[100]) {
       int i;
       for (i=0; i<100; i++)
           if (students[i].length() == 0)
               break;
       int length = i;
       bool clean ;
       do {
           clean = true;
           for (int j=1; j<length; j++)
               if (students[j] < students[j-1]) {
                   string temp = students[j];
                   students[j] = students[j-1];
                   students[j-1] = temp;
                   clean = false;
               }
       } while (!clean) ;
       for (int k = 0; k< length; k++)
           cout << students[k] << endl;
   }
};

int main () {
   ClassRecord record;
   string students [100] = {"Bill", "Jose", "Philipe", "Chaing", "Louise",
       "Mary", "Lisa"};
   record.buildClassBook(students);
}

Explanation / Answer

Each pattern has a section devoted to it, describing the following things:

• A pattern name.

• A description of the kinds of problems to which one might apply the pattern.

• An abstract description of a design problem and how its solution can be obtained.

• A discussion of the results and trade-offs that can occur when the pattern is applied.

Design patterns are used for many different purposes. Most describe how to separate code by responsibility. They are subdivided into three categories: Creational, Structural, and Behavioral. Structural patterns describe how to organize objects and connect them. Behavioral patterns describe how to organize code. Creational patterns describe how to organize code that manages object creation.

#include <iostream>

#include <map>

#include <string>

using namespace std;

enum RECORD_TYPE_en

{

   RECORD,

    BOOK,

    STUDENT

};

class Record

{

    public :

       Record() {}

       virtual ~Record() {}

      virtual Record* clone()=0;

       virtual void print()=0;

};

class classRecord : public Record

{

    private:

      string m_bookName;

      int m_ID;

    public:

      classRecord(string bookName, int ID)

        : Record()

        , m_bookName(bookName)

        ,m_ID(ID)

      {

      }

   

      classRecord(const classRecord& classRecord)

        : Record(classRecord)//call the base default copy constructor

      {

        m_className = classRecord.m_className;

        m_ID = classRecord.m_ID;

      }

        ~classRecord() {}

      Record* clone()

      {

        return new classRecord(*this);

      }

   

      void print()

      {

        cout << "Class Record" << endl

          << "Name : " << m_bookName << endl

          << "Number: " << m_ID << endl << endl;

      }

};

  class BookRecord : public Record

{

    private :

      string m_bookName;

   

      int m_ID;

   

    public :

      bookRecord(string bookName, int ID)

        : Record()

        , m_bookName(bookName)

        , m_ID(ID)

      {

      }

   

      bookRecord(const bookRecord& bookRecord)

        : Record(bookRecord)

      {

        m_bookName = bookRecord.m_bookName;

        m_ID = bookRecord.m_ID;

      }

   

      ~BookRecord() {}

      Record* clone()

      {

        return new bookRecord(*this);

      }

   

      void print()

      {

        cout << "Book Record" << endl

          << "Name : " << m_bookName << endl

          << "Number: " << m_ID << endl << endl;

      }

};

class PersonRecord : public Record

{

    private :

      string m_personName;

     

      int m_age;

   

    public :

      PersonRecord(string personName, int age)

        : Record() , m_personName(personName), m_age(age)

      {

      }

   

      PersonRecord(const PersonRecord& personRecord)

        : Record(personRecord)

      {

        m_personName = personRecord.m_personName;

        m_age = personRecord.m_age;

      }

   

      ~PersonRecord() {}

   

      Record* clone()

      {

        return new PersonRecord(*this);

      }

   

    void print()

    {

      cout << "Person Record" << endl

        << "Name : " << m_personName << endl

        << "Age : " << m_age << endl << endl ;

    }

};

class RecordFactory

{

    private :

      map<RECORD_TYPE_en, Record* > m_recordReference;

    public :

      RecordFactory()

      {

        m_recordReference[CAR] = new CarRecord("Ferrari", 5050);

       m_recordReference[BOOK] = new BookRecord("Yamaha", 2525);

        m_recordReference[PERSON] = new PersonRecord("Tom", 25);

      }

   

      ~RecordFactory()

      {

        delete m_recordReference[CAR];

        delete m_recordReference[BOOK];

        delete m_recordReference[PERSON];

      }

   

      Record* createRecord(RECORD_TYPE_en enType)

      {

        return m_recordReference[enType]->clone();

      }

};

int main()

{

    RecordFactory* poRecordFactory = new RecordFactory();

    Record* poRecord;

    poRecord = poRecordFactory->createRecord(CAR);

    poRecord->print();

    delete poRecord;

   

    poRecord = poRecordFactory->createRecord(BOOK);

    poRecord->print();

    delete poRecord;

   

    poRecord = poRecordFactory->createRecord(PERSON);

    poRecord->print();

    delete poRecord;

    delete poRecordFactory;

    return 0;

}

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