Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rewrite the indexing-based code in faculty.cpp with iterator-based code. #include #include faculty.h using namespace std; const unsigned Faculty::MAXSECTIONS = 150; /** * Construct a Faculty

Rewrite the indexing-based code in faculty.cpp with iterator-based code.

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions