I already BASICALLY have the code I just need you to modify it! So on my code, I
ID: 3699200 • Letter: I
Question
I already BASICALLY have the code I just need you to modify it!
So on my code, I now need to modify the scan_student function to scan a file and then display it as it is wished in order from highest to lowest grade.
Please make sure it works as the sample execution.
Please use visual studio 2015 #include<stdio.h>
The file ClassData10.txt is:
My code so far is (BUT DOES NOT WORK):
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#define SIZE 10
typedef struct student_info {
char student_name[100];
int reading_assignment_scores[12];
int homework_scores[8];
int in_class_participation;
int midterm1, midterm2, final_project;
double grade_prcnt;
char letter_grade;
} student_info;
void scan_student_info(student_info *x, FILE *in) {
float grade_per = 0;
char grade;
int i, j;
for (i = 0; i < SIZE; i++) {
fscanf(in, "%s", x[i].student_name);
printf("Name: %s ", x[i].student_name);
printf("reading: ");
for (j = 0; j < 12; j++) {
fscanf(in, "%d", &x[j].reading_assignment_scores);
printf("%d ", x[j].reading_assignment_scores);
}
printf(" homework: ");
for (j = 0; j < 8; j++) {
fscanf(in, "%d", &x[j].homework_scores);
printf("%d ", x[j].homework_scores);
}
fscanf(in, "%d", &x[i].in_class_participation);
printf(" class: %d ", x[i].in_class_participation);
fscanf(in, "%d", &x[i].midterm1);
printf("mid1: %d ", x[i].midterm1);
fscanf(in, "%d", &x[i].midterm2);
printf("mid2: %d ", x[i].midterm2);
fscanf(in, "%d", &x[i].final_project);
printf("final: %d ", x[i].final_project);
}
}
double grade_prcnt(student_info *x, int reading_assignment_scores, int homework_scores, int in_class_participation, int midterm1, int midterm2, int final_project) {
double grade_prcnt = 0;
int i;
for (i = 0; i < SIZE; i++) {
grade_prcnt += (10 * x->reading_assignment_scores[i]) / 120.0;
grade_prcnt += (30 * x->homework_scores[i]) / 800.0;
grade_prcnt += (15 * x->midterm1) / 100.0;
grade_prcnt += (15 * x->midterm2) / 100.0;
grade_prcnt += (25 * x->final_project) / 100.0;
}
return grade_prcnt;
}
void swap(student_info *x, student_info *y) {
student_info temp;
temp = *x;
*x = *y;
*y = temp;
}
void selection(student_info x[], int size) {
int i, j;
int min;
for (i = 0; i < SIZE; i++) {
min = i;
for (j = 0; j < SIZE; i++) {
if (x[j].grade_prcnt < x[min].grade_prcnt) {
min = j;
}
swap(&x[i], &x[min]);
}
}
}
void print_student(student_info *x) {
int i;
for (i = 0; i < SIZE; i++) {
printf("Grade information for %s", x[i].student_name);
printf(" Zybooks Scores = [");
for (i = 0; i < 12; i++) {
printf("%d, ", x[i].reading_assignment_scores);
}
printf("%d ]", x[i].reading_assignment_scores);
printf(" Homework Scores = [");
for (i = 0; i < 8; i++) {
printf("%d, ", x[i].homework_scores);
}
printf("%d ]", x[i].homework_scores);
printf(" In-class Participation Score = %d ", x[i].in_class_participation);
printf(" Midterm Scores = [%d, %d]", x[i].midterm1, x[i].midterm2);
printf(" Final Project Score = %d", x[i].final_project);
printf(" Calculated Percentage = %.2f", x[i].grade_prcnt);
printf(" The Final Grade for %s is %c", x[i].student_name, x[i].letter_grade);
}
}
int main() {
int i = 0;
FILE *in = fopen("ClassData10.txt", "r");
student_info x[100];
if (in == NULL) {
printf("file doesn't exist ");
}
scan_student_info(x, in);
x[i].grade_prcnt = grade_prcnt(x, x[i].reading_assignment_scores, x[i].homework_scores, x[i].in_class_participation, x[i].midterm1, x[i].midterm2, x[i].final_project);
selection(&x, SIZE);
print_student(&x);
printf(" Goodbye ");
return 0;
}
Please work with this code either debug it or solve the problem yourself
thank you!
Problem 2: Read Class Data from a File and Sort (50 points) The lile CassDala10.krt contains grade information for 10 fictitious students. The lile format is ·Student Naine . 12 Reading Assignment Scores 8 Honework Scores Scores for in-class participatio, idter dterm 2, and the linal project Using an array of type studeninfo, write a C program that I. Reads the lile information into a 10 element array of type studet inifo. Make sure you update the structure studen info from problem to acccpt 12 reading assignments and 8 homework scores. 2. Calculates the linal grades for al 10 students. 3. Print the linal scores in order, from highest to lowest. The following functions will sort an array of type in. Modify these functions to use variables of type studeil info. Your program must make use of the following functions void Print_Student (student_info X); void Scan_Student_Info (student_info *S, FILE *fp); void selection (int x. int size) / sclection sort int i,j int max for (i -0: i x[max)) // ?f found a larger element move it to the front for {j - i; jExplanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include<conio.h>
#define SIZE 10
typedef struct student_info {
char student_name[100];
int reading_assignment_scores[12];
int homework_scores[8];
int in_class_participation;
int midterm1, midterm2, final_project;
double grade_prcnt;
char letter_grade;
} student_info;
void scan_student_info(student_info x[], FILE *in) {
float grade_per = 0;
char grade;
int i, j;
for (i = 0; i < 10; i++) {
fscanf(in, "%s", &x[i].student_name);
printf("Name: %s ", x[i].student_name);
printf("reading: ");
for (j = 0; j < 12; j++) {
fscanf(in, "%d", &x[i].reading_assignment_scores[j]);
printf("%d ", x[i].reading_assignment_scores[j]);
}
printf(" homework: ");
for (j = 0; j < 8; j++) {
fscanf(in, "%d", &x[i].homework_scores[j]);
printf("%d ", x[i].homework_scores[j]);
}
fscanf(in, "%d", &x[i].in_class_participation);
printf(" class: %d ", x[i].in_class_participation);
fscanf(in, "%d", &x[i].midterm1);
printf("mid1: %d ", x[i].midterm1);
fscanf(in, "%d", &x[i].midterm2);
printf("mid2: %d ", x[i].midterm2);
fscanf(in, "%d", &x[i].final_project);
printf("final: %d ", x[i].final_project);
}
}
void grade_prcnt(student_info x[])
{
double grade_prcnt = 0.0;
int i,j;
double rs=0.0,hs=0.0;
for (i = 0; i < SIZE; i++) {
grade_prcnt=0.0;
for(j=0;j<12;j++)
{ rs=rs+(double)x[i].reading_assignment_scores[j];
}
for(j=0;j<8;j++)
{ hs=hs+(double)x[i].homework_scores[j];
}
grade_prcnt += (10 * rs) / 120.0;
grade_prcnt += (30 * hs) / 800.0;
grade_prcnt += (15 * x[i].midterm1) / 100.0;
grade_prcnt += (15 * x[i].midterm2) / 100.0;
grade_prcnt += (25 * x[i].final_project) / 100.0;
x[i].grade_prcnt=grade_prcnt;
if(x[i].grade_prcnt >150)
x[i].letter_grade='A';
else if( x[i].grade_prcnt>=100 && x[i].grade_prcnt<=150)
x[i].letter_grade='B';
else
x[i].letter_grade='C';
}}
void swap(student_info *x, student_info *y) {
student_info temp;
temp = *x;
*x = *y;
*y = temp;
}
void selection(student_info x[]) {
int i, j;
int min;
for (i = 0; i < SIZE; i++) {
min = i;
for (j = i+1; j < SIZE; j++) {
if (x[j].grade_prcnt > x[min].grade_prcnt) {
min = j;
}
swap(&x[i], &x[min]);
}}}
void print_student(student_info x[]) {
int i,j;
for (i = 0; i < SIZE; i++) {
printf(" Grade information for %s", x[i].student_name);
printf(" Zybooks Scores = [");
for (j = 0; j < 12; j++) {
printf("%d, ", x[i].reading_assignment_scores[j]);
}
printf("]");
printf(" Homework Scores = [");
for(j=0;j<8;++j){
printf("%d, ", x[i].homework_scores[j]);
}
printf("]");
printf(" In-class Participation Score = %d ", x[i].in_class_participation);
printf(" Midterm Scores = [%d, %d]", x[i].midterm1, x[i].midterm2);
printf(" Final Project Score = %d", x[i].final_project);
printf(" Calculated Percentage = %.2f", x[i].grade_prcnt);
printf(" The Final Grade for %s is %c", x[i].student_name, x[i].letter_grade);
}
}
int main() {
int i = 0;
FILE *in = fopen("ClassData10.txt", "r");
student_info x[100];
if (in == NULL) {
printf("file doesn't exist ");
}
scan_student_info(x, in);
grade_prcnt(x);
selection(x);
getch();
printf(" Result starts in Higher to lower");
print_student(x);
printf(" Goodbye ");
return 0;
}
i have made corrections to code but you didnt given any clear method for calculating grade percent and letter grade
so have made my own way you can modify in that funtions above as your way.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.