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 (30 points The file ClassData 10

ID: 3740793 • Letter: P

Question

Problem 2: Read Class Data from a File and Sort (30 points The file ClassData 10.lat contains grade information for 10 fictitious students. The file format i 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 informaation into a ? element array of type student.m a Make sure you update the structure student. m ? from problem1 to accept 12 reading assignments and 8 homework scores. 2. Caleulates the final grades for all 10 students. 3. Print the final scores in order, from highest to lowest The following functions will sort an array of type int. Modify these functious to use variables of type student.info. void selection (int x11int size) selection sort int int min min-1 7 start searching from currently unsorted E xIS1>ximin) 7 af found smaller element min 1: // ?0ve it to the front void swap (intinty) int tenp Sample Code Execution: Red text indicates information entered by the user Grade infornatson for Sarah Zybooks Scores [9, 2. 5, 6, 3. 8, 9. 8. 3. 10. 10. 1 Honework Scores (93, 95, 95, 92, 94, 96, 92, 94 In-class Participation Score94 Midtern Scores-[95, 98] Fisal Project Score-93 Calculated Percentage 91.23 The Final Grade for Sarah is A Grade information for Li1y ZybookB Scores-[10, 1. 10. 7. 6-8,0,10. S. 4. 7. 4] Honework Scores[8, 85, 100, 89,8.88, 83, 84) In-class Participation Score 95 Midtern Scores [99, 90] Final Project Score-98 Calculated Percentage89.74 The Final Grade for Lily isB Grade inforsation for David Zybooks Scores [9. 4. 10, 5. . 10. 8.1. 2. 2. 9. 4 Honework Scores (82, 78, 96. 93, 84, 86, 85, 100) Ia-class Participation Score-90 Midters Scores[94. 91] Fisal Project Score98 Calculated Percentage 88.98 The Final Grade for David i B Grade information for Sydney zybooks Scores [9, 2, 4, 10, 2, 5, 8. 7. 3, 6, 10. 3 Honework Scores t72, 82, 100, 82, 80, 88. 95, 33] In-class Participation Score-9 Midterm Scores [96, 93

Explanation / Answer

Solution:

code:

#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");

}

}

}

}

};

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

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