/* Program to record, print, and process an individual's four test scores
   and final exam score
*/

#include <stdio.h>
#include <string.h>

#define NAME_LENGTH 20

/* a student struct identifies relevant data for one student  */
struct student 
{
   char name[NAME_LENGTH];
   double test1;
   double test2;
   double test3;
   double final;
};

/* Print a student's name and test record */
void
printStudent (struct student stu)
{
  printf ("%-20s: %7.1lf  %7.1lf  %7.1lf   %7.1lf\n",
	  stu.name, stu.test1, stu.test2, stu.test3, stu.final);
} // printStudent


int 
main (void)
{
  /* declaration and initialization of three students */
  struct student stu1 = {"Michael Mouse",      93.2, 98.7, 89.6, 95.6};
  struct student stu2 = {"Sebastian the Fish", 75.3, 78.8, 72.6, 92.6};
  struct student stu3 = {"Shamrock the Cat",   85.3, 87.2, 78.5, 82.8};
  struct student stu4;
  strncpy (stu4.name,"Inky the Dog",NAME_LENGTH); // Copy string literal to field
  stu4.name[NAME_LENGTH-1] = '\0'; // Ensure there is a null terminator
  stu4.test1 = 98.6;
  stu4.test2 = 86.9;
  stu4.test3 = 69.8;
  stu4.final = 93.1;

  /* print initital student records  */
  printf ("Initial student records\n");
  printf ("name                    test 1   test 2   test 3  final exam\n");
  printStudent (stu1);
  printStudent (stu2);
  printStudent (stu3); 
  printStudent (stu4); 

  return 0;
} // main
