hye..its kinda easy..but i still cant solve it..

1.Write a program that has an array of at least 10 string objects that hold student’s ids and names, you may make-up your own strings or use the following:

“1000614921, Abdulkadir Musa Jibrin”
“1000717859, Abdulwahab Ali Esmail Al-Nawah”
“1000716597, Ahmed Ebrahim Mohammed Al-Moay”
“1000820803, Arash Moeenjahromi”
“1000715628, Azaribe Antionette Doris”
“1000717577, Fahmi Abdulqader Ahmed Ali”
“1000818032, Fares Mohammed Mohammed Askn”
“1000818087, Khairalah Fadhl Qasem Al-Galal”
“1000715803, Liman Sadiq Musa”
“1000820441, Lin Joo Foong”

The program should ask the user to enter name, partial name or student id to search for in the array. Any entries in the array that match the string entered should be displayed. For example, if the user enters “Mohammed” the program should display the following names from the list.

1000716597, Ahmed Ebrahim Mohammed Al-Moay
1000818032, Fares Mohammed Mohammed Askn

this is what I have done

#include <iostream>

#include <string>

using namespace std;

void search(string data[], string ayat)
    int j;
    for(j=0; j < 10; j++){
        if(data[j] == ayat)
            cout<<data[j] << endl;


int main(){
string ayat;

 string data[10] =  {"1000614921, Abdul kadir Musa Jibrin",
             "1000717859, Abdul wahab Ali Esmail Al-Nawah",
             "1000716597, Ahmed Ebrahim Mohammed Al-Moay",
             "1000820803, Arash Moeenjahromi",
             "1000715628, Azaribe Antionette Doris",
             "1000717577, Fahmi Abdul qader Ahmed Ali",
             "1000818032, Fares Mohammed Mohammed Askn",
             "1000818087, Khairalah Fadhl Qasem Al-Galal",
             "1000715803, Liman Sadiq Musa",
             "1000820441, Lin Joo Foong"};

cout<<"Enter string: "<<endl;

search(data, ayat);

return 0;

Edited by ekin5683: its should be search string in array

5 Years
Discussion Span
Last Post by ekin5683
Featured Replies
  • 1

    [url]http://www.cplusplus.com/reference/string/string/[/url] Scroll down to 'String operations:'. You can use functions like find, compare etc. Read More

if(data[j] == ayat)

This comparison will only work if the user enters the exact string that is in the data array. This is not what the question asks, you need to come up with a way to compare parts of(the entire student ID, or part of the student name) the data[j] string with ayat.


awwww..thank you..
im already solve it!Thanks thanks..

btw, im using find function :)

This question has already been answered. 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.