Define an array of class to store students information

Hello friends, I am not sure what I am doing wrong here. I am new to C++ programing.


Define an array or a vector of class to store studnets information. Then write a main function to populate the array (vector) nd display it by the member function. The student class has member variable name, mark, address, as well as display() member function to display the member variables.


Any help would be appreciate it . thanks a lot

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  int main(){
        student = s[5];
	int n;
	for(n=0; n <5; n++)
	{
		cout << " Please enter your name 'quit' " << endl;
		getline (cin, s[n].name);
		if (s[n].name=="quit")
		break;
		cout <<"Please enter your mark" << endl;
		cin >> s[n].mark;
		cin.ignore(1);
		cout <<" Please enter your address " << endl;
		getline(cin, s[n].address);	
	}
	for (int i=0; i <n; i++)
	{
		s[i].display();
	}
}
Last edited on
Where have you been having trouble? What have you tried so far?
If you let us know what you've tried, we can know how to help you better. But we can't just hand you a solution.
If you have issues/errors/wrong output, let us know where the issues are and we can investigate it faster.
Last edited on
I get two errors:

student and s were not declared in the scope.
Right.

They haven't been defined anywhere. You need to define these. In your original comment, you already listed everything the class needs to have in it. You need to use that to define the class.
Topic archived. No new replies allowed.