Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that uses an array of structs to store the first name, middle in

ID: 3919588 • Letter: W

Question

Write a program that uses an array of structs to store the first name, middle initial, last name, and score of 5 students.

1. Declare the size of the array of structs.

2. Define your struct globally(i.e before main)

3. Main:

a) you'll declare the array of structs.

b) you'll call a function that willl initialize the values of the array of struct(first names, middle initial, last name, and score) entered by user.

c) then you'll ask the user to enter a name to find then call a function that will search for a student by the name entered by the user. The funtion returns a Boolean value and display an apppropiate message to the user.

d) Next, you'll call a function that will return the average of all the students' scores and dissplay the result to the user.

Write all necessary functions and prototypes. All parameters must be passed by reference.

Explanation / Answer

// since the language was not specified, so C has been used.
#include<stdio.h>
#include<string.h>

struct students{
   char first[30];
   char middle[30];
   char last[30];
   int score;
};

struct students info[10]; // you can change the size or take the value from user

//values passed by reference
void initialize(struct students *info);
bool find(char *name, struct students *info);
float average(struct students *info);

void initialize(struct students *info){

   for (int i = 0; i < 10; info++)
   {
       printf("enter first name: ");
       scanf(" %c", info->first);
       printf("enter middle name: ");
       scanf(" %c", info->middle);
       printf("enter last name: ");
       scanf(" %c", info->last); // space before %c is important otherwise it would take enter as the input
       printf("enter score: ");
       scanf("%d", &info->score);
       i++;
   }

}

bool find(char *name, struct students *info){
   for (int i = 0; i < 10; info++)
   {
       if (*info->first == *name)
           return true;
       i++;
   }
   return false;
}

float average(struct students *info)
{
   float sum = 0;
   for (int i = 0; i < 10; info++)
   {
       sum = sum + info->score;
       i++;
   }

   return sum / 10;
}
int main(){

    char name[30];
    float result;
    bool value;
   initialize(info);
   printf("enter name to find: ");
   scanf(" %c",name);
   char p = *name;
   value = find(name, info);
   if (value == true)
       printf("student entry exists");
   else
       printf("student entry does not exists");
   printf(" ");
   result = average(info);
   printf("%f", result);
  
}

Hope this helps:)

Feel free to ask if I missed out something.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote