pr3algoritmo
pr3algoritmo
end const
type
{User defined types}
tGrade = {A, B, C_PLUS, C_MINUS, D}
tActivityType = {CAA, PR}
tActivityName = {CAA1, CAA2, CAA3, CAA4, PR1, PR2, PR3}
tActivityState = {SUBMITTED, NOT_SUBMITTED, EXCLUDED}
tActivity = record
name: tActivityName; {Activity Name}
state: tActivityState; {Activity State}
mark: real; {Activity Mark}
end record
tStudent = record
studentId: integer; {Student ID}
name: string;{Student Name}
activities: vector[NUM_ACTIVITIES] of tActivity; {Student Activities}
end record
tStudentsTable = record
students: vector[MAX_STUDENTS] of tStudent; {Students info and grades}
nStudents: integer; {Number of students}
end record
end type
{Exercise 1}
{Acción parcialmente desarrollada. Hay que completarla, según las instrucciones del enunciado de la
PR3}
fileToRead := openFile(filename);
if fileToRead ≠ NULL then
{Initializations}
studentTable.nStudents:=0;
for i := 1 to NUM_ACTIVITIES do
{Read mark and activity state}
newStudent.activities[i].mark := readRealFromFile(fileToRead);
newStudent.activities[i].state := readEnumFromFile(fileToRead);
end while
closeFile(fileToRead);
isRead := true;
else
isRead := false;
end if
end action
{Exercise 2}
action calcularNotaFinal(in student: tStudent, out notaTotalCaa: real, out notaTotalPr: real )
var
i: integer;
notaTotalCaa: real;
notaTotalPr: real;
end var
i := 0
notaTotalCaa := 0.0;
notaTotalPr := 0.0;
end action
{Exercise 3}
action returnActivityTypeAndWeight(activity: tActivity, out activityType: tActivityType, out weight: integer)
if activity.name = CAA1 then
activityType := CAA;
weight := CAA1_WEIGHT;
else if activityType = CAA2 then
activityType := CAA;
weight := CAA2_WEIGHT;
else if activityType = CAA3 then
activityType := CAA;
weight := CAA3_WEIGHT;
else if activityType = CAA4 then
activityType := CAA;
weight := CAA4_WEIGHT;
else if activityType = PR1 then
activityType := PR;
weight := PR1_WEIGHT;
else if activityType = PR2 then
activityType := PR;
weight := PR2_WEIGHT;
else if activityType = PR3 then
activityType := PR;
weight := PR3_WEIGHT;
end if
end action
{Exercise 4}
action activitiesSubmittedByStudents(in student: tStudent, out nCaa: integer, out nPr)
var
i: integer
nCaa: integer;
nPr: integer;
end var
nCaa := 0;
nPr := 0;
{Exercise 5}
{Acción parcialmente desarrollada. Hay que completarla, según las instrucciones del enunciado de la
PR3}
action writeStudentData(in student: tStudent, in markCaa: float, in markPr: float, in nCaa: integer, in nPr:
integer)
var
allPrSubmitted: boolean;
end var
allPrSubmitted := everythingSubmitted(student);
writeInteger(student.studentId);
writeString(" ");
writeString(student.name);
writeString(" ");
writeReal(markCaa);
writeString(" ");
writeReal(markPr);
writeString(" ");
writeInteger(nCaa);
writeString(" ");
writeInteger(nPr);
if allPrSubmitted then
writeInteger(1);
else
writeInteger(0);
end if
writeString("\n");
end action
{Exercise 6}
boolean everythingSubmitted(student: tStudent)
var
i: integer;
end var
i := 0;
for i := 1 to NUM_ACTIVITIES do
if student.activities[i].name = PR and student.activities[i].state != SUBMITTED then
return false;
end if
end for
return true;
end function;
algorithm UOCSubjectGrade
var
studentsTable: tStudentsTable;
i: integer;
filename: string;
isRead: boolean;
end var
{Exercise 1}
studentsLoadDataFromFile(filename, studentsTable, isRead);
if isRead then
writeString(“RESULTS:”);
writeString(“ID NAME PEC_MARK PR_MARK N_PEC N_PR ALL_PR?(1=YES)”);
for i := 1 to MAX_STUDENTS do
{Exercise 2}
calcularNotaFinal(studentsTable.students[i], notaTotalCaa, notaTotalPr)
{Exercise 4}
activitiesSubmittedByStudents(studentsTable.students[i])
{Exercise 5}
writeStudentData(studentsTable.students[i], notaTotalCaa, notaTotalPr, nCaa, nPr)
end for
else
writeString("NO STUDENTS RECOVERED");
end if
end algorithm