use of class

HI: I need to write a code for the following calss implementation

Implement the following class ‘enrollmentList’. ‘enrollmentList’ maintains a list of students using an array.
The key function for ‘enrollmentLilst’ is the ‘resize’ function. The effect of calling resize(x) should be to dynamically allocated a new array of size x, copy the elements of array items into this new array, free the original array items, and set items to point to the new array. With this function, add should call resize to a larger value than the current array capacity if the array is already full. Similarly, delete should call resize to a smaller value than the current capacity if the number of items is much smaller than the current capacity. This way, new room is always made for newly added items, and there is never too much memory wasted.
Challenge: Assume that, as a rule, numItems must always be at least 25% of the capacity of the array so that you are guaranteed to never waste too much memory. Given this restriction, make your list perform as fast as possible for a large number of additions and deletions. To maximise speed, how big should you resize the array to when you run out of room, and by how much and when should you decrease the size?

This is what I have done so far. Up to this point,I suppose, I determine the size of the array and introduce the name of the students. I just want to know if I am in the right path.

#include <iostream>
#include <string>
using namespace std;
class student
{
public:
double gpa;
};
class enrollmentlist
{
private:
int capacity;
string * list;

public:
void studentlist(int n);
void addItem(string item);
string name;

};
void enrollmentlist::studentlist(int numstudents)
{
capacity=numstudents;
list = new string[numstudents];

}
void enrollmentlist::addItem(string item)
{

for(int i=0; i<=capacity-1; i++)
{

cout << "Enter a student name: " << endl;
cin>>list[i];
}

}
int main()
{
int numstudents;
cout << "How many students should we store in the array?" << endl;
cin >> numstudents;
enrollmentlist mylist;
mylist.studentlist(numstudents);
mylist.addItem("");
return 0;
}


Thanks




This site has a good example on expanding arrays:
http://www.fredosaurus.com/notes-cpp/newdelete/55dynexample.html

Do you have to use arrays or can you use vectors?

With your student class maybe each student should have a unique ID or a name, then you could pass a student object to your enrolment class. You program doesn't use any students at the moment
Topic archived. No new replies allowed.