Question

Using C programming For this project, you have been tasked to read a text file with student grade...

Using C programming

For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th array position to hold the computed average. Once the file has been read and the averages calculated and stored in the array, you must sort the list by grade in descending order. Finally, the records should be printed to screen in descending final grade order with statistics at the end of the file for the class average, highest and lowest grades. We will cover the aspects you need to complete this project over the next 3-4 weeks. Objectives: • Use of the FILE* and file functions. • Use of functions to include the passing of arrays and or array elements. • Implementation of a common (bubble sort) sorting algorithm. • Display formatted output using input/output statements. • Use format control strings to format text output. • Use C data types. Requirements: Your program should make use of the following functions.

1. A function to read the file into an array of arrays. This function should take an empty multi-dimensional array from the caller. The function should ask the user for the name of the file. You may assume the file name entered will be accurate and accessible. You may omit this requirement and hard code the path to the file. You will be given a test file (shown below). I suggest hard coding the filename while you develop your project to save typing it over and over while you test.

2. A function to compute the grade for each array/record. This function should access the array and average the test grades, inserting the final average into the last position for each record as a float.

3. A function to sort the array of arrays by final grade in descending order (highest grade first). This function should take the entire array.

4. A function to print out the results of the operation to screen calculating the required totals and formatting the output appropriately. This function should take the entire array as well. Your program is expected to only deal with fractional values. Therefore, you are required to use a multi-dimensional array of type float or double. Your program will not have to resize your array; you may hard code the size of the array using a constant (#define). The test files will have 10 records/students, a student number followed by 4 grades. You may not use any global variables save for the use of a constant for array size if you wish as shown often in some examples

grades input file

6814 85 86 92 88

7234 76 81 84 78

6465 87 54 68 72

7899 92 90 88 86

9901 45 78 79 80

8234 77 87 84 98

7934 76 91 84 65

7284 56 81 87 98

7654 76 87 84 88

3534 86 81 84 73

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include<stdio.h>
#include<malloc.h>

#define MAX_ROWS 10//Number of records in file

//Function prototypes
void inputGrades(float *arr[MAX_ROWS]);
void calculateAverage(float *arr[MAX_ROWS]);
void sortArray(float *arr[MAX_ROWS]);
void display(float *arr[MAX_ROWS]);


int main()
{
    float *arr[MAX_ROWS];//Declaring array of pointers and will be used as a 2D array
    for(int i = 0; i < MAX_ROWS; i++)
    //Allocating memory to 2D array
    arr[i] = (float *)malloc(sizeof(float)*6);
    inputGrades(arr);//Input grades from file
    calculateAverage(arr);//Calculate average for each array
    sortArray(arr);//Sort array by grades in descending order
    display(arr);//Dsiplay resultant array
    return 0;
}

//This function takes input a file name from the user which contains
//grades of student in unsorted order and read grades from the file in array
void inputGrades(float *arr[MAX_ROWS])
{
    char fileName[20];
    printf("Enter file name: ");
    scanf("%s", fileName);//Input file name
    FILE *f = fopen(fileName, "r");//Open file
    if(f == NULL)
    {
        printf("Cannot open file");
        exit(0);
    }
    int i = 0;
    while(fscanf(f, "%f %f %f %f %f", &arr[i][0], &arr[i][1], &arr[i][2], &arr[i][3], &arr[i][4]) == 5)//Reading student ID and grades from file
        i++;
}

//Function to calculate average of each grades for a student and store it in last position of array
void calculateAverage(float *arr[MAX_ROWS])
{
    for(int i = 0; i < MAX_ROWS; i++)
        arr[i][5] = (arr[i][1] + arr[i][2] + arr[i][3] + arr[i][4])/4;//Calculate average of grades and store in 5th position
}

//Function to display the result after sorting
void display(float *arr[MAX_ROWS])
{
    float totalAvg = 0;
    printf("\n%11s%11s%11s%11s%11s%11s", "Student ID", "Test 1", "Test 2", "Test 3", "Test 4", "Final");
    printf("\n\n******************************************************************");
    for(int i = 0; i < MAX_ROWS; i++)
    {
        printf("\n%11.0f %10.0f %10.0f %10.0f %10.0f %10.2f", arr[i][0], arr[i][1], arr[i][2], arr[i][3], arr[i][4], arr[i][5]);
        totalAvg += arr[i][5];//Adding average for each student
    }
    printf("\n******************************************************************");
    totalAvg = totalAvg/MAX_ROWS;//Class average
    printf("\nClass Average: %.2f\tHighest Grade: %.2f\t Lowest Grade: %.2f", totalAvg, arr[0][5], arr[9][5]);
}

//Function to implement bubble sort and sort the array by average grades
//in descending order
void sortArray(float *arr[MAX_ROWS])
{
    int i, j;
    for (i = 0; i < MAX_ROWS - 1; i++)
        for (j = 0; j < MAX_ROWS - i - 1; j++)
            if(arr[j][5] < arr[j+1][5])
            {
                //Swap row a[j] and row a[j+1]
                float *temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
}

Output:

Add a comment
Know the answer?
Add Answer to:
Using C programming For this project, you have been tasked to read a text file with student grade...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++: Create a grade book program that includes a class of up to 20 students each...

    C++: Create a grade book program that includes a class of up to 20 students each with 5 test grades (4 tests plus a Final). The sample gradebook input file (CSCI1306.txt) is attached. The students’ grades should be kept in an array. Once all students and their test scores are read in, calculate each student’s average (4 tests plus Final counts double) and letter grade for the class. The output of this program is a tabular grade report that is...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • Please in Python: Studentlist.txt: 1237, Davis, Michael 1244, White, Ronald 2365, Smith, Jason 3458, Wilson, Robert...

    Please in Python: Studentlist.txt: 1237, Davis, Michael 1244, White, Ronald 2365, Smith, Jason 3458, Wilson, Robert Gradebook.txt: 1237,1,87 1244,1,79 2365,1,86 2365,2,96 3458,1,88 3458,8,68 1237,2,84 1237,3,90 1244,4,96 1244,6,83 2365,3,73 2365,5,74 3458,7,70 3458,2,89 3458,3,77 2365,4,89 1237,4,78 1244,3,89 2365,6,86 3458,4,84 3458,5,93 1244,2,88 1237,5,86 2365,7,92 3458,6,67 1244,5,72 Modify the gradebook assignment that you created by combining the student records and the grades into an array. Calculate the average and grades from the info in the array. Add the average and grade to the student...

  • Student average array program

    Having a bit of trouble in my c++ class, was wondering if anyone can help.Write a program to calculate students' average test scores and their grades. You may assume the following input data:Johnson 85 83 77 91 76Aniston 80 90 95 93 48Cooper 78 81 11 90 73Gupta 92 83 30 68 87Blair 23 45 96 38 59Clark 60 85 45 39 67Kennedy 77 31 52 74 83Bronson 93 94 89 77 97Sunny 79 85 28 93 82Smith 85 72...

  • Write a program in C++ to: 1. Read all records from a binary file (also attached...

    Write a program in C++ to: 1. Read all records from a binary file (also attached to this email) to arrays; (the record structure: student number (20 bytes), grade (integer)) 2. Sort the list according to test scores; 3. Calculate the average test score for the class and print on the screen; 4. write sorted records to a new binary file. For example: The records in the original file: 1 89 2 95 3 76 The new file sorted by...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • C++ Use C++ functions and build a program that does the most basic job all students...

    C++ Use C++ functions and build a program that does the most basic job all students have to contend with, process the grades on a test and produce a summary of the results. The big wrinkle is, it should be a multi-file program. -Requires three simple things: Figure out the best score of all scores produced Figure out the worst score of all scores produced Assign a letter grade for each score produced Complete this lab by writing three functions....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT