I need help to solve this exercise
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mansour Alhazmi
le 15 Juin 2016
Rouvert : Walter Roberson
le 26 Avr 2023
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'
Réponse acceptée
Steven Lord
le 15 Juin 2016
One general hint: if you're not sure what command in MATLAB you will need to use to do something, I recommend searching the MATLAB documentation for an appropriate command. Open the documentation using this command in the MATLAB Command Window:
doc
Then type a description of what you're trying to do into the search box. For instance, try "spreadsheet" or perhaps "read spreadsheet". See if there's something on the first page or two of results that looks like it is related to what you're trying to do. If so, try adapting any examples on that page to meet your needs. If not, try breaking what you're trying to do into smaller steps and searching for those smaller tasks.
0 commentaires
Plus de réponses (1)
Samuel Nkwindja
le 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

0 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!