Question

In: Computer Science

Write a C program that calculates the average grade for a specified number of students from...

Write a C program that calculates the average grade for a specified number of students from each student's test1 and test2 grades. The program must first ask the user how many students there are. Then, for each student, the program will ask the user for the test1 grade (grade #1) and test2 grade (grade #2). The program should be able to handle up to 100 students, each with 2 grades (test1 and test2). Use a two-dimensional float array to store the grades. Then, using a loop, prompt the user for the test1 and test2 grade of each student. Create a second single-dimensional float array to hold the average grade for each student (for up to 100 students). To calculate the average grade, pass both the two-dimensional array and the single-dimensional array to a function named void calculateAverages(float grades[][2], float averages[], int numStudents). The third parameter of the function indicates the actual number of students. The function will then use a loop to calculate the average grade for each student. Remember, since averages is an array parameter, any changes to averages is changing the original array. When the function returns to main, the program (in main) should display the average grade for each student (using a loop).

Solutions

Expert Solution

#include<stdio.h>

void calculateAverages(float grades[][2], float averages[], int numStudents)
{
        int i;

        //CALCULATING THE AVERAGE GRADE OF EACH STUDENT
        for(i = 0; i < numStudents; i++)
        {
                averages[i] = (float)((grades[i][0] + grades[i][1])/2);
        }
}

int main()
{
        int numStudents,i;
        float grades[100][2],averages[100];
        printf("Enter the number of students: ");
        scanf("%d", &numStudents);          //INPUT NUMBER OF STUDENTS FROM USER

        //TAKING INPUT FROM USER
        for(i = 0; i < numStudents; i++)
        {
                printf("\nStudent %d: \n", i+1);
                printf("Enter grade for test 1: ");
                scanf("%f", &grades[i][0]);
                printf("Enter grade for test 2: ");
                scanf("%f", &grades[i][1]);
        }

        calculateAverages(grades, averages, numStudents);

        //PRINTING AVERAGE GRADES OF ALL STUDENTS
        printf("\n");
        for(i = 0; i < numStudents; i++)
        {
                printf("Average grade for Student %d: %0.2f\n", i+1, averages[i]);
        }
}

IF YOU LIKED THE ANSWER, PLEASE UPVOTE


Related Solutions

Write a C program that calculates the average grade for a specified number of students from...
Write a C program that calculates the average grade for a specified number of students from each student's termtest and final grade. The program must first ask the user how many students there are. Then, for each student, the program will ask the user for the termtest grade (grade #1) and final grade (grade #2). The program should be able to handle up to 100 students, each with 2 grades (termtest and final). Use a two dimensional float array to...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
Write a C++ program named, myGrade.cpp, that calculates a letter grade for a student of this...
Write a C++ program named, myGrade.cpp, that calculates a letter grade for a student of this course (CSC100 online) based on three user inputs. This program should begin by printing the title of the application (program) and a brief description of what it does. (Note: this is NOT the same as the program prolog: a prolog is much more detailed, has required elements, and is intended for other programmers reading the cpp file. The title and description displayed by the...
Question: How do I write a program in C# that calculates a student's final grade for...
Question: How do I write a program in C# that calculates a student's final grade for a test with 20 multiple questions using arrays and helper methods? Instructions: (0-incorrect answer, 1-correct answer) If the student answered the question right, add .5 points to the running total. If the student didn’t answer correctly subtract .5 points from the running total. The running total is initialized with 5 points (so the student receives 5 points extra credit). To define the final grade...
Create a C++ program which will accept an unlimited number of scores and calculates the average...
Create a C++ program which will accept an unlimited number of scores and calculates the average score. You will also need to prompt for the total points possible. Assume each test is worth 100 points. Requirements. • Enter the Student ID first, then prompt for grades. Keep prompt- ing for grades until the client enters ’calc’. That triggers final pro- cessing. • Make your code as reliable as possible. • Make your program output easy to read. • You cannot...
Write a python program that calculates the average number of words per sentence in the input...
Write a python program that calculates the average number of words per sentence in the input text file. every sentence ends with a period (when, in reality, sentences can end with !, ", ?, etc.) and the average number of sentences per paragraph, where a paragraph is any number of sentences followed by a blank line or by the end of the text.
Program Name: Divisible. Write a program that calculates the number of integers in a range from...
Program Name: Divisible. Write a program that calculates the number of integers in a range from 1 to some user-specified upper bound that are divisible by 3, the sum of those integers, and the number and sum of those integers not divisible by 3. Your program must display meaningful output which includes: the selected upper bound number of integers divisible by 3 sum of integers divisible by 3 number of integers not divisible by 3 sum of integers not divisible...
Program Name: Divisible. Write a program that calculates the number of integers in a range from...
Program Name: Divisible. Write a program that calculates the number of integers in a range from 1 to some user-specified upper bound that are divisible by 3, the sum of those integers, and the number and sum of those integers not divisible by 3. Your program must display meaningful output which includes: the selected upper bound number of integers divisible by 3 sum of integers divisible by 3 number of integers not divisible by 3 sum of integers not divisible...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of test scores where the lowest score is dropped. It should use the following functions a) void getScores should have 4 double reference parameters (one for each test score) getScores should do the following: - read 4 test scores from the text file Lab11C.txt (Important: declare your ifstream infile and open the file inside this function, not in the main function) - store them in...
Data was collected from students to determine the effects on overall grade average and number of...
Data was collected from students to determine the effects on overall grade average and number of hours spent playing video games per week. Grade   Hours/Week 20 23 96 3 74 6 85 5 67 8 56 14 79 4 65 7 Which is the: -Independent variable?   _______________________ -Dependent variable?   _______________________ -Calculate the coefficient of correlation and interpret the results. -Determine both the coefficient of determination and non-determination and explain the result. -Determine the unrounded regression equation for this data set....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT