% Function Name: passFail % Input(1): (char) name of xls file % Output(0): None
ID: 3538728 • Letter: #
Question
% Function Name: passFail
% Input(1): (char) name of xls file
% Output(0): None
%
% Function Description:
% Write a function passFail that takes in an excel spreadsheet with
% students' names and grades and writes a new excel
% spreadsheet with an additional column to the right indicating if each
% student passed or failed.
% - The new column should have the header "Pass/Fail".
% - If a student has a passing grade (70 or above), this is indicated
% with a "P". If a student has a failing grade (below 70), this is
% indicated with an "F".
%
% - The function should write to a file named the same as the original
% file with "_final" added to the end.
%
% Test case:
% The file 'grades.xls' looks like this:
%
% ________________________________
%
% Students Grades
% Brittany 98
% Ana 67
% Kyle 54
% Aziz 71
% Will 70
%
%________________________________
%
%
% Calling passFail('grades.xls') should generate a new spreadsheet
% named 'grades_final.xls' that looks like this:
%
% ________________________________
% Students Grades Pass/Fail
% Brittany 98 P
% Ana 67 F
% Kyle 54 F
% Aziz 71 P
% Will 70 P
Explanation / Answer
function passFail(inp)
[a,n,all]=xlsread(inp);
name=strtok(inp,'.');
name=strcat(name,'_final.xls');
all{1,3}='Pass/Fail';
s=size(all);
s=s(1);
for k=2:s
if all{k,2}>=70
all{k,3}='P';
else
all{k,3}='F';
end
end
xlswrite(name,all);
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.