0

Hi,
I have been asked to create a small programme that asks a user how many students information they would like to enter and then asks the user to enter all their information storing it all into a struct.

The above is all good I know exactly know how to do this, but then we have to ask the user to seacrh for a student record using the student ID where they are then shown the record of that particular student.
Student ID will be an element in the struct. I am not sure exactly how to go about this!
Any help would be appreciated.
Thanks

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by unbeatable0
0

What about a linked list?
Or alternatively, you could store all the class instances in an array with as many elements as the the user inputs, and to check which instance has the student's ID run a loop through all the indexes.
An example to make it all clearer:

...
struct StudentInfo
{
...
unsigned int ID;
...
}

int main(void)
{
short int NumOfStudents;
cout<<"Input information on how many students?\n";
cin>>NumOfStudents;
StudentInfo Students[NumOfStudents];
short int Index;
   for(Index=0;Index<NumOfStudents;Index++)
   {
   ... // input students information
   }

unsigned int ID_ToLookFor;
cout<<"Search for a student with what ID?\n";
cin>>ID_ToLookFor;
   for(Index=0;Index<NumOfStudents;Index++)
   {
   if(Students[Index].ID==ID_ToLookFor) .. // do whatever you need to do here
   }
...
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.