I need help to solve this exercise
Show older comments
2. One requirement for all first-year classes is an issue of a 'Standing' during the middle of the term.
The results are either a Satisfactory (S) or Unsatisfactory (U). Since you are the office employee in charge of issuing these grades you decide to write a function called midtermGrades to help you.
You discover that the grades are on a spreadsheet organized like this:
a. Each student is represented by one row on the spreadsheet
b. The first row will contain the following 6 strings in the following order:
'name', 'math', 'science', 'english', 'history' and 'cs'.
c. Under the name column will be a string with the student’s name.
d. Grades in the other columns can be 'A', 'B', 'C', 'D', 'F', or 'W'.
e. A student’s grade is ‘S’ if there are more A’s, B’s and C’s than not. Your function should print out grades ready to be entered consisting of a table with headings 'Name' and 'S/U'
4 Comments
TastyPastry
on 15 Jun 2016
Can you post what you've attempted?
Mansour Alhazmi
on 15 Jun 2016
Mansour Alhazmi
on 15 Jun 2016
Edited: Walter Roberson
on 15 Jun 2016
Accepted Answer
More Answers (1)
Samuel Nkwindja
on 25 Jan 2022
This functions transfers both the input and the output of the function midtTermResults to the file Final_results.xlsx.
function midTermGrade(grades)
%This functions tells whether the results are satisfactory or not for a a
%given
%grades is a cell array containing the names of students and their grades
a=size(grades);
student_st=cell(a(1),1); %student_st= student status (either S or U)
student_st{1}='S/U';
if iscell(grades)
for i = 2: a(1)
As=count([grades{i,2:a(2)}],'A');
Bs=count([grades{i,2:a(2)}],'B');
Cs=count([grades{i,2:a(2)}],'C');
Ds=count([grades{i,2:a(2)}],'D');
Fs=count([grades{i,2:a(2)}],'F');
Ws=count([grades{i,2:a(2)}],'W');
satisfactory = As+Bs+Cs > Ds+Fs+Ws; %Implementig the condition for satisfactory results
if satisfactory
student_st{i}='S';
else
student_st{i}='U';
end
end
results=[grades(:,1),student_st]; %storing the final results'
xlswrite('Final_results.xlsx',results,2)
xlswrite('Final_results.xlsx',grades,1)
else
disp('The input must be a cell array!');
end
Testing the function with this example ,
example={'name' 'math' 'sc' 'english' 'history' 'CS';
'Maher' 'A' 'C' 'D' 'A' 'A';
'Mansour' 'D' 'D' 'D' 'B' 'B';
'Mohammed' 'B' 'A' 'A' 'A' 'A'};
midTermGrade(example);
We obtain

Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!