// fylladio 5 ASKHSH 11 C++ 2019-2020
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#define N 120
using namespace std;

class alfa {
private :
	int month;
	int point;
	int demand;
public:

//default constructor
	alfa()
	{month=0; point=0; demand=0;}

//constructor with parameters' list
	alfa(int in_month, int in_point, int in_demand)
	{
		month=in_month;
		point=in_point;
		demand=in_demand;
	};

	int get_month() {return month;};
	int get_point() {return point;};
	int get_demand() {return demand;};

	void print()
	{cout<<month<<"   "<<point <<"   "<<demand<<endl; 	}

};// end class alfa definition
 
//function press any key
void pak()
{ printf("Press ENTER key to Continue\n");  getchar();   }

class new_alfa:public alfa
{
private:
	double production_cost;
	double delivery_cost;

public :
	//default constructor
	new_alfa()  { alfa(); production_cost=0.0; delivery_cost=0.0;  }

	//constructor with parameters' list
	new_alfa(int in_month, int in_point, int in_demand, double in_production_cost, double in_delivery_cost) : alfa(in_month, in_point, in_demand)
	{production_cost=in_production_cost;
	delivery_cost=in_delivery_cost;}
	
	void new_print()
	{ print(); 	cout<<"new values are :"<<production_cost<<"  "<<delivery_cost<<endl; }
}; //end derived class definition

int main()
{ alfa a[N]; new_alfa b[N];
int i,k,j,z, m,in_date, in_total_q, in_d[10],sum=0; double in_production_cost, in_delivery_cost;
int total[10][12]={0}, *y1, flag=0, count=0, year_total[10]={0}, count_days[12][2]={0};

srand((unsigned int)time(0));

	// initialize array a
cout<<"INITIALIZE Object array a"<<endl;
for(i=0;i<N;i++) { a[i]=alfa(); a[i].print();}
pak();

ifstream fg;
fg.open("orders.txt");
	if(!fg) {
				cout<<"file does not open"<<endl;
				exit(1);
			}
	k=0;
	 cout<<"----------------------------------------------------"<<endl;
	 cout<<"DISPLAY DATA FROM FILE"<<endl;
	while(!fg.eof())
	{  // read from file
		sum=0;
		fg>>in_date>>in_total_q;
		for (i=0;i<10;i++) { fg>>in_d[i]; sum=sum+in_d[i];}
			k++;
		// display data from file
			cout<<in_date<<" "<<in_total_q<<"   ";
			for (i=0;i<10;i++) cout<<in_d[i]<<" ";
			cout<<endl<<endl;
	
		// fill array total[10][12] !!!
			m=in_date % 100 - 1; // month number
			for (j=0;j<10;j++) 
			    total[j][m]+=in_d[j];   
	
		// fill dynamic array
		if (flag==0)  {y1=new int; flag=1;}
		y1[count]=m;
		y1[count+1]=in_total_q-sum;
		count+=2;

	}; // end while not eof()

//display array total

for (i=0;i<10;i++)
{
	for (j=0;j<12;j++) cout<<total[i][j]<<" ";
	cout<<endl;
}

//insert 120 objects into array a and display objects in array a
cout<<"insert AND display objects - ARRAY a"<<endl;
for (i=0;i<10;i++)
{
	}	for (j=0;j<12;j++)
	{
		a[i*10+j]=alfa(j+1,i+1,total[i][j]);
		a[i*10+j].print();
	};
	pak();
};
pak(); 
cout<<"count ="<<count<<endl; pak();

//display dynamic array
cout<<"DYNAMIC ARRAY "<<endl;
  for (i=0;i<count;i+=2)
	  cout<<y1[i]<<"  "<<y1[i+1]<<endl;
pak();

//ERWTHMA 3
for (i=0;i<10;i++)
	for (j=0;j<12;j++)
		year_total[i]+=a[i*10+j].get_demand();

//display year_total array
for( z=0;z<10;z++) 
	{	cout<<"point ="<<z<<"   year total =";
		cout<<year_total[z]<<endl;
	};

//ERWTHMA 4
cout<<"DYNAMIC ARRAY:   + or  - "<<endl;
  for (i=0;i<count;i+=2)
	  if (y1[i+1]>=0) count_days[y1[i]][0]++; else count_days[y1[i]][1]++;

  //display ERWTHMA 4
  for (z=0;z<12;z++)
	  cout<<"month="<<z<<"  days + "<<count_days[z][0]<<"   days -   "<<count_days[z][1]<<endl;

  // ERWTHMA 5 - inheritance
		//initialize and display derived class new_alfa
		for (i=0;i<N;i++) b[i]=new_alfa();
			cout<<endl<<endl<<" class new_alfa - initialization !!! "<<endl;
		for (i=0;i<N;i++) b[i].new_print();
		pak();
		//copy 
		cout<<endl<<endl<<" class new_alfa - copying objects..... "<<endl;
		count=0;
		for (i=0;i<10;i++)
           	for (j=0;j<12;j++)
			{			
				// create random values 
				in_production_cost=rand()%40+20;
				in_delivery_cost=rand()%10+3;
								
				b[i*10+j]=new_alfa(a[i*10+j].get_month(), a[i*10+j].get_point(),a[i*10+j].get_demand(),in_production_cost, in_delivery_cost);
				b[i*10+j].new_print();
				count++;
			}
		cout<<"count == "<<count<<endl;

return 0;
} // end main
