Lab Assignment 2: Calculate Grade Average Description: Using Lab Assignment1’s p
ID: 3724305 • Letter: L
Question
Lab Assignment 2: Calculate Grade Average
Description: Using Lab Assignment1’s program as a template, design a program that calculates the grade averages of two students with 4 grades each.
Requirements:
Properly document code using the ANSI C Coding standards.
Use float type values for grades.
Use a constant variable for the number of grades per student to calculate the average.
Read the first and last name for each student.
Read grades from the keyboard input real-time for each student.The input request should look like the below for each student (without quotes):
“Please enter Student 1’s First name: ” (then get First name)
“Please enter Student 1’s Last name: ” (then get Last name )
“Please enter Student 1’s first grade: “ (then get grade 1)
“Please enter Student 1’s second grade: “ (then get grade 2)
etc.
Display the first and last name of each student and all grades entered per student and their grade average.The output should be as below (example only based on inputted grades) :
“Jessie Ventura’s grades: 90, 90, 95, and 80. Their average is 88” (note the type conversion in the output)
“John Wayne’s grades: 80, 20, 60, and 70. Their average is 57” (on a new line)
Explanation / Answer
#include<stdio.h>
int main() {
int i,j,a[2][4],avg,sum=0;
for(i=0;i<2;i++) {
printf("Please enter Student %d first grade: ",i+1);
scanf("%d", &a[i][0]);
printf("Please enter Student %d second grade: ",i+1);
scanf("%d", &a[i][1]);
printf("Please enter Student %d third grade: ",i+1);
scanf("%d", &a[i][2]);
printf("Please enter Student %d fourth grade: ",i+1);
scanf("%d", &a[i][3]);
}
for(i=0;i<2;i++) {
sum=0;
printf("“Student %d grades: ",i+1);
for(j=0;j<4;j++) {
sum+=a[i][j];
if(j==3) {
printf("%d. ",a[i][j]);
} else {
printf("%d, ",a[i][j]);
}
}
avg= sum/4;
printf("Average is %d ", avg);
}
}
Output:
Please enter Student 1 first grade: 90
Please enter Student 1 second grade: 100
Please enter Student 1 third grade: 95
Please enter Student 1 fourth grade: 80
Please enter Student 2 first grade: 80
Please enter Student 2 second grade: 20
Please enter Student 2 third grade: 60
Please enter Student 2 fourth grade: 70
“Student 1 grades: 90, 100, 95, 80. Average is 91
“Student 2 grades: 80, 20, 60, 70. Average is 57
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.