Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int NUMBER_OF_STUDENTS = 2;
- const int NUMBER_OF_GRADES = 5;
- struct Student {
- char name[30];
- char surname[30];
- char egn[11];
- int fn;
- double grades[NUMBER_OF_GRADES];
- };
- Student getNew()
- {
- Student newStudent;
- cout << "Enter name of new student:";
- cin >> newStudent.name;
- cout << "Enter surname of new student:";
- cin >> newStudent.surname;
- cout << "Enter egn of new student:";
- cin >> newStudent.egn;
- cout << "Enter faculty number of new student:";
- cin >> newStudent.fn;
- cout << "Enter grades of new student:";
- for (int i = 0; i < 5; i++)
- {
- cin >> newStudent.grades[i];
- }
- return newStudent;
- }
- Student getStudentWithHighestGrades(Student students[NUMBER_OF_STUDENTS])
- {
- Student highestAchievingStudent;
- double highestGrade = 0;
- for (int i = 0; i < NUMBER_OF_STUDENTS; i++)
- {
- double averageGrade = 0;
- for (int j = 0; j < NUMBER_OF_GRADES; j++)
- {
- averageGrade += students[i].grades[j];
- }
- averageGrade /= NUMBER_OF_GRADES;
- if (highestGrade < averageGrade)
- {
- highestGrade = averageGrade;
- highestAchievingStudent = students[i];
- }
- }
- return highestAchievingStudent;
- }
- void printStudent(Student student)
- {
- cout << student.name << endl;
- cout << student.surname << endl;
- cout << student.egn << endl;
- cout << student.fn << endl;
- for (int j = 0; j < NUMBER_OF_GRADES; j++)
- {
- cout << student.grades[j] << endl;
- }
- }
- void printStudentsBornInMarch(Student students[NUMBER_OF_STUDENTS])
- {
- for (int i = 0; i < NUMBER_OF_STUDENTS; i++)
- {
- if (students[i].egn[3] == '3')
- {
- printStudent(students[i]);
- }
- }
- }
- int main()
- {
- Student students[NUMBER_OF_STUDENTS];
- for (int i = 0; i < NUMBER_OF_STUDENTS; i++)
- {
- students[i] = getNew();
- }
- char input[30];
- cout << "Do you want the student with the highest grade or the students born in march?" << endl;
- cin >> input;
- if (strcmp(input, "highest grade") == 0)
- {
- Student myBestStudent = getStudentWithHighestGrades(students);
- printStudent(myBestStudent);
- }
- else if(strcmp(input, "born march") == 0){
- printStudentsBornInMarch(students);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement