1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <string>
using namespace std;
int searchString(string A[],int size, string target)
{
int j;
for(j=0; j < size; j++){
if(A[j] == target)
return j;
}
return j= -1;
}
int main ( )
{
string target = "";
string sName[5] = { "Ali", "Asad", "Aslam", "Akram","Ahsan" };
string fName[5] = { "Ali's Father", "Asad's Father", "Aslam's Father", "Akram's Father","Ahsan's Father" };
int age[5] = {15,18,21,19,23};
cout << "\n Please enter a Student Name, or enter q to exit: ";
getline(cin, target);
while(true){
if (target == "q")
{return 0;}
else
{
int j = searchString( sName, 5, target );
if (j== -1){
cout<< "\n Student Not Found";
}
else{
cout << "\n\n\n Student Name: \t" << sName[j];
cout << "\n Father Name: \t" << fName[j];
cout << "\n Age: \t" << age[j];
}
cout << "\n\n\n Please enter a Student Name, or enter q to exit: ";
getline(cin, target);
}
}
return 0;
}
|