0

What I want to do is to make a searching engine for searching student`s grade in student list with student number and student name. If multiple students match the requested name, the system will ask the user to enter the student id.

I have done the read txt file, however, I stopped at changing txt to array for storing and searching. I don't know how to store those data into array.

I got 20 students and here's two examples of student's grading in each subject:

SS6709 Peter VT001 C VT002 E VT003 D VT004 D VT009 A+ VY018 A++ VT024 B

SS9830 Amy VT001 D VT002 C VT003 C VT004 D VT009 D VT018 D VT023 B

Community
  • 1
  • 1
  • 7
    And what have you tried so far? – Zac Howland Nov 13 '13 at 15:06
  • 2
    After you get the basics done, you might want to look into some of the nice [algorithms in the C++ standard library](http://en.cppreference.com/w/cpp/algorithm), for example [`std::sort`](http://en.cppreference.com/w/cpp/algorithm/sort) and [`std::find_if`](http://en.cppreference.com/w/cpp/algorithm/find). – Some programmer dude Nov 13 '13 at 15:08
  • put your data in a multi_map, where you use student name as key. if you have multiple students with same name, iterate over find results in order to find id. – Jepessen Nov 13 '13 at 15:08
  • Also, you do know about structures and classes? Maybe you want to read something from the beginners section of [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? – Some programmer dude Nov 13 '13 at 15:09
  • @Jepessen: The first field seems to be an unique identifier; a map should suffice. – dario_ramos Nov 13 '13 at 15:09
  • You'll have to store the data one character at a time. ->open file ->while end of file ->read character -> store in an array ->close file – Sumedh Nov 13 '13 at 15:10
  • @dario_ramos I agree but he wants to search using student name at first, so I think that using name as key will be faster in most cases, and only when are same, serch by ID. if he wants to search by ID in first place, I'd suggest the same thing as you. – Jepessen Nov 13 '13 at 15:12
  • 1
    @Jepessen You can always have multiple collections. One vector to store the data, then a few mappings with references to the objects in the vector, for easy searching. – Some programmer dude Nov 13 '13 at 15:15
  • @JoachimPileborg You're also right, there are a lot of possibilities. I've just said the first thing in my mind. – Jepessen Nov 13 '13 at 15:18
  • thankyou for all urs response, if theres a requirement that all searching and sorting can only refer to string array in my prog, after loading the txt file,i cant read and write in txt file.As a beginner, i feel lost in convert those student`s info to 3d array.......=( – user2988179 Nov 13 '13 at 15:21

2 Answers2

1
  1. think and define a class Item that will represent a single item that will hold the data about a single student (code, name, ...)
  2. create an empty std::vector of those structures that will hold your "items"
  3. open the file for reading
  4. read the file line-by-line (use std::getline to get WHOLE lines, not just filestream.getline or file >> var operator)
    1. (for each line that you read)
    2. read the line as std::string, just as std::getline wants
    3. create a Item for holding next group of data
    4. analyze the line and cut/copy the student's code into myItem.code
    5. analyze the line and cut/copy the student's name into myItem.name
    6. analyze the line and cut/copy the XXXXXXXXXXXXXX into myItem.whateverelse
    7. append the myItem that you have just read to the vector that you prepared earlier
  5. close the file after reading all lines

Now you have a 'vector' that holds all the data, nicely stored as "items" that each have a code, name, and other data. You can now loop/search over that vector to find if any name or code matches.

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
0

it looks like you need to create your own data structure to store the values. You can define your own struct

struct Student{
 string name
 string iD
 ....
};

and use a array of type in this case Student

Student data_base[100];

this is a very basic approach but it should get you going...

cmh
  • 10,612
  • 5
  • 30
  • 40
Pandrei
  • 4,843
  • 3
  • 27
  • 44