Use Stdio.h Please add comments explaining your code and steps Q Search Problem
ID: 3699695 • Letter: U
Question
Use Stdio.h Please add comments explaining your code and steps Q Search Problem 2: The file ClassData10.trt contains grade information for 10 fictitious students. The file format is ata from a File and Sort (50 points) . Student Name 12 Reading Assignment Scores 8 Homework Scores Scores for in-class participation, midterm 1, midterm 2, and the final project Using an array of type student.info, 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 inf from problem 1 to accept 12 reading assignments and 8 homework scores. 2. Calculates 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 functions to use variables of type student info. Your program must make use of the following functions . void Print.Student (student info X); e void Scan_Student Info(student info s, FILE *fp); void selection (int x, int size) I/ selection sort int i, int maxi for (i o iExplanation / Answer
As given data wrote a program as shown below
//reptresents explanation
Program:
#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");
}
}
}
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.