



Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!




The objective of this problem is to develop an e-learning application that presents some questions to a student (only ONE) and checks the answers. The questions are organized in units of increasing level of difficulty. The number of questions in the system is always 250 and the number of units is 10 Section 1. (1 point). Design, create and initialize the data structures needed to develop the program: a) A vector of structures (questions) to store all the questions in the system. The information to store regarding a question is the number of the unit it belongs to, the text of the question, and the answer (that can only be true or false). b) A vector of structures (outcomes) storing the outcome of the student in the different units. The vector contains one outcome structure per unit, storing the unit number, the number of questions from that unit that have been asked for the student, and the number of correct answers given by the student in that unit. c) A vector of integers (usedQuestions) with the same number of elements as the vector of questions, where 1 in a given position indicates that this question has been asked by the student, and 0 indicates the opposite. Add a drawing that represents the data structures you have defined. Initialize the number of correct and total questions for every unit to zero. You can do this either in the declaration of the structure or right after it. % SECTION 1 nQuestions = 250; nUnits = 10; questions = struct('unit', cell(1,nQuestions),... 'text', cell(1,nQuestions),... 'answer', cell(1,nQuestions)); outcomes = struct('unit', cell(1,nUnits),... 'asked', cell(1,nUnits),... 'correct', cell(1,nUnits)); for (i=1:nUnits) outcomes(i).unit = i; outcomes(i).asked = 0; outcomes(i).correct = 0; end usedQuestions = zeros(1,nQuestions); … 1 2 3 4 5 6 247 248 249 250 questions answer question unit text
Section 2. (1.5 points). Implement the function selectQuestion to select one question from the vector of questions. The input parameters for this function are the vector with all the questions, the total number of questions, the number of the unit, and the vector with the used questions. The output is the position of the selected question in the vector of questions (integer). The function searches (in the vector of questions) for the first question belonging to the unit defined by the parameter that has not been previously used. In case there are no questions left from that unit, the function returns - 1. The header for this function must be: function pos=selectQuestion(questions, nQuestions, unit, usedQuestions) % SECTION 2 function pos=selectQuestion(questions, nQuestions, unit, usedQuestions) question = 1; cont = true; pos = - 1; while ((question <= nQuestions) && cont) if ((questions(question).unit==unit) && (usedQuestions(question)==0)) pos = question; cont = false; else question = question + 1; end end end Section 3. ( 2 points). Write the function testUnit to present the questions from one unit to the user. The input parameters are the vector with all the questions, the total number of questions, the number of the unit to test and the vector with the used questions. The output is one structure of the type outcome and the updated vector with the used questions. testUnit must call the function selectQuestion to select the question to ask, display the text question, read the user answer, and update the used questions and the number of correct answers in the unit. The number of questions to ask from a unit is 3 if it is possible. If there are only one or two questions 1 2 3 4 5 6 7 8 9 10 outcomes correct outcome unit asked … 1 2 3 4 5 6 247 248 249 250 usedQuestions
while (unit <= nUnits && ~finish) [outcome,usedQuestions]=testUnit(questions, nQuestions, unit, usedQuestions); outcomes(unit)=outcome; if (outcome.correct > 1) unit = unit + 1; else if ((outcome.correct == 0) && (unit > 1)) unit = unit - 1; end end finish = input('Do you want to stop? 1 --> Yes 0 --> No\n'); end if (~finish) userOutcome=processOutcome (outcomes, nUnits); for (i=1:nUnits) if (userOutcome.marks(i) < 8) fprintf('Dear %s, you must review the unit %d\n', userOutcome.name,i); end end end Section 5. (1.5 points) Write a function called processOutcome to calculate the final mark of the student in each unit. The mark for each unit is 10 times the number of correctly answered questions divided by the total number questions asked by the program. This function will create a new structure - userOutcome - containing the name of the user, the outcomes vector and the vector with the marks and save it to a binary file (using the function save). The name of the file will be marks.mat and the name of the student will be entered by the user. Write as well the code that has to be added at the end of the main script in section 4 to calculate the final mark obtained in each unit and to display the units that he or she should review. The program will display messages recommending the user to review any unit for which the mark is below 8. If the student has selected to exit the program without completing all the units, the outcome will not be processed The header for this function must be: function userOutcome=processOutcome (outcomes, nUnits) % SECTION 5 function userOutcome=processOutcome (outcomes, nUnits) userOutcome = struct('name','', ... 'outcomes',outcomes,... 'marks', zeros(1,nUnits)); userOutcome.name = input('Please type your name\n'); for (i=1:nUnits) userOutcome.marks(i) = 10*outcomes(i).correct/outcomes(i).answer; end % save('marks.mat'); end Section 6. ( 2 points ) Let’s now assume that 20 different users have used the previous program and we want to analyze the results to see which unit is the most difficult. You can assume that a vector of structs called users exists according with the following Matlab statements:
(You don’t have to develop this part, assume the vector users already stores all the data). nUsers=20; users = struct('name',cell(1, nUsers), ... 'outcomes',cell(1, nUsers),... 'marks', cell(1, nUsers)); Write the Matlab code that you consider to identify the most difficult unit, defined as the unit in which the ratio of total correct answers asked divided by total questions asked is lower. % SECTION 6 ratios = zeros(1,nUnits); for (i=1:nUnits) for (j=1:nUsers) ratios(i) = ratios(i) + users(j).outcomes(i).correct/users(j).outcomes(i). asked; end end ratioMin = 1; hardestUnit = 0; for (i=1:nUnit) if (ratios(i) < ratioMin) ratioMin = ratios(i); hardestUnit = i; end end fprintf ('The hardest unit is %i\n', hardestUnit); Notes All the program outputs must have an appropriate format (use fprintf instead of disp) Only the following MatLab functions can be used: zeros, ones, randi, struct and those explicitly referenced