Right now we have a CourseListType that will hold a static 50 courses. Now we need to make that a little more flexible. To do that we want to change the static array to a dynamic array. So, what do we need to do? Modify CourseListType so that it contains a pointer to a CourseType rather than an array of CourseType. Modify the CourseListType constructor to create a dynamic array allocating space for a specific number of CourseType elements rather than always using 50. (Note: This is still not totally flexible, but is much better than a static limit.) Finally, we need to create a destructor to for CourseListType to deallocate space whenever a declared object goes out of scope.)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Right now we have a CourseListType that will hold a static 50 courses. Now we need to make that a little more flexible. To do that we want to change the static array to a dynamic array. So, what do we need to do?

  1. Modify CourseListType so that it contains a pointer to a CourseType rather than an array of CourseType.
  2. Modify the CourseListType constructor to create a dynamic array allocating space for a specific number of CourseType elements rather than always using 50. (Note: This is still not totally flexible, but is much better than a static limit.)
  3. Finally, we need to create a destructor to for CourseListType to deallocate space whenever a declared object goes out of scope.)

//courseListType.h file

#ifndef COURSELISTTYPE_H_INCLUDED
#define COURSELISTTYPE_H_INCLUDED

#include <string>
#include "courseType.h"

class courseTypeList {

public:
void print() const;
void addCourse(std::string);
courseTypeList();

private:
static const int NUM_COURSES = 50;
int courseCount;
courseType courses[NUM_COURSES];
};

#endif // COURSELISTTYPE_H_INCLUDED

//courseListType Implementation File

#include <iostream>
#include <string>
#include "courseTypeList.h"

void courseTypeList::print() const {

for (int i = 0; i < courseCount; i++) {
courses[i].print();
}
}

void courseTypeList::addCourse(std::string name) {
courses[courseCount++].setCourseName(name);
}

courseTypeList::courseTypeList() {
courseCount = 0;
}

===========================

This is just a reference to the courseType class that was mentioned in the above instructions:

//courseType.h file

#ifndef COURSETYPE_H_INCLUDED
#define COURSETYPE_H_INCLUDED
#include <iostream>
#include <string>

using namespace std;

class courseType {

public:
courseType(int, string);

int getCourseID();
string getCourseName();

void setCourseID(int);
void setCourseName(string);

void printCourse();

private:
int courseID;
string courseName;

};

//courseType Implementation FIile

#include "courseType.h"
#include <string>

using namespace std;

courseType::courseType(int id, string name) {
this-> courseID = id;
this-> courseName = name;
}

int courseType::getCourseID() {
return courseID;
}

string courseType::getCourseName() {
return courseName;
}

void courseType::setCourseID(int id) {
courseID = id;
}

void courseType::setCourseName (string name) {
courseName = name;
}

void courseType::printCourse() {
cout << "Course ID: " << getCourseID() << endl;
cout << "Course Name: " << getCourseName() << endl;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education