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!