Question: #include #include #include #include #define PASS _ THRESHOLD 5 0 / / Minimum average to pass / / Global variables for statistics int * students
#include
#include
#include
#include
#define PASSTHRESHOLD Minimum average to pass
Global variables for statistics
int studentspassingperquestion; Array for passing stats per question
int totalstudentspassing ;
int highestgrade lowestgrade ; Start with extreme values
semt statssemaphore; Semaphore to protect shared stats
typedef struct
int studentid;
int numgrades;
int grades;
StudentData;
Function to process each student's data
void processstudentvoid arg
StudentData data StudentDataarg;
float sum ;
for int i ; i datanumgrades; i
sum datagradesi;
Update perquestion passing stats safely
if datagradesi PASSTHRESHOLD
semwait&statssemaphore;
studentspassingperquestioni;
sempost&statssemaphore;
float average sum datanumgrades;
Update overall stats safely
semwait&statssemaphore;
if average PASSTHRESHOLD
totalstudentspassing;
for int i ; i datanumgrades; i
if datagradesi highestgrade
highestgrade datagradesi;
if datagradesi lowestgrade
lowestgrade datagradesi;
sempost&statssemaphore;
Print student result
printfd f s
datastudentid average, average PASSTHRESHOLD "Passed" : "Failed";
pthreadexitNULL;
int main
FILE inputfile fopeninputtxtr;
if inputfile NULL
perrorError opening input file";
return ;
int numstudents, numquestions;
fscanfinputfile, d &numstudents;
fscanfinputfile, d &numquestions;
studentspassingperquestion intcallocnumquestions, sizeofint;
seminit&statssemaphore, ;
pthreadt threadsnumstudents;
StudentData studentdatanumstudents;
for int i ; i numstudents; i
studentdataigrades intmallocnumquestions sizeofint;
studentdatainumgrades numquestions;
fscanfinputfile, d &studentdataistudentid;
for int j ; j numquestions; j
fscanfinputfile, d &studentdataigradesj;
pthreadcreate&threadsi NULL, processstudent, &studentdatai;
for int i ; i numstudents; i
pthreadjointhreadsi NULL;
freestudentdataigrades;
fcloseinputfile;
Print overall statistics
printf
Overall Statistics
;
printfNumber of students passing each question:
;
for int i ; i numquestions; i
printfQuestion d: d students passed.
i studentspassingperquestioni;
printfTotal number of students who passed overall: d
totalstudentspassing;
printfHighest grade: d
highestgrade;
printfLowest grade: d
lowestgrade;
freestudentspassingperquestion;
semdestroy&statssemaphore;
return ;
In this code, my output should be like the result output when given the input I have added in the photos, but my result is like the result of out I can not understand the problem, I need a correction in my code, thanks in advance.
input:
results.txt :
Dosya Dzen Biim Grnm Yardm
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:
out:
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:
input.txt Not Defteri
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
