| | |
Searching Array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 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
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
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
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:
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:
c++ Syntax (Toggle Plain Text)
... 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 } ... }
Last edited by unbeatable0; Apr 14th, 2009 at 9:02 am.
![]() |
Similar Threads
- Searching an array for an existing name (Java)
- Searching an array...where to begin? (Java)
- Fastest way to search the table ( or array ) (C++)
- Searching an array (Java)
- Searching array problems (C++)
- using boolean expression on an array (Java)
Other Threads in the C++ Forum
- Previous Thread: C++I need some Help Please?
- Next Thread: Strange (extra) data in buffer after ifstream::read()
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelp homeworkhelper iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings template text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





