In: Computer Science
****************************************Instructions****************************************************
I just need a test .cpp client file that tests the new bold bits of code of the courseListType class.
It can be relatively simple. :)
Just want to let you know this is Part 2 of the question previously answered at:
https://www.chegg.com/homework-help/questions-and-answers/right-courselisttype-hold-static-50-courses-need-make-little-flexible-want-change-static-a-q57690521
***********************************************************************************************************
//courseTypeList.h
#ifndef COURSELISTTYPE_H_INCLUDED
#define COURSELISTTYPE_H_INCLUDED
#include
#include "courseType.h"
class courseTypeList {
public:
void print() const;
void addCourse(std::string);
courseTypeList(int n);
~courseTypeList();
private:
int NUM_COURSES;
int courseCount;
courseType *courses;
};
#endif // COURSELISTTYPE_H_INCLUDED
====================================================
//courseTypeList.cpp
#include
#include
#include "courseTypeList.h"
void courseTypeList::print() const {
for (int i = 0; i < courseCount; i++) {
courses[i].printCourse();
}
}
void courseTypeList::addCourse(std::string name) {
courses[courseCount++].setCourseName(name);
}
/* This allocates the array of the provided size, if no size is provided, default is 50 */
courseTypeList::courseTypeList(int n = 50)
{
courseCount = 0;
courses = new courseType[n];
NUM_COURSES = n;
}
/* destructor to for CourseListType to deallocate space whenever a declared object goes out of scope. */
courseTypeList::~courseTypeList()
{
delete courses;
}
***************************************************************************************************************
Just showing the courseType files as a reference for pieces of code in courseListType files.
***************************************************************************************************************
//courseType.h
#ifndef COURSETYPE_H_INCLUDED
#define COURSETYPE_H_INCLUDED
#include
#include
using namespace std;
class courseType {
public:
courseType(int, string);
courseType();
int getCourseID();
string getCourseName();
void setCourseID(int);
void setCourseName(string);
void printCourse();
private:
int courseID;
string courseName;
};
#endif
===================================================
//courseType.cpp
#include "courseType.h"
#include
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;
}
courseType::courseType()
{
;
}
void courseType::printCourse() {
cout << "Course ID: " << getCourseID() <<
endl;
cout << "Course Name: " << getCourseName() <<
endl;
}
//courseTypeList.h
#ifndef COURSELISTTYPE_H_INCLUDED
#define COURSELISTTYPE_H_INCLUDED
#include <string>
#include "courseType.h"
class courseTypeList {
public:
void print() const;
void addCourse(std::string);
courseTypeList(int n);
~courseTypeList();
private:
int NUM_COURSES;
int courseCount;
courseType *courses;
};
#endif // COURSELISTTYPE_H_INCLUDED
====================================================
//courseTypeList.cpp
#include <iostream>
#include <string>
#include "courseTypeList.h"
void courseTypeList::print() const {
for (int i = 0; i < courseCount; i++) {
courses[i].printCourse();
}
}
void courseTypeList::addCourse(std::string name) {
courses[courseCount].setCourseName(name);
courses[courseCount].setCourseID(1000+courseCount);
courseCount++;
}
courseTypeList::courseTypeList(int n = 50)
{
courseCount = 0;
courses = new courseType[n];
NUM_COURSES = n;
}
courseTypeList::~courseTypeList()
{
delete &courses;
}
====================================================================
//courseType.h
#ifndef COURSETYPE_H_INCLUDED
#define COURSETYPE_H_INCLUDED
#include <iostream>
#include <string>
using namespace std;
class courseType {
public:
courseType(int, string);
courseType();
int getCourseID();
string getCourseName();
void setCourseID(int);
void setCourseName(string);
void printCourse();
private:
int courseID;
string courseName;
};
#endif
===================================================
//courseType.cpp
#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;
}
courseType::courseType()
{
this-> courseID = 0;
this-> courseName = "";
}
void courseType::printCourse() {
cout << "Course ID: " << getCourseID() <<
endl;
cout << "Course Name: " << getCourseName() <<
endl;
}
==================================================
//test.cpp
#include"courseTypeList.cpp"
#include<iostream>
using namespace std;
int main()
{
courseTypeList c1(10);
c1.addCourse("CSC");
c1.addCourse("Physics");
c1.print();
}
=========================================
//Output