Question

In: Computer Science

Current Assignment: **It is important to note that we are learning about Composition right now.** Now...

Current Assignment:

**It is important to note that we are learning about Composition right now.**

Now that we have the CourseType class (included courseType code below instructions) we want to create another "collection" class to hold more than one. This way we can add one class to the StudentType and have a full list of courses. There are many (better) ways we could structure this collection, but for now we're going to use a static array:

  • Create a new class named CourseListType that contains an array of CourseTypes as its private data. (You can limit the size to something reasonable, like 50 courses.) You'll also want to add some basic public functions like print and AddCourse.
  • Make sure you test your new CourseListType class by declaring an object and testing at least it's constructor.
  • The courseListType does not need to be complex. It can be a simple program

Submit: Commented test, implementation and header files (.cpp and .h) for new CourseListType.

My courseType header 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;

};


#endif // COURSETYPE_H_INCLUDED

My courseType Implementation file:

#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;
}

courseType test program

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

using namespace std;

int main() {

courseType c1(101, "English");
courseType c2(102, "Mathematics");
courseType c3(103, "Oceanography");

vector <courseType> courses;

courses.push_back(c1);
courses.push_back(c2);
courses.push_back(c3);

for(int i = 0; i < courses.size(); i++) {
cout << "======================================" << endl;
cout << "\t COURSE #" << (i+1) << " DETAILS " << endl;
cout << "======================================" << endl;
courses.at(i).printCourse();
cout << endl;
}
return 0;
}

Solutions

Expert Solution

// courseType.h

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

using namespace std;

class courseType {

public:
// Add a default constructor in the courseType class so that static array of courses can be created(as static array will call default constructor of courseType for all its entries)
courseType();
courseType(int, string);
  
int getCourseID();
string getCourseName();

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

void printCourse();

private:
int courseID;
string courseName;

};

#endif // COURSETYPE_H_INCLUDED

// end of courseType.h

//courseType.cpp
#include "courseType.h"

// default constructor that sets courseID and courseName to 0 and empty string respectively
courseType::courseType()
{
courseID = 0;
courseName = "";
}

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;
}

// end of courseType.cpp

// courseListType.h
#ifndef COURSELISTTYPE_H_INCLUDED
#define COURSELISTTYPE_H_INCLUDED

#include "courseType.h"

class courseListType
{
public:
courseListType();
void addCourse(courseType course);
void printCourseList();

private:
int numCourses; // current number of courses in the list
courseType courses[50]; // static array of maximum 50 courses
};

#endif // COURSELISTTYPE_H_INCLUDED

//end of courseListType.h

// courseListType.cpp

#include "courseListType.h"

// default constructor that creates an empty list
courseListType::courseListType()
{
numCourses = 0;
}

// function to add course to list
void courseListType:: addCourse(courseType course)
{
if(numCourses < 50) // array is not full, add course at the end of list
{
courses[numCourses] = course;
numCourses++;
}
}

// function to display the courses in the list
void courseListType:: printCourseList()
{
if(numCourses == 0) // empty list
cout<<"There are no courses in the list"<<endl;
else
{
for(int i=0;i<numCourses;i++){
courses[i].printCourse();
cout<<endl;
}
}
}

// end of courseListType.cpp

// courseListTypeTest.cpp : C++ program to test the courseListType class
#include <iostream>
#include <string>
#include "courseListType.h"

int main()
{
courseListType list;
list.addCourse(courseType(101, "English"));
list.addCourse(courseType(102, "Mathematics"));
list.addCourse(courseType(103, "Oceanography"));

list.printCourseList();
  
   return 0;
}

// end of courseListTypeTest.cpp

Output:


Related Solutions

Now that we know a bit more about epidemiologic curves and the important steps in an...
Now that we know a bit more about epidemiologic curves and the important steps in an outbreak investigation, let's see how this is playing out with COVID-19. 1. You've probably heard public health officials say that we need to "flatten the curve". What does this statement mean and why is it so important? 2. Discuss one method public health officials have implemented to flatten the COVID-19 curve. Do you think this method is effective? Explain. 3. Will the nation-wide Black...
We have prepared an article about the general economic situation of India before. Now, as assignment...
We have prepared an article about the general economic situation of India before. Now, as assignment 2, we have an assignment to answer these three questions with India data. It is very important that it is not too short since we will write it in the form of a report. I am sending at the same time because the questions are not separated. I would be glad if you help. my questions are; 1)India Check their X, IM, NX by...
we are facing aging society right now, because young people do not care about health that...
we are facing aging society right now, because young people do not care about health that much. if today tou were in charge of global house agency manager, what would you do in promoting healthy habit?
Determine the current in the circuit by calculating the current in the resistor. Note: We will...
Determine the current in the circuit by calculating the current in the resistor. Note: We will use I (and VR since it has the same phase) for reference throughout our analysis (VR/R = I). Determine the capacitance of the circuit from its reactance, the current calculated above, and the frequency of the source (VC/I = XC). Determine the inductance of the circuit from three different voltage measurements, the current calculated in step 1, and the frequency of the source, following...
It is important to note that we are assuming that so far there has been NO...
It is important to note that we are assuming that so far there has been NO governmental action regarding the virus. So, there has been no quarantining, there have been no “Stay-at-Home” orders, there have been no orders closing businesses, and, generally, there have been no decisions by a governmental entity regarding the virus.Draw a graph to explain your answer. First, explain (in words) what an “efficient” outcome is in the present context. Then, present an economic argument, using a...
What are the best sectors to invest in the US right now, given the current economic...
What are the best sectors to invest in the US right now, given the current economic conditions? Rank the sectors in the order of allocation % and explain in detail your reasoning.
How is evolution affecting us/our world right now, as we speak?
How is evolution affecting us/our world right now, as we speak?
This week we are learning about atomic physics. At some point we talked about photons. Do...
This week we are learning about atomic physics. At some point we talked about photons. Do some research about photons and share your findings with your group about photons, what they are, why scientists introduced them, and what they do in our understandings of the nature of light.
Please work on the assignment below: Please review the instructions INTEGRATIVE LEARNING ASSIGNMENT Writing about Statistics...
Please work on the assignment below: Please review the instructions INTEGRATIVE LEARNING ASSIGNMENT Writing about Statistics Choose one of the following Health issues (migraine cures, cancer cures, the spread of malaria, pediatric health issues, blood pressure medicines, controversial or novel techniques for curing illnesses….) Write the General summary of the article including the type of study discussed Statistics involved in the topic (be very detailed) Technical details or ne points about the topic Conclusion, including your opinions about the study...
When learning about depreciation and how to record it into the journal, we hear about an...
When learning about depreciation and how to record it into the journal, we hear about an account called accumulated depreciation and that it is a contra asset account. Please explain what this account is and what it means to be a contra asset account.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT