lab4ex1
You cannot submit for this problem because the homework's deadline is due.
Ex1. Who has the highest GPA?
This exercise aims to get you familiar with structs.
Read information about some students as user input, find the student with the highest GPA and print his/her information according our specified format given below.
The first line of the input is the number of students.
For each student, his/her name and gender will be given on two separate lines. After this, one number
c
c will be given, representing the number of courses he/she has taken. Following this number is
c
c groups of lines, each representing one course.
Each course is given by three lines: the name of the course, the name of the instructor and a row vector whose first and second element stand for the credit and the student's grade for this course respectively.
If the student with the highest GPA is a bot whose name is "Zhu Kan", and his GPA is 4.0, you should first print:
Admire Zhu Kan! His/Her GPA is 4.00!\n\n
Copy
where you should keep 2 digits after the decimal point for the GPA.
Then directly use disp() to print the struct representing the student with name Zhu Kan.
After this, use disp() to print all courses where this student got full marks (4.0). Your output for this part should begin with:
He/She got full marks in these courses:\n\n
Copy
and the order of the courses should be the same as in the input.
You should have two types of structs for this exercise: one for students and one for courses.
The struct for students should have the fields name, gender, courseNum(number of courses taken) and courses(array of courses taken).
The struct for courses should have the fields name , instructor, credit and grade.
Input Limitation
There will be no students with the same name. No student would take the same course twice.
The gender of each student will only be "male" or "female".
There will be at least one student. Each student will have taken at least one course.
Output Limitation
Still print He/She got full marks in these courses: even if there is only one or even no full credit courses.
Keep 2 digits after the decimal point for the GPA.
Keep consistency with the possessive pronoun: He/His, She/Her.
Hint: If you feel confused, try to implement the following:
function courseList = fullCourses(student)
% EFFECTS: return the courselist that the given student got full credit
% ==== Your code here ==== %
end
function ret = GPA(student)
% EFFECTS: return the GPA of the given student
% Formula: Calulate the total grade and the total credits
% ==== Your code here ==== %
ret = gradeSum / creditSum;
end
function student = readStudent()
% EFFECTS: read the information of each students and return a struct
% ==== Your code here ==== %
end
function course = readCourse()
% EFFECTS: read the information of all the courses that the given student takes
% and return a struct
% ==== Your code here ==== %
end
Copy
Sample test case
Input:
3
Zhu Kan
male
3
Intro to Involution
Scarlet
[3 3]
Intro to Computers and Programming
Manuel
[4 4]
Honors Mathematics
Horst
[4 3.7]
Adriana
female
2
Calculus
Olga
[4 4]
Academic Writing
Peter Weise
[4 4]
Salty Fish
male
2
Intro to Moyu
Salty Fish
[4 4]
Physics
MK
[4 0]
Copy
Output:
Admire Adriana! Her GPA is 4.00!
name: 'Adriana'
gender: 'female'
courseNum: 2
courses: [1x2 struct]
She got full marks in these courses:
name: 'Calculus'
instructor: 'Olga'
credit: 4
grade: 4
name: 'Academic Writing'
instructor: 'Peter Weise'
credit: 4
grade: 4
Copy