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

topic is Structures and Array of Structures example struct Date { int month; int

ID: 3781700 • Letter: T

Question

topic is Structures and Array of Structures

example

struct Date

{

int month;

int day;

int year;

};

(a), write a C program that has the following functions: a. Write a function called createStudent that takes the student identification number, credits completed and GPA, and returns a student record.

b. Assume that a student can graduate if their total credits is 100. Write a function called checkGraduation that takes a student record and returns TRUE if the student can graduate and FALSE if the student cannot graduate.

c. Write a function called fillStudents that takes an array of five students and gets the student details from the user and fills that array with the values.

d. Write a function called resetCredits that takes a student record and resets his (her) total credits to zero.

e. Write a function called avgGPA that takes an array of students, and returns the average GPA for that array of students.

f. Write a function called avgGPACredits that takes an array of students, and returns the average GPA and average total credits for that array of students.

Explanation / Answer

#include<stdio.h>


struct Student
{
int id;
int credits;
int gpa;
};

Student createStudent()
{
   Student s;
   printf("Please enter student id: ");
   scanf("%d",&s.id);
  
   printf("Please enter student credits: ");
   scanf("%d",&s.credits);
  
   printf("Please enter student gpa: ");
   scanf("%d",&s.gpa);
  
   return s;
}
bool checkGraduation(Student s)
{
   if(s.credits >=100) return true;
   else return false;
}
void fillStudents(Student s[],int n)
{
   for(int i=0;i<n;i++)
       s[i]=createStudent();
}
float avgGPA(Student s[],int n)
{
   float sum=0;
   for(int i=0;i<n;i++)
       sum=sum+s[i].gpa;
   return sum/n;
}
float avgCredits(Student s[],int n)
{
   float sum=0;
   for(int i=0;i<n;i++)
       sum=sum+s[i].credits;
   return sum/n;
}
void resetCredits(Student s)
{
   s.credits=0;
}
void displayStudents(Student s[],int n)
{
   for(int i=0;i<n;i++)
   {
       printf("%d: %d %d %d ",i+1,s[i].id,s[i].credits,s[i].gpa);
      
   }
}
int main()
{
   Student s[5];
   fillStudents(s,5);
   displayStudents(s,5);
   printf("%f ",avgGPA(s,5));
  
   resetCredits(s[3]);
   displayStudents(s,5);
   printf("%f",avgGPA(s,5));
}