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

//simple program demonstrating constructors and destructors

#include <stdio.h>
#include <iostream>
using namespace std;


int numStudents = 0; 
int nextID = 1000;

class Student
{
    int ID;
    int Grades[20];
    int GPA;
public:
    Student()
    {
        ID = nextID;	
        numStudents++;
        nextID++;
        Init();
    }
    ~Student()
    {
        numStudents--;
    }
    void Init()
    {
        for (int i = 0; i < 20; i++)
        {
            Grades[i] = -1;		//use -1 to mean not-defined-yet
        }
        GPA = -1;
    }
    void Print()
    {
        printf("ID = % d\n", ID);
        for (int i = 0; i < 20; i++)
        {
            printf("Grade - % d = % d\n", i, Grades[i]);
        }
        printf("GPA = % d\n", GPA);
    }
};



int main()
{
    Student* s1 = new Student();
    printf("%d students\n", numStudents);
    Student* s2 = new Student();
    printf("%d students\n", numStudents);

    delete s2;
    printf("%d students\n", numStudents);

    Student* s3 = new Student();
    printf("%d students\n", numStudents);
    s3->Print();

    delete s1;
    delete s3;

    return 0;
}

