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 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...
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...
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
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....
Write a program that translates a letter grade into a number grade. Letter grades are A,...
Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and 0. There is no F+ or F-. A “+” increases the numeric value by 0.3, a “–“ decreases it by 0.3. However, an A+ has value 4.0.4 pts Enter a Letter grade: B- The numeric value is 2.7 Your code with comments A screenshot...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
Write a C program that calculates a worker’s wages from their hours worked and hourly rate....
Write a C program that calculates a worker’s wages from their hours worked and hourly rate. This wage calculator should also account for overtime hours, calculate amount to be witheld from taxes, and calculate the final net income. Required functionality: 1. Ask the user for the number of hours worked and hourly rate in dollars. The program should be able to accept decimal values for both of these (e.g. 3.2 hours, 11.25 dollars/hour) 2. Overtime hours are those worked in...
using c++. ALWAYS GRADE MY ANSWERS Write a program that reads students’ names followed by their...
using c++. ALWAYS GRADE MY ANSWERS Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in a struct variable of type studentType, which has four components: studentFName and studentLName of type string, testScore of type...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT