Write a C program that does the following: 1) Create a two-dimensional array to
ID: 3531448 • Letter: W
Question
Write a C program that does the following:
1) Create a two-dimensional array to store four scores of three students and initialize them to be as follows:
Student 1: 89,100, 71, 92
Student 2: 67, 99, 96, 89
Student 3: 100, 95,100, 8
2) create a one-dimensional array named avgarray to store the average score of four students and initialize them as 0 each.
3) Write a function that displays the scores of all students in a table
4) Write a function named setscore that passes three parameters (two-dimensional array, the number of scores) and should change the score for one student after getting the indexes of student and score and the new score from keyboard.
5) Write a function that calculates the averaged score for each student and store into the passing average score array.
6) Write a function that calculates and returns the highest score of all of the students
7) Write a function that calculates and returns the lowest score of all of the students
8) Test your function in main by calling each function to do the following:
a. print the scores of all students in a table
b. change the 2nd score of student 2 to be 100
c. calculate and display the average score for each student
d. calculate the highest score of all students and display it in main
e. calculate the lowest score of all students and display it in main
Please Use C, not C++
Sample output:
---------------------------------
| Student 0 | 77 | 68 | 86 | 73 |
---------------------------------
| Student 1 | 96 | 87 | 89 | 78 |
---------------------------------
| Student 2 | 70 | 90 | 86 | 81 |
---------------------------------
highest score is 96
lowest score is 68
average score of students:
student 0 : 76.000000
student 1 : 87.500000
student 2 : 81.750000
Enter index for student, index for score, and new score:
1 1 100
---------------------------------
| Student 0 | 77 | 68 | 86 | 73 |
---------------------------------
| Student 1 | 96 | 100 | 89 | 78 |
---------------------------------
| Student 2 | 70 | 90 | 86 | 81 |
---------------------------------
highest score is 100
lowest score is 68
average score of students:
student 0 : 76.000000
student 1 : 90.750000
student 2 : 81.750000
Press any key to continue . . .
Explanation / Answer
#include<stdio.h>
int array[3][4]={{89,100,71,92},{67,99,96,89},{100,95,100,8}};
void dispaly()
{
int i=0;
int j=0;
printf(" -------------------------------------------------- ");
for(i=0;i<3;i++)
{
printf(" | student %d| ",i);
for(j=0;j<4;j++)
{
printf("%d |",array[i][j]);
}
}
}
void setScore(int studentIndex,int scoreIndex,int score)
{
array[studentIndex][scoreIndex]=score;
}
void calculateAverage(float avgarr[3])
{
int i=0;
int j=0;
for(j=0;j<3;j++)
{
for(i=0;i<4;i++)
{
avgarr[j]+=(float)array[j][i];
}
avgarr[j]/=3;
}
}
int highestScore()
{
int i=0;
int j=0;
int high=array[0][0];
for(i=0;i<3;i++)
for(j=0;j<4;j++)
if(high<array[i][j])
high=array[i][j];
return high;
}
int lowestScore()
{
int i=0;
int j=0;
int small=array[0][0];
for(i=0;i<3;i++)
for(j=0;j<4;j++)
if(small>array[i][j])
small=array[i][j];
return small;
}
int main()
{
float avgarr[3];
int i;
int studentIndex, scoreIndex, score;
while(1)
{
dispaly();
for(i=0;i<3;i++)
avgarr[i]=0.0;
calculateAverage(avgarr);
printf(" highest score is %d",highestScore());
printf(" lowest score is %d",lowestScore());
printf(" average score of student ");
for(i=0;i<3;i++)
printf(" student %d :%f",i,avgarr[i]);
printf(" Enter index for student, index for score, and new score :");
scanf("%d",&studentIndex);
scanf("%d",&scoreIndex);
scanf("%d",&score);
setScore(studentIndex,scoreIndex,score);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.