Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class named Student that has three member variables: name - A string th

ID: 3667509 • Letter: C

Question

Create a class named Student that has three member variables:
name - A string 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 names of the classes that the student is enrolled in.

a. Include a two argument constructor that accepts the name of the student and the number of enrolled courses as input.
b. A method that sets all course names to "ECGR"
c. A method that outputs the names of all courses.
d. A destructor that releases all memory that has been allocated.

Below is the testing program -

int main()
{
   Student stud1("Alice", 6), stud2("Bob", 4);
   stud1.getInput();
   stud1.printClasses();
   cout << endl;
   stud2.getInput();
   stud2.printClasses();
   cout << endl;
   return 0;
}

Explanation / Answer

Answer -

#include <iostream>
#include<string>
using namespace std;

class Student
{
public:
string name;
int numClasses;
string classList[10];
Student(string Cname, int CnumClasses)
{
this->name=Cname;
this->numClasses=CnumClasses;
string classList[this->numClasses];
}
void getInput()
{
for(int i=1;i<=this->numClasses;i++)
{
this->classList[i]="ECGR";
}
}
void printClasses()
{
cout<<" Student Name :"<<this->name;
cout<<" Subjects enrolled :"<<this->numClasses;
for(int i=1;i<=this->numClasses;i++)
{
cout<<" Subject "<<i<<" :"<<this->classList[i];
}
}
~Student()
{
}
};

int main()
{
Student stud1("Alice", 6), stud2("Bob", 4);
stud1.getInput();
stud1.printClasses();
cout << endl;
stud2.getInput();
stud2.printClasses();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote