Create a class turned student that hat three member variables name - A swing tha
ID: 3632764 • Letter: C
Question
Create a class turned student that hat three member variables name - A swing that stores the name of the student numClasses - An integer that tracks how many courses the student is currently enrolled in classList - A dynamic array of strings used to store the names of the classes that the student is enrolled in Write appropriate constructor(s), mutator, and accessor methods for the class along with the following: A method that inputs all values from the user, including the list of class names. Ibis method will have to support input for an arbitrary number of classes. A method thM outputs the name and list of all courses. A method that resets the number of classes to 0 and the classlist to an empty list. An overloaded assignment operator that correctly males a new copy of the list of courses. A destructor that releases all memory that has been allocated. Write a main method that tests all of your functions. Hint: Recall that cin variable leases a newline in the buffer. This can be a problem if you arc mixing cin variable and getline. Use cin.ignore to discard the newline. I give you part of the code. you complete itExplanation / Answer
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class Student
{
public:
//constructors
Student();
Student(string, int, string[]);
//distructor
~Student();
// setters and getters
string GetName();
void SetName(string name);
int GetNumClasses();
void SetNumClasses(int numClasses);
void GetClassList(string list[], int &size);
void SetClassList(string list[], int size);
// inputs data from the console
void InputData();
//outputs data to the console
void OutputData();
// resets the classes
void ResetClasses();
// overloaded assignment operator
Student& operator = ( const Student &rightSide);
private:
string name; //name of the student
int numClasses; //num ber of classes he enrolled
string *classList; // classes list
};
//default constructor
Student::Student()
{
SetName("");
SetClassList(NULL, 0);
}
//argumented constructor
Student::Student(string name, int numClasses, string list[])
{
SetName(name);
SetClassList(list, numClasses);
}
//returns student name
string Student::GetName()
{
return name;
}//sets student name
void Student::SetName(string name)
{
this-> name = name;
}
//returns number classes student enrolled
int Student::GetNumClasses(){
return numClasses;
}//sets number of clsses enrolled
void Student::SetNumClasses(int numClasses)
{
this->numClasses = numClasses;
}
//copies the classes list to passed parameter
void Student::GetClassList(string list[], int &size)
{
size = numClasses;
for(int i=0; i< size; i++)
list[i] = classList[i];
}
//sets the classes list
void Student::SetClassList(string list[], int size)
{
numClasses = size;
for(int i=0; i< size; i++)
classList[i] = list[i];
}
//inputs data from the console
void Student::InputData()
{
cout << "Enter Student Name: ";
cin >> name;
cout << "Enter number of classes enrolled: ";
cin >> numClasses;
classList = new string[numClasses];
cout << "Enter classes: ";
for(int i=0; i<numClasses; i++)
cin >> classList[i];
}
//outputs data to the console
void Student::OutputData()
{
cout<<" Student Name: "<<name<<endl;
cout<<"Classes Enrolled: "<<numClasses<< endl;
for(int i=0; i<numClasses; i++)
cout << classList[i] << " ";
}
//resets class list
void Student::ResetClasses()
{
numClasses = 0;
classList = NULL;
}
//overloaded assignment operator
Student& Student::operator=(const Student &rightSide)
{
SetName(rightSide.name);
SetClassList(rightSide.classList, rightSide.numClasses);
return *this;
}
//destructor
Student::~Student()
{
delete []classList;
}
//main function
int main()
{
Student s;
s.InputData();
s.OutputData();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.