#include<stdio.h>

/* structure definitions */ 

enum student_type {REGULAR, PASS_FAIL};

union finalgrade
{
  float score; /* for a REGULAR student */
  char pf;   /* 'p' if pass, 'f' if fail, for PASS_FAIL type  */
};

struct Student
{

  enum student_type type;

struct
{
  char name[50];
  long phone;
}personal;

  float h[8];  /* Homework scores */
  float e[3];  /* Exam scores */
  float proj;  /* Project score */

  union finalgrade final;

};



union finalgrade compute_finalgrade(struct Student s)
{
  float total=0;
  union finalgrade f;
  int i;

  total+=0.15*s.proj;

  for(i=0;i<8; i++)
    total+=0.25/8*s.h[i];

  for(i=0;i<3; i++)
    total+=0.20*s.e[i];

  if(s.type==REGULAR)
    f.score=total;
  else
    {
      if(total>20)
	f.pf='p';
      else
	f.pf='f';

    }

  return f;

}


void main()
{
  struct Student s[80];

  int i, n, j;
  char yn, tmp;

  printf("\n Enter number of students: ");
  scanf("%d", &n);

  for(i=0; i<n; i++)
    {
      printf("\n Is the student a regular student?<y/n>: ");
      scanf("%c%c%c", &yn, &yn, &tmp);
      if(yn=='y')
	s[i].type=REGULAR;
      else
	s[i].type=PASS_FAIL;

      printf("\n Enter student name: ");
      fgets(s[i].personal.name, 50, stdin);
      printf("\n Enter phone number: ");
      scanf("%li", &s[i].personal.phone);

      for(j=0; j<8; j++)
	{
	  printf("\n Enter Homework %d score: ", j+1);
	  scanf("%f", &s[i].h[j]);
	}
      for(j=0; j<3; j++)
	{
	  printf("\n Enter Exam %d score: ", j+1);
	  scanf("%f", &s[i].e[j]);
	}


      printf("\n Enter project score: ");
      scanf("%f", &s[i].proj);

      s[i].final= compute_finalgrade(s[i]);

      if(s[i].type==REGULAR)
	printf("\n Total score is %f\n", s[i].final.score);
      else
	if(s[i].final.pf=='p')
	  printf("\n Student passed\n");
	else
	  printf("\n Student failed\n");

    }


}



