#include<iostream.h>
#include<math.h>
#include"lib351.h"

void main (){

	bool goout = false;
	while (!goout){

    	ofstream dataOutStr;

    	//_____SET_THE_VARIABLES_____

		int lines, columns;
      	lines = 21;
  	   	columns = 16;

		float **vector;
		vector = new float *[lines];
		for (int j = 0; j < lines; j++){
			vector[j] = new float [columns];
		}

		float A1, A2, Q1, Q2;
		float r1, r2;

		//_____INPUT_THE_DATA___

		cout <<"X coordinate for Q1"<< endl;
		cin  >> A1;
     	cout <<"\nX coordinate for Q2"<< endl;
		cin  >> A2;
   		cout <<"\ncharge Q1"<< endl;
		cin  >> Q1;
		cout <<"\ncharge Q2"<< endl;
		cin  >> Q2;

		//____OUTPUT_THE_HEADER___

		outFileMaker("m348p1c.out", &dataOutStr);
		dataOutStr<<"m348p1c.cpp:   Potential for 2 Point Charges:"<< endl<<endl;
		dataOutStr<<"A1="<<A1<<"; A2="<<A2<<"; Q1="<<Q1<<"; Q2="<<Q2<<endl<<endl;

		//____CONSTRUCT_THE_MATRIX______

		for (j = -10; j <= 10; j++){
			for (int i = -10; i <= 5; i++){

				r1 = sqrtf(powf((i-A1), 2) + powf(j, 2)) + 0.000001;
				r2 = sqrtf(powf((i-A2), 2) + powf(j, 2)) + 0.000001;

				float potential =  Q1/r1 + Q2/r2;
				if (potential >= 10.0) {potential = 9.99;}
				if (potential <= -1.0) {potential = -9.99;}
				vector[j+10][i+10] =  potential;

			}
 		}

		//____OUTPUT_THE_MATRIX___

	   	d2aArrayOutput(lines, columns, vector, &dataOutStr);

		//_____QUERY_THE_USER______

		goout = query();

	}
};
