I am trying to add a Try-Catch and throw 'exception' for possible wrong input data. I've also got to add a vector template container and at least one member function of the vector template from STL and it has to be implemented into my original code which comes after the following paragraph. Can anyone help me implement these things:
1) A Try-Catch & Throw (exception handler) for wrong input data
2) Add a vector template container with at least 1 member function of the vector template from the STL.
cout << "\n \nThe following 5 students are being popped out of the array! \n" << endl;
stack.pop();
stack.pop();
stack.pop();
stack.pop();
stack.pop();
cout << "\n \nThe remaining students left in the array are: \n" << endl;
stack.display();
system("PAUSE");
return 0;
}
Any help would be great! Thank you very much for your help!
Are you required to do #1? If so, I feel very very sorry for you. It's poor design and shouldn't be done that way.
As for #2, there are a few things you have to consider.
Your "Studentrecords" class seems to be a container, however it has very tight coupling. You should remove the "student" struct from it (just keep it outside the class) and you should rename it so it is more generic (it will be come your vector class). I'd suggest a name that doesn't include the word "student".
The other thing is that you will need to define all the member functions inline for it to become a template. Like this:
1 2 3 4 5 6 7
struct MyClass
{
void f()
{
//definition right here, inside the class
}
};
Lastly, you'll need to convert it into a template. This involves using the template keyword correctly, and replacing all references to "student" with the name of the template parameter.