Imagine you are a teacher in a programming class, and you want to create a simple program to manage and analyze the scores of your students. Your task is to develop a C program that performs basic operations on an array representing the students' scores. The program will help you quickly view, analyze, and update the scores. Here's a breakdown of the tasks:1. Initialize Array:o Declare an array named studentScores to store the scores of 5 students in your programming class.o Initialize the array with random scores between 50 and 100 to represent their performance in a recent assignment.2. Display Scores:o Implement a function named displayScores that takes the array of scores and its size as parameters. This function should display the scores of each student, allowing you to easily check the performance distribution in the class.3. Calculate Average:o Implement a function named calculateAverage to calculate and return the average score of the students. This will help you understand the overall performance of the class.4. Find Highest Score:o Implement a function named findMaxScore that finds and returns the highest score in the array. Knowing the highest score will give you an idea of the best-performing student.5. Update Scores:o Implement a function named updateScores to increment each student's score by 5. This simulates a bonus or extra credit being added to the assignment.6. Main Function:o In the main function, initialize the array with scores, display the initial scores, calculate and display the average, find and display the highest score, update the scores, and finally, display the updated scores.
Question
Imagine you are a teacher in a programming class, and you want to create a simple program to manage and analyze the scores of your students. Your task is to develop a C program that performs basic operations on an array representing the students' scores. The program will help you quickly view, analyze, and update the scores. Here's a breakdown of the tasks:1. Initialize Array:o Declare an array named studentScores to store the scores of 5 students in your programming class.o Initialize the array with random scores between 50 and 100 to represent their performance in a recent assignment.2. Display Scores:o Implement a function named displayScores that takes the array of scores and its size as parameters. This function should display the scores of each student, allowing you to easily check the performance distribution in the class.3. Calculate Average:o Implement a function named calculateAverage to calculate and return the average score of the students. This will help you understand the overall performance of the class.4. Find Highest Score:o Implement a function named findMaxScore that finds and returns the highest score in the array. Knowing the highest score will give you an idea of the best-performing student.5. Update Scores:o Implement a function named updateScores to increment each student's score by 5. This simulates a bonus or extra credit being added to the assignment.6. Main Function:o In the main function, initialize the array with scores, display the initial scores, calculate and display the average, find and display the highest score, update the scores, and finally, display the updated scores.
Solution 1
Sure, here is a simple C program that performs the tasks you mentioned:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 5
void displayScores(int scores[], int size) {
for(int i = 0; i < size; i++) {
printf("Student %d: %d\n", i+1, scores[i]);
}
}
int calculateAverage(int scores[], int size) {
int sum = 0;
for(int i = 0; i < size; i++) {
sum += scores[i];
}
return sum / size;
}
int findMaxScore(int scores[], int size) {
int max = scores[0];
for(int i = 1; i < size; i++) {
if(scores[i] > max) {
max = scores[i];
}
}
return max;
}
void updateScores(int scores[], int size) {
for(int i = 0; i < size; i++) {
scores[i] += 5;
}
}
int main() {
srand(time(0));
int studentScores[SIZE];
for(int i = 0; i < SIZE; i++) {
studentScores[i] = (rand() % 51) + 50;
}
printf("Initial scores:\n");
displayScores(studentScores, SIZE);
printf("Average score: %d\n", calculateAverage(studentScores, SIZE));
printf("Highest score: %d\n", findMaxScore(studentScores, SIZE));
updateScores(studentScores, SIZE);
printf("Updated scores:\n");
displayScores(studentScores, SIZE);
return 0;
}
This program first initializes an array of 5 student scores with random values between 50 and 100. It then displays these initial scores, calculates and displays the average score, finds and displays the highest score, updates the scores by adding 5 to each, and finally displays the updated scores.
Solution 2
Sure, here is a simple C program that performs the tasks you mentioned:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 5
void displayScores(int scores[], int size) {
for(int i = 0; i < size; i++) {
printf("Student %d: %d\n", i+1, scores[i]);
}
}
int calculateAverage(int scores[], int size) {
int sum = 0;
for(int i = 0; i < size; i++) {
sum += scores[i];
}
return sum / size;
}
int findMaxScore(int scores[], int size) {
int max = scores[0];
for(int i = 1; i < size; i++) {
if(scores[i] > max) {
max = scores[i];
}
}
return max;
}
void updateScores(int scores[], int size) {
for(int i = 0; i < size; i++) {
scores[i] += 5;
}
}
int main() {
srand(time(0));
int studentScores[SIZE];
for(int i = 0; i < SIZE; i++) {
studentScores[i] = (rand() % 51) + 50;
}
printf("Initial scores:\n");
displayScores(studentScores, SIZE);
printf("Average score: %d\n", calculateAverage(studentScores, SIZE));
printf("Highest score: %d\n", findMaxScore(studentScores, SIZE));
updateScores(studentScores, SIZE);
printf("Updated scores:\n");
displayScores(studentScores, SIZE);
return 0;
}
This program first initializes an array of 5 student scores with random values between 50 and 100. It then displays these initial scores, calculates and displays the average score, finds and displays the highest score, updates the scores by adding 5 to each, and finally displays the updated scores.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.