/*
* Copyright 2023, Ali Arya
* Anyone Can Code: Algorithmic Thinking
* Example 5.5c
*/

#include <iostream>
#include "string.h""
using namespace std;

#define NUM_GRADES 5

struct Student
{
    char name[50];
    int ID;
    int grades[NUM_GRADES];
    int average;
};

void StudentInfo1(char name[], int ID, int grades[], int average)
{
    cout << name << "\n";
 	cout << ID << "\n";
    for(int i=0; i < NUM_GRADES; i++)
 	    cout << grades[i] << "\n";
 	cout << average << "\n";
}
void StudentInfo2(Student s)
{
 	cout << s.name << "\n";
 	cout << s.ID << "\n";
    for (int i = 0; i < NUM_GRADES; i++)
        cout << s.grades[i] << "\n";
 	cout << s.average << "\n";
}

int main()
{
    ///////////////////////////////////////////
    //create and initialize a test Student

    Student s;
    strcpy_s(s.name, 50, "Ali");
    s.ID = 1000;
    s.average = 0;
    for (int i = 0; i < NUM_GRADES; i++)
    {
        s.grades[i] = rand() % 100;
        s.average += s.grades[i];
    }
    s.average /= 5;

    StudentInfo2(s);

    ///////////////////////////////////////////
    //array of Student variables

    Student year1[10];		    //array of 10 students
    year1[0].ID = 1000;		    //ID for the first student
    year1[0].grades[0] = 99;	//first grade for the first student
    year1[0].average = 100;
    year1[1].ID = 1001;		    //ID for the second student
    //continue individually for all students
    //or create an initialize function and call it in a loop
    
    //using a loop to access all Studnet array members
    cout << "Name" << "\t" << "ID" << "\t" << "g1" << "\t" << "g2" << "\t" << "g3" << "\t" << "g4" << "\t" << "g5" << "\t" << "average\n";
    cout << "------" << "\t" << "------" << "\t" << "------" << "\t" << "------" << "\t" << "------" << "\t" << "------" << "\t" << "------" << "\t" << "------\n";
    for (int i = 0; i < 10; i++)	//loop over all students
    	StudentInfo2(year1[i]);


    return 0;
}
