I need help to solve this exercise
显示 更早的评论
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 个评论
TastyPastry
2016-6-15
Can you post what you've attempted?
Mansour Alhazmi
2016-6-15
Mansour Alhazmi
2016-6-15
编辑:Walter Roberson
2016-6-15
采纳的回答
更多回答(1 个)
Samuel Nkwindja
2022-1-25
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

类别
在 帮助中心 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!