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 Comments

Can you post what you've attempted?
Actually, I'm new student. I don't have any background in Matlab. I have some information how to do loop and function, but for write and read excel sheet. I couldn't understand how to do it. If you could help by writing this code thank you, If not thank you again.
function midtermGrades
example{1,1} = 'name';
example{1,2} = 'math';
example{1,3} = 'sc';
example{1,4} = 'english';
example{1,5} = 'history';
example{1,6} = 'CS';
example{2,2} = 'A';
example{2,3} = 'C';
example{2,4} = 'D';
example{2,5} = 'A';
example{2,6} = 'A';
example{3,2} = 'A';
example{3,3} = 'A';
example{3,4} = 'D';
example{3,5} = 'B';
example{3,6} = 'B';
example{4,2} = 'B';
example{4,3} = 'A';
example{4,4} = 'A';
example{4,5} = 'A';
example{4,6} = 'A';
example{2,1} = 'Maher';
example{3,1} = 'Mansour';
example{4,1} = 'Mohammed';
xlswrite('midtermGrades.xlsx',example,1)
end

Sign in to comment.

 Accepted Answer

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.

More Answers (1)

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

Asked:

on 15 Jun 2016

Reopened:

on 26 Apr 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!