int main(void)
{
int s = 0;
int *instances;
Student object;
cout<<"please enter the object size";
cin>>s;
object *instances = new (object[s]);
for (int i = 0; i < s; i++ ){
cout<<"enter the data for the " <<i+1<<" student"<<endl;
cout<<"enter First name ";
cin>>object[i].Firstname;
cout<<"enter last name ";
cin>>object[i].Lastname;
cout<<"enter your first test scores ";
cin>>object[i].grades[0];
cout<<"enter your second test scores ";
cin>>object[i].grades[1];
cout<<"enter your second test scores ";
cin>>object[i].grades[2];
cout<<"enter your second test scores ";
cin>>object[i].grades[3];
cout<<" the average test score for " <<i+1<<"student is ";
object[i].calgradeaverage();
}
;
delete[] instances;
}
i want the user to be able to input the size of the array
int s = 0;
Student object;
cout<<"please enter the object size";
cin>>s;
object *instances = new object[s]//instances and object is underline with red it said instances is undefinted;
int *instances; //this is wrong cos instances will point to Student (which is class name) later soREMOVE THIS
Student object; // wht's this ?? you want this object to be dynamicaly alocated wright? REMOVE THIS TOO
1 2 3
cout<<"please enter the object size"; //OK
cin>>s; //OK
object *instances = new (object[s]); //FATAL ERROR this has no meaning you cna't create array from object !!...
create dynamic array of objects like this:
1 2
Student* instances = new Student [s]; //this will create s objects of class Student dynamicaly.
pointer will point to each object...
THIS IS ALL WRONG:
1 2 3 4 5 6 7
for (int i = 0; i < s; i++ ){
cout<<"enter the data for the " <<i+1<<" student"<<endl;
cout<<"enter First name ";
cin>>object[i].Firstname;
cout<<"enter last name ";
cin>>object[i].Lastname;
//ETC...
u must do int like this
1 2 3 4 5 6 7
for (int i = 0; i < s; i++ ){
cout << "enter the data for the " <<i+1<<" student"<<endl;
cout << "enter First name ";
cin >> instances [i].Firstname;
cout<<"enter last name ";
cin>> instances [i].Lastname;
//ETC...
now each instance will have it's own student object with it's own initializaiton.
there is one more error:
u didn't include class header or you didn't provide it here
did u implement class Student???
you have forgot return 0; too !!