can it be in programming language C, thanks 5. (20pt) Suppose the student data f
ID: 3749262 • Letter: C
Question
can it be in programming language C, thanks
5. (20pt) Suppose the student data file (say student.txt) starts with an integer showing the number of students in the file. It then contains that many lines, where each line has the followings per student: student ID, how many courses he/she took, and then that many pairs of numbers representing the course ID and the grade in that course. All these values are integers. Here is a sample file with 3 students 5 80 1 40 2 30 3 90 13 3 15 5 5 60 470 3 60 2 40 1 40 Complete the following program that can read student.txt file and just create the dynamic structure as shown in the below figure. There is no output file, no need to free it either cID5 grade 80 sID numC courses SI01 S 133 SI2 155 cID 2 3 grade 40 30 90 CID 5 43 2 1 grade | 60 | 70 | 60 40 | 40 /suppose al1 standard libraries are included here */ typedef struct int cID; course ID int grade; courseT typedef struct int sID int numC courseT courses: student ID / nmnber of courses taken by this student */ a dynamic array of nun curseT cD, grade] taken by this student ) studentT; include int main (void) FILE infp; int numS; I/ number of Students int i, j studentT *s; /if needed, you can declare other variables here/ if ((nfp = fopen ("student . txt", printf ("Input file cannot be opened ") return-1 "r")) NULL){ if(fscanf(infp, "%d", &nums) !"1) exit (0);Explanation / Answer
#include #include typedef struct { int cID; int grade; }courseT; typedef struct { int sID; int numC; courseT *courses; } studentT; int main(void) { FILE *infp; int numS; //Number of students int i, j; studentT *S; if((infp = fopen("student.txt", "r")) == NULL) { printf("Input file cannot be opened "); return -1; } if(fscanf(infp, "%d", &numS) != 1) exit(0); //Creating dynamic structure to read from student.txt S = (studentT *)malloc(sizeof(studentT) * numS); //Allocate memory for studentT structure pointer S for(i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.