User Defined Functions Matlab: This problem requires you to explain sections of
ID: 3757988 • Letter: U
Question
User Defined Functions Matlab:
This problem requires you to explain sections of code and to finish writing a user-written function to provide you with exposure to structures. Please look at the code listed below. For this problem, complete the following two items:
Respond to each of the 10 numbered prompts that appear in the comments of the code below. Your responses should be typed.
Complete the user-written function that calculates a student’s final grade.
Additional information:
Brief description of the code: (1) an array of assignment categories and their associated weights are stored (generally in response to user-input) (2) Then, points associated with each assignment within each category as stored. (3) The structure arrays created by step 1 and step 2 are passed to a user-defined function that calculates the final grade.
For example, the code can be used to calculate a course grade given the following information:
Six homework assignments, each out of ten points (altogether, 20% of the final grade)
Three midterms, each out of a hundred points (altogether, 50% of the final grade)
One final, out of 100 points (30% of the final grade).
This is the code:
Explanation / Answer
For the given MATLAB code above I have explained the working of the procedures in the Source code that functions:-
Region 1:-
It begins with the main function by clearing all the data that is already present in the script editor.
The fprintf is used to print the information on the screen.Afterwards, it asked for the user input, and the response from the user is captured in the variable "requestUserInput".Also the isempty() is used to check whether the user have input any response from its end.
The array have been made with the variable name "categories" with the different input and also the "weights" is carrying the values of the array "categories".
The done varibale in array has been assigned the false value and we assumr that it is the boolean variable.
Region 2:-
Now the while loop check whether the further steps will be executed or not.As the value of "done" is false the statement will negate and the further statements are executed.
The category is entered by the user and the next steps check whether the assignmenr it done or not. strcmp function is used in this case to compare the values and after that the value of "done" is made true.
Region 3:-
If the category is not done i.e if the value comes out to be false then it enters the region of the code where the string value is concatenated, its type and the weight of the assignment.
Region 4:-
The idx,type,weight are copied form the original array and the value is concatenated.The user is prompted to input the weight and then it is concatenated.
The array is defined "userinput" "worths" and the value of done is set to false.Similarly all the values are redefined again.
Region 5:-
Again it is checked for the variable "done".As it have the false value it will be excuted further.
The user is prompted to enter the score and the points earned.The values will be stored in the "earned" variable.
The if statement check whether the points earned and the length of the category is divisible by 5 or not.
After this part of the code is executed the value of done is set to true.
Region 6:-
For the false condition the value of the earned is set to -1.
Region 7:-
The "idxCat" value is set to one more.
Region 9:-
This line of code iterates from the start to the total lengh of the scores array.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.