| | |
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 array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





