Question: Create a constructor to allow Faculty objects to be constructed from a course name and an initializer_list of sections. #ifndef AUTHOR_H #define AUTHOR_H #include #include

Create a constructor to allow Faculty objects to be constructed from a course name and an initializer_list of sections.

#ifndef AUTHOR_H #define AUTHOR_H

#include #include #include "section.h"

class Faculty { private:

//** You must not change the private data members of this class, nor //** may you add additional data members. //** //** You may add private functions if you wish.

static const unsigned MAXSECTIONS;

std::string name; //!< The name of the faculty member unsigned numberOfSections; //!< Number of course sections being taught by this faculty member Section* sections; //!< Array of sections being taught by this faculty member

public: //** You may alter the public interface but it must continue to //** compile with the existing, unaltered application code and //** test code.

/** * Construct a Faculty object with empty name and no course sections. */ Faculty();

/** * Construct a faculty member with the given name and no course sections. * * @param theName name to give to this faculty member */ Faculty(std::string theName);

// The Big 3 ~Faculty(); Faculty (const Faculty& fac); Faculty& operator= (const Faculty& fac);

/** * Get the name of the faculty member. * * @return the name */ std::string getName() const {return name;}

/** * Set the name of the faculty member. * * @param theName the name to give to this faculty member. */ void setName (std::string theName) {name = theName;}

/** * How many sections are associated with this faculty member? * * @return number of sections */ unsigned numSections() const { return numberOfSections; } /** * Add a section to the list for this faculty member. Sections are kept ordered * by course number and CRN. * * @param sect a course section * @pre numSections() < MAXSECTIONS */ void add (const Section& sect);

/** * Retrieve the sectionNum_th section associated with this faculty member * * @param sectionNum identifies the section to be retrieved. * @return the desired section * @pre sectionNum < numSections() */ const Section& getSection (unsigned sectionNum) const;

/** * Ordered by name */ bool operator< (const Faculty&) const; bool operator== (const Faculty&) const;

/** * Used by the instructor for testing purposes. */ bool sanityCheck() const; };

/** * Print a faculty member name, followed, one per line, by the sections associated * with this faculty member; */ std::ostream& operator<< (std::ostream& out, const Faculty& a);

#endif

#include #include "faculty.h"

using namespace std;

const unsigned Faculty::MAXSECTIONS = 150; /** * Construct a Faculty object with empty name and no course sections. */ Faculty::Faculty() : name(), numberOfSections(0), sections(new Section[MAXSECTIONS]) { }

/** * Construct a faculty member with the given name and no course sections. * * @param theName name to give to this faculty member */ Faculty::Faculty(std::string theName) : name(theName), numberOfSections(0), sections(new Section[MAXSECTIONS]) { }

/** * Retrieve the sectionNum_th section associated with this faculty member * * @param sectionNum identifies the section to be retrieved. * @return the desired section * @pre sectionNum < numSections() */ const Section& Faculty::getSection(unsigned sectionNum) const { assert (sectionNum < numberOfSections); return sections[sectionNum]; }

/** * Add a section to the list for this faculty member. Sections are kept ordered * by course number and CRN. * * @param sect a course section */ void Faculty::add(const Section §) { assert (numberOfSections < MAXSECTIONS); sections[numberOfSections] = sect; int k = numberOfSections; while (k > 0 && sections[k] < sections[k-1]) { Section temp = sections[k]; sections[k] = sections[k-1]; sections[k-1] = temp; --k; } ++numberOfSections; }

/** * Ordered by name */ bool Faculty::operator<(const Faculty & right) const { if (name != right.name) return name < right.name; if (numberOfSections != right.numberOfSections) return numberOfSections < right.numberOfSections; for (unsigned i = 0; i < numberOfSections; ++i) if (!(sections[i] == right.sections[i])) return sections[i] < right.sections[i]; return false; }

bool Faculty::operator==(const Faculty & right) const { if (name != right.name) return false; if (numberOfSections != right.numberOfSections) return false; for (unsigned i = 0; i < numberOfSections; ++i) if (!(sections[i] == right.sections[i])) return false; return true; }

/** * Print a faculty member name, followed, one per line, by the sections associated * with this faculty member; */ std::ostream& operator<< (std::ostream& out, const Faculty& fac) { out << fac.getName() << " "; for (unsigned i = 0; i < fac.numSections(); ++i) { const Section& sect = fac.getSection(i); out << " " << sect << endl; } return out; }

// The Big 3 Faculty::~Faculty() { delete [] sections; }

Faculty::Faculty (const Faculty& fac) : name(fac.name), numberOfSections(fac.numberOfSections), sections(new Section[MAXSECTIONS]) { for (unsigned i = 0; i < numberOfSections; ++i) { sections[i] = fac.sections[i]; } }

Faculty& Faculty::operator= (const Faculty& fac) { if (this != &fac) { name = fac.name; numberOfSections = fac.numberOfSections; for (unsigned i = 0; i < numberOfSections; ++i) { sections[i] = fac.sections[i]; } } return *this; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!