How to deal with pointers with structures

Last week I took new things about pointers, but to be honest it always makes me confused and I face difficulties with it!

Here is a question about structures and pointers which I solved, but my instructor told me that I used the normal way not pointers, hope you guys have a time to check my answer and tell me how can I use pointers with it.


Part (A)
Consider the following struct declaration:
struct student
{
long ID;
string name;
float GPA;
};

Write a function named displayTopStudents that takes as parameters: a pointer to an array of type student and the array size. The function should display the ID and name of all students with GPA 3.5 and above.

Part (B)
Write a main function to create a dynamic array of type student and ask the user to input the students’ information. The number of students should be determined by the user. Then use the above function to display the top students’ names and IDs.



My answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <string>
using namespace std;
struct student
{
	long ID;
	string name;
	float GPA;
};

void displayTopStudents(student *List, int size);
int main()
{
	int size;

	cout<<"Enter the number of students: ";
	cin>>size;

	if(size<=0)
	{
		cout<<"Number should be above 0, program will shut down."<<endl;
		return -1;
	}

	student *List=new student[size];

	cout<<"Enter the students details:-"<<endl;
	for(int i=0; i<size; i++)
	{
		cout<<"Student #"<<i+1<<" name: ";
		getline(cin, List[i].name);
		getline(cin, List[i].name);
		cout<<"Student #"<<i+1<<" ID: ";
		cin>>List[i].ID;
		cout<<"Student #"<<i+1<<" GPA (0.0 to 4.0): ";
		cin>>List[i].GPA;
		cout<<endl;
		while(List[i].GPA < 0.0 || List[i].GPA > 4.0)
		{
			cout<<"Re-Enter the GPA of student #"<<i+1<<": ";
			cin>>List[i].GPA;
			cout<<endl;
		}
	}

	displayTopStudents(List, size);

	delete []List;
	system("pause");
	return 0;
}

void displayTopStudents(student *List, int size)
{
	bool check=false;
	for(int i=0; i<size; i++)
	{
		if(List[i].GPA >= 3.5)
		{
			cout<<"\nStudent Name: "<<List[i].name<<endl
				<<"Student ID: "<<List[i].ID<<endl
				<<"Student GPA: "<<List[i].GPA<<endl;
			check=true;
		}
	}

	if(check==false)
		cout<<"No students with GPA 3.5 or above."<<endl;

}
Are we just talking about the use of array vs. pointer notation here?

If so, he could mean that instead of writing this:
List[i].name <--array notation
You should write this:
(List+i)->name <-- pointer notation
It seems ok to me.

You've completed the assignment in a competent way, I have no idea what your lecturer means.
Topic archived. No new replies allowed.