Gavin Deane wrote:
> osmium wrote:
> > template <class T>
> > class Gpa
> > {
> > public:
> > Gpa();
> > ~Gpa();
> > void input(); /* number of inputs are
> > unknown. Terminate with EOF*/
> > double cal_gpa();
> > private:
> > T* presult; // pointer to an array
> > int na; // current size of result array.
> > // try starting with na = 6 or so.
> > };
> > Some people would prefer vector to array, I don't have any really strong
> > feelings there.
>
> Really? The assignment calls for an array, so presumably a vector would
> not be acceptable. But having said that, I would have thought this is a
> perfect example of how vectors could make your life easier. Nothing in
> the spec says anything about how many courses a particular student
> might have taken. The examples happen to use 5, but that's not stated
> as a requirement. Using an array implies needing to keep count of how
> many entries you've made so far, and reallocating as required. Exactly
> the sort of things a vector does for you. Unless the point of this
> assignment is to learn how to do that sort of thing by hand (unlikely -
> since the point seems to be something about templates) the requirement
> to use an array looks to me like an unnecessary complication. The only
> other possibility that occurs is that, after this assignment is handed
> in, the class will be shown how much simpler it could be with a vector,
> but again, that message would probably be confused amongst the
> templates.
>
> Gavin Deane
I don't know and I don't care what is a GPA, but we have to admit it is
a good exercise to build an array<> or a matrix<> template in the
classroom.
It is very good for learning templates, constructors, destructors,
memory management, first class objects...
Diego
|