Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a function that takes two input parameters, a vector of test scores and a

ID: 3549016 • Letter: D

Question

Define a function that takes two input parameters, a vector of test scores and a scalar passing grade. The function returns the fraction of passing grades as a number in the range [0 1] (so 0.3 means 30% of the grades were passing. Define the function without using any MATLAB library functions.


Write a main program that prompts the user to enter grades in a loop, ending on a negative number, stores the grades in a vector, and asks the user for a passing grade. Ten pass the grade vector and passing cutoff to the function and print the percent of passing grades.

Explanation / Answer

function frac = pass( V,g )

pass=0;

for i=1:length(V)

if(V(i)>=g)

pass=pass+1;

end

fraction=pass/length(V);

disp(['The passing fraction is ' num2str(fraction)]);

end


% MATLAB COMMAND WINOW FUNCTION

%Define a program to enter grades till negative is obtained

for i=1:1000

a=input('Enter grade');

if(a>=0)

V(i)=a;

else

break;

end

end


% Now get the passing grade

g=input('Enter passing grade');

%Now pass the data to our defined function pass

pass(V,g)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote