Question: #include #include #include #include #define PASS _ THRESHOLD 6 0 int * * grades; int num _ students, num _ questions; int * question _
#include
#include
#include
#include
#define PASSTHRESHOLD
int grades;
int numstudents, numquestions;
int questionpasscounts;
int totalpasscount ;
int maxgrade mingrade ;
semt sem;
typedef struct
int id;
float average;
int passed;
Student;
Student students;
void readdataconst char filename
FILE file fopenfilenamer;
if file
perrorError opening input file";
exitEXITFAILURE;
fscanffiled d &numstudents, &numquestions;
grades mallocnumstudents sizeofint ;
for int i ; i numstudents; i
gradesi mallocnumquestions sizeofint;
students mallocnumstudents sizeofStudent;
questionpasscounts callocnumquestions, sizeofint;
for int i ; i numstudents; i
fscanffiled &studentsiid;
for int j ; j numquestions; j
fscanffiled &gradesij;
fclosefile;
void processstudentvoid arg
int studentindex int arg;
freearg;
float sum ;
int localmax localmin ;
for int j ; j numquestions; j
int grade gradesstudentindexj;
sum grade;
if grade PASSTHRESHOLD
semwait&sem;
questionpasscountsj;
sempost&sem;
if grade localmax localmax grade;
if grade localmin localmin grade;
studentsstudentindexaverage sum numquestions;
studentsstudentindexpassed studentsstudentindexaverage PASSTHRESHOLD;
semwait&sem;
if studentsstudentindexpassed totalpasscount;
if localmax maxgrade maxgrade localmax;
if localmin mingrade mingrade localmin;
sempost&sem;
return NULL;
void writeresultsconst char filename
FILE file fopenfilenamew;
if file
perrorError opening output file";
exitEXITFAILURE;
for int i ; i numstudents; i
fprintffiled f s
studentsiid studentsiaverage,
studentsipassed "Passed" : "Failed";
fprintffile
Overall Statistics
;
fprintffile "Number of students passing each question:
;
for int i ; i numquestions; i
fprintffile "Question d: d students passed.
i questionpasscountsi;
fprintffile "Total number of students who passed overall: d
totalpasscount;
fprintffile "Highest grade: d
maxgrade;
fprintffile "Lowest grade: d
mingrade;
fclosefile;
int main
readdatainputtxt;
seminit&sem, ;
pthreadt threads mallocnumstudents sizeofpthreadt;
for int i ; i numstudents; i
int arg mallocsizeofint;
arg i;
pthreadcreate&threadsi NULL, processstudent, arg;
for int i ; i numstudents; i
pthreadjointhreadsi NULL;
writeresultsresultstxt;
for int i ; i numstudents; i
freegradesi;
freegrades;
freequestionpasscounts;
freestudents;
freethreads;
semdestroy&sem;
return ;
can you solve the above code with a different solution method using multithreading and semophore again
I added sample input and output below
input:
output:
Passed
Failed
Passed
Overall Statistics
Number of students passing each question:
Question : students passed.
Question : students passed.
Question : students passed.
Question : students passed.
Total number of students who passed overall:
Highest grade:
Lowest grade:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
