0% found this document useful (0 votes)
5 views

pr3algoritmo

Uploaded by

GonzaloBrandán
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

pr3algoritmo

Uploaded by

GonzaloBrandán
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

const

MAX_STUDENTS: integer = 20; {Max. number of students}


NUM_ACTIVITIES: integer = 7; {Max. number of activities of the subject}
NUM_CAA_ACTIVITIES: integer = 4; {Number of CAA activities}
NUM_PR_ACTIVITIES: integer = 3; {Number of PR activities}

MIN_C_MINUS: real = 3.0; {Minimum mark for grade C-}


MIN_C_PLUS: real = 5.0; {Minimum mark for grade C+}
MIN_B: real = 7.0; {Minimum mark for grade B}
MIN_A: real = 9.0; {Minimum mark for grade A}

CAA1_WEIGHT: integer = 10; {Percent weight of CAA1 in EC grade}


CAA2_WEIGHT: integer = 20; {Percent weight of CAA2 in EC grade}
CAA3_WEIGHT: integer = 30; {Percent weight of CAA3 in EC grade}
CAA4_WEIGHT: integer = 40; {Percent weight of CAA4 in EC grade}
PR1_WEIGHT: integer = 20; {Percent weight of PR1 in PR grade}
PR2_WEIGHT: integer = 30; {Percent weight of PR2 in PR grade}
PR3_WEIGHT: integer = 50; {Percent weight of PR3 in PR grade}

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}

action studentsLoadDataFromFile(in filename: string, out studentsTable: tStudentsTable, out isRead:


boolean)
var
fileToRead : file;
newStudent: tStudent;
i: integer;
end var

fileToRead := openFile(filename);
if fileToRead ≠ NULL then
{Initializations}
studentTable.nStudents:=0;

while not isEndOfFile(fileToRead) and studentTable.nStudents <= MAX_STUDENTS do


newStudent.studentId := readIntegerFromFile(fileToRead);
newStudent.name := readStringFromFile(fileToRead);

for i := 1 to NUM_ACTIVITIES do
{Read mark and activity state}
newStudent.activities[i].mark := readRealFromFile(fileToRead);
newStudent.activities[i].state := readEnumFromFile(fileToRead);

{Assign activity name}


if i:= 1
newStudent.activities[i].name = 'CAA1';
else if i:=2
newStudent.activities[i].name = 'CAA2';
else if i := 3
newStudent.activities[i].name = 'CAA3';
else if i := 4
newStudent.activities[i].name = 'CAA4';
else if := 5
newStudent.activities[i].name = 'PR1';
else if i := 6
newStudent.activities[i].name = 'PR2';
else if i := 7
newStudent.activities[i].name = 'PR3';
end for

{Add newStudent to studentsTable }


studentsTable.students[nStudents] := newStudent
studentsTable.nStudents := studentsTable.nStudents + 1;

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;

{ Identificar si es SUBMITTED, ya que de lo contrario las notas no se suman }


for i := 1 to NUM_ACTIVITIES do
if student.activities[i].state = SUBMITTED then
{identificar el tipo de actividad y acumular notas}
if student.activities[i].name = CAA1 or student.activities[i].name = CAA2 or
student.activities[i].name = CAA3 or student.activities[i].name = CAA4 then
notaTotalCaa := notaTotalCaa + student.activities[i].mark
else
notaTotalPr := notaTotalPr + students.activities[i].Mark
end if
end if
end for

{ calcular el promedio para CAA y PR }


notaTotalCaa := notaTotalCaa / 4;
notaTotalPr := notaTotalPr / 3;

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;

{iterar sobre las actividades CAA (de la 1 a 4)}


for i := 1 to NUM_CAA_ACTIVITIES do
if student.activities[i].name = CAA1 or if student.activities[i].name = CAA2_WEIGHT
or if student.activities[i].name = CAA3 or if student.activities[i].name = CAA4 then
nCaa := nCaa + 1;
end if
end for

{iterar sobre las actividades PR (de la 5 a la 7)}


for i := NUM_CAA_ACTIVITIES to NUM_ACTIVITIES do
if student.activities[i].name = PR1 or if student.activities[i].name = PR2
or if student.activities[i].name = PR3 then
nPr := nPr + 1;
end if
end ofr
end action

{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

{Load data from file}


writeString("LOAD DATA FROM FILE. ENTER FILE NAME >>");
filename := readString();

{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

You might also like