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

use c programming not c+ It is easier to use the “dot” notation to access elemen

ID: 3575704 • Letter: U

Question

use c programming not c+

It is easier to use the “dot” notation to access elements within a structure.

Create a structure “student” using “typdef”, which has four fields to store the ID, name, Quiz and Test scores of students: int ID, char name[20], float Q, float T).

Create a function void get_student_data(void): This function asks the user to enter the student ID, name, Quiz (out of 100) and Test (out of 100) scores , and prints them in a file “Stu_score.txt”, till the user enters “999” to quit. Call this function from main to test and ensure that data are being written into the “Stu_score.txt” file.

In the main create an array to store at least 50 students: student ESC_Class[50].

Create a function int STORE_DATA_IN_ARRAY (student x[]); This function opens the file “Stu_score.txt”, scans data from the file and stores them in the student x[] array. It keeps track of number of students beaing stored in the student x[] array and returns that number. Call this function from main using printf to print data stored in ESC_Class[50] array on the creen to ensure that this function is working.

Create a function float curv_factor(student x[], int num): This function determines the curving factor for students in student ESC_Class[50] array, knowing the number of students in the class (Remember int STORE_DATA_IN_ARRAY( ) function would have returned the number of students in the class. The curving factore rule is same as before: Quiz weight 40%, Test weight 60%. If the class mean is less than 70, then curving factor is 70/mean, otherwise it is 1. Call this function from main and test to make sure that it works.

Create a function char grade(student Y, float curving): This function calculates and returns the letter grade of student Y, knowing the curving factor for the class. Test function from main for a student. It calculates the grade as per our earlier logic and returns the letter Grade (A, B, C, D, or F). A: 90-100, B=80-89, C=70-79, D=60-69, F otherwise.

Create a function void print_class_grade (student x[], int num, float curving): This function repeatedly calls the function char grade(student y, float curving) and prints on the screen the Student Name and Letter Grade in Two columns. Call this function from main.

Typical Screen output looks like as shown below.

TYPICAL OUTPUT

********************** ************

Enter 4 digit Student ID:or 999 to end input: 101

Enter name, Quiz and Test Scores, separated by blanks:

John 30 70

Enter 4 digit Student ID:or 999 to end input: 102

Enter name, Quiz and Test Scores, separated by blanks:

Joe 50 70

Enter 4 digit Student ID:or 999 to end input: 103

Enter name, Quiz and Test Scores, separated by blanks:

Debi 60 70

Enter 4 digit Student ID:or 999 to end input: 104

Enter name, Quiz and Test Scores, separated by blanks:

Mark 60 60

Enter 4 digit Student ID:or 999 to end input: 999

101 John 30.00 70.00

101 John 30.00 70.00

101 John 30.00 70.00

101 John 30.00 70.00

The curving factor for this class is:1.16

John            D

Joe             C

Debi            C

Mark            D

Press any key to continue . . .

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
typedef struct Student
{
int ID;
char name[20];
float Q, T;
}Student;
void get_student_data(void)
{
FILE *fp;
int c = 0, x, id;
char na[20];
float q, t;
fp = fopen("Stu_score.txt", "w");
do
{
printf(" Enter 4 digit Student ID:or 999 to end input: ");
scanf("%d", &id);
if(id == 999)
break;
else
{
fprintf(fp, "%d ", id);
printf(" Enter name: ");
scanf("%s", na);
fprintf(fp, "%s ", na);
do
{
printf(" Enter Quiz Mark: ");
scanf("%f", &q);
if(q > 100)
printf("ERROR: Quiz mark cannot more than 100: Please reenter.");
else
{
fprintf(fp, "%.2f ", q);
break;
}
}while(1);
do
{
printf(" Enter Test Scores: ");
scanf("%f", &t);
if(t > 100)
printf("ERROR: Test mark cannot more than 100: Please reenter.");
else
{
fprintf(fp, "%.2f ", t);
break;
}
}while(1);
c++;
}
}while(1);
fclose(fp);
}
int STORE_DATA_IN_ARRAY (Student x[])
{
int c = 0, co = 0;
FILE *fr;
fr = fopen("Stu_score.txt", "r");
int id;
char na[20];
float q, t;
do
{
fscanf(fr, "%d %s %f %f ", &x[co].ID, x[co].name, &x[co].Q, &x[co].T);
co++;
}while(!feof(fr));
for(c = 0; c < co; c++)
printf(" ID = %d Name = %s Quiz = %f Test = %f", x[c].ID, x[c].name, x[c].Q, x[c].T);
return co;
}
float curv_factor(Student x[], int num)
{
float mean, cf;
int c, tot = 0;
for(c = 0; c < num; c++)
tot += x[c].Q * .40 + x[c].T * .60;
mean = tot / num;
if(mean < 70)
cf = 70 / mean;
else
cf = 1;
}
int main()
{
Student ESC_Class[50] = {0, " ", 0.0f, 0.0f};
int count;
float cf;
get_student_data();
count = STORE_DATA_IN_ARRAY (ESC_Class);
cf = curv_factor(ESC_Class, count);

}