Hello everyone I'm currently working on a program that takes a student name and number of classes. Then asks the user to enter the his classes. I have most of the program done but I'm having trouble with my dynamic array for some reason it wont let me type in more than one class before it crashes. Can someone please help me out with this.
#include <iostream>
using namespace std;
class Student
{
string name;
int numClasses, key;
string *classList;
public:
Student();
Student(int , string);
void user_Input();
void class_Output();
};
Student::Student()
{
}
Student::Student(int classes, string student)
{
numClasses = classes;
name = student;
classList = new string [numClasses];
}
void Student::user_Input()
{
cout<<"Please enter your name"<<endl;
cin>>name;
cout<<"Please enter the number of classes you have"<<endl;
cin>>numClasses;
cout<<"Please enter your classes: "<<endl;
for(int i=0; i<numClasses; i++)
{
cin>>classList[i];
}
}
void Student::class_Output()
{
cout<<"\n"<<name<<endl;
}
int main()
{
Student obj;
obj.user_Input();
obj.class_Output();
return 0;
}