Question: #include #include #include #define NAME _ LENGTH 2 0 typedef struct studentRecord { int studentID; char name [ NAME _ LENGTH + 1 ] ;
#include
#include
#include
#define NAMELENGTH
typedef struct studentRecord
int studentID;
char nameNAMELENGTH ;
int exam exam exam;
double examAvg;
char letterGrade;
RECORDTYPE;
int menu;
void loadRosterFILE infile RECORDTYPE gradeRoster int numStudents;
void processChoiceFILE infile FILE outfile int choice, RECORDTYPE gradeRoster int numStudents;
void displayGradeInfoRECORDTYPE gradeRoster int numStudents;
void searchRosterRECORDTYPE gradeRoster int numStudents;
void writeGradeReportFILE outfile RECORDTYPE gradeRoster int numStudents;
char determineLetterGradedouble average;
int main
char infilename "roster.txt;
char outfilename "gradeReport.txt;
FILE infile;
FILE outfile;
int numStudents;
RECORDTYPE gradeRoster;
infile fopeninfilenamer;
if infile NULL
printfError: Unable to open input file.
;
return ;
outfile fopenoutfilenamew;
if outfile NULL
printfError: Unable to open output file.
;
fcloseinfile;
return ;
fscanfinfiled &numStudents;
gradeRoster RECORDTYPE mallocnumStudents sizeofRECORDTYPE ;
if gradeRoster NULL
printfError: Memory allocation failed.
;
fcloseinfile;
fcloseoutfile;
return ;
loadRosterinfile gradeRoster, numStudents;
int choice;
do
choice menu;
processChoiceinfile outfile, choice, gradeRoster, numStudents;
while choice ;
fcloseinfile;
fcloseoutfile;
for int i ; i numStudents; i
freegradeRosteri;
freegradeRoster;
return ;
void loadRosterFILE infile RECORDTYPE gradeRoster int numStudents
int i studentID, exam exam exam;
char studentNameNAMELENGTH ;
for i ; i numStudents; i
fscanfinfiled s d d d &studentID, studentName, &exam &exam &exam;
gradeRosteriRECORDTYPE mallocsizeofRECORDTYPE;
if gradeRosteri NULL
printfError: Memory allocation failed.
;
exit;
gradeRosteristudentID studentID;
strcpygradeRosteriname, studentName;
gradeRosteriexam exam;
gradeRosteriexam exam;
gradeRosteriexam exam;
gradeRosteriexamAvg exam exam exam;
gradeRosteriletterGrade determineLetterGradegradeRosteriexamAvg;
int menu
int choice;
printf
Display contents of the roster.
;
printf Search the roster.
;
printf Write a grade report.
;
printf Quit.
;
printfEnter your choice: ;
scanfd &choice;
return choice;
void processChoiceFILE infile FILE outfile int choice, RECORDTYPE gradeRoster int numStudents
switch choice
case :
displayGradeInfogradeRoster numStudents;
break;
case :
searchRostergradeRoster numStudents;
break;
case :
writeGradeReportoutfile gradeRoster, numStudents;
break;
case :
printfExiting
;
break;
default:
printfInvalid choice. Please try again.
;
void displayGradeInfoRECORDTYPE gradeRoster int numStudents
printf
Grade Information:
;
printfIDtNametExamtExamtExamtAvgtGrade
;
for int i ; i numStudents; i
printfdtstdtdtdtftc
gradeRosteristudentID, gradeRosteriname,
gradeRosteriexam gradeRosteriexam gradeRosteriexam
gradeRosteriexamAvg, gradeRosteriletterGrade;
void searchRosterRECORDTYPE gradeRoster int numStudents
printf
Search functionality:
Enter student ID to search: ;
int searchId;
scanfs searchName;
int found ;
for int i ; i numStudents; i
if strcmpgradeRosteriname, searchName
printfStudent found:
;
printfIDtNametExamtExamtExamtAvgtGrade
;
printfdtstdtdtdtftc
gradeRosteristudentID, gradeRosteriname,
gradeRosteriexam gradeRosteriexam gradeRosteriexam
gradeRosteriexamAvg, gradeRosteriletterGrade;
found ;
break;
if found
printfStudent not found.
;
void writeGradeReportFILE searchroster should be student ID not by name, this is th attempt
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
