Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2: Read Class Data from a File and Sort (50 points The file ClassDeta10.

ID: 3739657 • Letter: P

Question

Problem 2: Read Class Data from a File and Sort (50 points The file ClassDeta10.trt contains grade information for 10 fictitious students. The file format is e Student Name . 12 Reading Assignment Scores 8 Homework Scores .Scores for in-class participation, midterm 1, midterm 2, and the final project Using a linked list, write a C program that 1. Reads the file information into a 10 element array of type student info. Make sure you update the structure student info from problem 1 to accept 12 reading assiguments and 8 homework scores. 2. Calculates the final grades for all 10 students. 3. Print the final soores in order, from highest to lowest. The following functions will sort an array of type int. Modify these functions to use variables of type student info. void selection (int xt1 int size) selection sort int int min mLn · l; // start searching from cu r rently un sorted E Cx131> xIminh 7r t founda smaller element min-:/move it to the front void swap

Explanation / Answer

#include "stdio.h"

#include <string.h>

struct student_info {

char name[50];

int zybooks[12];

int homework[8];

int inclass;

int midterm[2];

int project;

int totalmarks;

float percentage;

};

void swap (int *x, int *y) {

int temp;

temp = *x;

*x=*y;

*y=temp;

}

void selection(int x[], int size) { //selection sort

int i,j;

int min;

  

for (i=0; i < size; i++) {

min=i; // start searching from currently unsorted

for (j = i; j<size; j++) {

if (x[j] > x[min]) // if found a smaller element

min = j; // move it to the front

}

swap(&x[i], &x[min]);

}

}

int stringtoint(char num[100]) {

int dec = 0, i, j, len;

len = strlen(num);

for(i=0; i<len; i++){

dec = dec * 10 + ( num[i] - '0' );

}

return dec;

}

void main() {

FILE *fp;

char temp[255];

int i;

int totalmarkslist[10];

int sum;

struct student_info studarray[10];

sum=0;

fp = fopen("test.txt", "r");

for (i=0;i<10;i++) {

fscanf(fp, "%s", studarray[i].name);

//studarray[i].name=temp;

printf("%s",studarray[i].name);

int j;

for (j=0;j<12;j++) {

fscanf(fp, "%s", temp);

studarray[i].zybooks[j]=stringtoint(temp);

sum=sum+stringtoint(temp);

}

  

int k;

for (k=0;k<8;k++) {

fscanf(fp, "%s", temp);

studarray[i].homework[k]=stringtoint(temp);

sum=sum+stringtoint(temp);

}

  

fscanf(fp, "%s", temp);

studarray[i].inclass=stringtoint(temp);

sum=sum+stringtoint(temp);

  

int l;

for (l=0;k<2;k++) {

fscanf(fp, "%s", temp);

studarray[i].homework[l]=stringtoint(temp);

sum=sum+stringtoint(temp);

}

  

fscanf(fp, "%s", temp);

studarray[i].project=stringtoint(temp);

sum=sum+stringtoint(temp);

  

studarray[i].percentage=sum/1241;

totalmarkslist[i]=sum;

}

fclose(fp);

  

selection(totalmarkslist,10);

  

int m;

for (m=0;m<10;m++) {

int n;

for (n=0;n<10;n++) {

if(totalmarkslist[m]==studarray[n].totalmarks) {

printf("Grads information for %s",&studarray[n].name," ");

printf("zybooks Scores = [");

int p;

for(p = 0; p < 12; p++)

printf("%d, ", &studarray[n].zybooks[p]);

printf("] ");

printf("Homework Scores = [");

for(p = 0; p < 8; p++)

printf("%d, ", &studarray[n].homework[p]);

printf("] ");

printf("In-class Participation Scores = %d", &studarray[n].inclass );

printf("] ");

printf("Midterm Scores = [");

for(p = 0; p < 2; p++)

printf("%d, ", &studarray[n].midterm[p]);

printf("] ");

printf("Final project Score = %d", &studarray[n].project );

printf("Calculated Percentage = %f", &studarray[n].percentage );

if (studarray[n].percentage>90) {

printf("The Final Grade for Sarah is = A");

} else {

printf("The Final Grade for Sarah is = B");

}

}

}

}

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote