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
|
#include <iostream>
#include <string>
using namespace std;
struct Student
{
int idstudent;
string firstname;
string lastname;
float Project;
float Intra;
float Final;
int noteFinale;
};
Student searchbyname(Student[], int, string);
int main()
{
Student studentList[] = {
0, "** not ", "found **", 0, 0, 0, 0,
3, "Emily", "Frank", 2.30, 4.70, 8.41, 2
};
int studentCount = sizeof(studentList) / sizeof(Student);
Student found;
found = searchbyname(studentList, studentCount, "Frank");
cout << found.firstname + found.lastname << endl;
found = searchbyname(studentList, studentCount, "Fronk");
cout << found.firstname << ' ' << found.lastname << endl;
return 0;
}
Student searchbyname(Student tabStudent[], int noStudents, string aName)
{
for (int i = 1; i < noStudents; i++)
{
if (tabStudent[i].lastname == aName)
return tabStudent[i];
}
return tabStudent[0];
}
|