#include "teslacoil.hpp"

/***************************************************************************
**                       SECTION FOR THE 'CLASS'                          **
**                 DEFINITIONS AND WORKING FUNCTIONS                      **
***************************************************************************/

//***********************Spacer**********************************
void funcSpacer(int i){
	for (int x = 0; x < i; x++)
		cout << "\n";
}

//***********************Percent difference**********************
double funcPercentDifference(double A, double B){
	if (A > B){
		return ((A-B) * 100 / B);}
	else {
		return ((B-A) * 100 / A);}
}
//***********************Inductor geometry***********************
void funcSetCoilRadius(inductor &c, double i){
	c.setCoilRadius(i);
}
double funcGetCoilRadius(inductor &c){
	return c.getCoilRadius();
}

void funcSetCoilTurns(inductor &c, double i){
	c.setCoilTurns(i);
}
double funcGetCoilTurns(inductor &c){
	return c.getCoilTurns();
}

void funcSetCoilSpacing(inductor &c, double i){
	c.setCoilSpacing(i);
}
double funcGetCoilSpacing(inductor &c){
	return c.getCoilSpacing();
}

void funcSetCoilLength(inductor &c, double i){
	c.setCoilLength(i);
}
double funcGetCoilLength(inductor &c){
	return c.getCoilLength();
}

//***********************Voltage*********************************
void funcSetVoltage (component &c, double i){
    c.setVoltage(i);
}
double funcGetVoltage (component &c){
	return c.getVoltage();
}       

//***********************Current*********************************
void funcSetCurrent(teslaCoil &t, double i){
	t.LCcurrent(i);
}
double funcGetCurrent(teslaCoil &t){
	return t.LCcurrent();
}

//**********************Impedence*********************************
void funcSetImpedence (component &com, double i){
	com.setImpedence(i);
}
double funcGetImpedence (component &com){
    return com.getImpedence();
}

//*****************Capacitor geometry*****************************
void funcSetCapacitor (capacitor &cap, double i){
    cap(i);
}
double funcGetCapacitor (capacitor &cap){
	return cap();
}

void funcCapacitorArea(capacitor &cap, double i){
	cap.CapacitorArea(i);
}
double funcCapacitorArea(capacitor &cap){
	return cap.CapacitorArea();
}

void funcCapacitorDielectric(capacitor &cap,double i){
	cap.CapacitorDielectric(i);
}
double funcCapacitorDielectric(capacitor &cap){
	return cap.CapacitorDielectric();
}

void funcCapacitorNumPlates(capacitor &cap, double i){
	cap.CapacitorNumPlates(i);
}
double funcCapacitorNumPlates(capacitor &cap){
	return cap.CapacitorNumPlates();
}

void funcCapacitorThickness(capacitor &cap, double i){
	cap.CapacitorThickness(i);
}
double funcCapacitorThickness(capacitor &cap){
	return cap();
}

void funcCapacitorRadius(capacitor &cap, double i){
	cap.CapacitorRadius(i);
}
double funcCapacitorRadius(capacitor &cap){
	return cap.CapacitorRadius();
}

void funcCapacitorMajorRadius(capacitor &cap, double i){
	cap.CapacitorMajorRadius(i);
}
double funcCapacitorMajorRadius(capacitor &cap){
	return cap.CapacitorMajorRadius();
}

void funcCapacitorMinorRadius(capacitor &cap, double i){
	cap.CapacitorMinorRadius(i);
}
double funcCapacitorMinorRadius(capacitor &cap){
	return cap.CapacitorMinorRadius();
}

//************************Inductor*******************************
void funcSetInductor (inductor &ind, double i){
    ind(i);
}
double funcGetInductor (inductor &ind){
	return ind();
}

//*************************Spark Length***************************
void funcSetSparkLength(teslaCoil &t, double i){
	t.SparkLength(i);
}
double funcGetSparkLength(teslaCoil &t){
	return t.SparkLength();
};

//**********************Resonant Frequency************************
void funcSetResonantFrequency(teslaCoil &t, double i){
	t.ResonantFreq(i);
}
double funcGetResonantFrequency(teslaCoil &t){
	return t.ResonantFreq();	
}

//*************************Main***********************************
void main(void){
	ui run;
	run.display();
}

/*	
	start of the USER INTERFACE...
	these member functions govern what the user sees on the screen and off the 
	screen.  This group of functions has been set outside of the main funtion
	for more versatility when switching between different enviornments.
*/

void ui::display()
{
	int Choice = 0, DoLoop = 0;
	double i = 0;
    //*****************************Main Menu*******************************
    do
    {
		cout<<"\n\t\t\t\tTHE TESLA COIL PROGRAM\n\n\n";
		cout<<"\t1) Facts vs. Fiction/Theory"<<"\t\t**Secondary Circuit**\n";
		cout<<"\t2) Spark Length"            <<"\t\t\t\t 9) Secondary Coil\n";
		cout<<"\t3) Output Voltage"          <<"\t\t\t10) Secondary Capacitor\n";
		cout<<"\t4) Frequency"               <<"\t\t\t\t11) Help\n";
		cout<<"\t**Primary Circuit**"        <<"\t\t\t12) Save/Print\n";
		cout<<"\t5) Power Transformer"       <<"\t\t\t13) Quit\n";
		cout<<"\t6) Spark Gap"               <<endl;
		cout<<"\t7) Primary Capacitor"       <<endl;
		cout<<"\t8) Primary Coil"            <<endl;
		funcSpacer(10);
		cout<<"Choice: ";
		cin>>Choice;
		switch (Choice)
		{
			case 1:                            //Intro
					infoInstance.runFactFiction();
					DoLoop = 1;
					break;
			case 2:                            //Spark Length
					if (!findingSparkLength())
						break;
					DoLoop = 1;
					break;
			case 3:                            //Secondary Volts
					if (!findingSecVoltage())
						break;
					DoLoop = 1;
					break;
					case 4:                    //whats the frequency kenneth
					if (!findingResonantFreq())
						break;
					DoLoop = 1;
					break;
			case 5:                            //Power Transformer
					if (!findingPowerTrans())
						break;
					DoLoop = 1;
					break;
			case 6:                            //Spark Gap Info
					infoInstance.runSparkGapHelp();
					DoLoop = 1;
					break;
			case 7:                            //Primary Capacitor
					findingPriCapValue();
					DoLoop = 1;
					break;
			case 8:                            //Primary Coil
					findingPriIndValue();
					DoLoop = 1;
					break;
			case 9:                            //Secondary Coil
					findingSecIndValue();
					DoLoop = 1;
					break;
			case 10:                           //Secondary Cap$
					findingSecCapValue();
					DoLoop = 1;
					break;
			case 11:                           //General Help
					infoInstance.runGenHelp();
					DoLoop = 1;
					break;
			case 12:{                           //Save to file
				DoLoop = 1;
				double Cop;
				Brain();
				checkMissingValues();

				char name[256];
				cout << "Save file as: ";
					cin >> name;
				ofstream OutputFile  (name);
				OutputFile << "TESLA COIL DESIGN\n";
				OutputFile << "Label: " << name;
				OutputFile << "\n\n\n";
				OutputFile << "PRIMARY CIRCUIT\n";
				OutputFile << "  voltage:\t\t\t"             << funcGetVoltage(PInd)	<< " V\n";
				OutputFile << "  current:\t\t\t"             << funcGetCurrent(Pri)    << " A\n";
				OutputFile << "  inductor:\t\t\t"            << funcGetInductor(PInd)*1E6  << " uH\n";
				OutputFile << "    starting radius:\t\t"     << funcGetCoilRadius(PInd)  << " cm\n";
				OutputFile << "    number of turns:\t\t"     << funcGetCoilTurns(PInd)   << endl;
				OutputFile << "    spacing between turns:\t" << funcGetCoilSpacing(PInd) << " cm\n";
				OutputFile << "  capacitor:\t\t\t"           << funcGetCapacitor(PCap)*1E6 << " uF\n";
				OutputFile << "    Number of Plates:\t\t"    << funcCapacitorNumPlates(PCap)  << "\n";
				OutputFile << "    Dielectric constant:\t"   << funcCapacitorDielectric(PCap) << endl;
				OutputFile << "    Area of plates:\t\t"      << funcCapacitorArea(PCap)    << " cm cm\n";
				OutputFile << "    Dielectric thickness:\t"  << funcCapacitorThickness(PCap)  << " cm\n";
				OutputFile << "\n\n";
				OutputFile << "SECONDARY CIRCUIT\n";
				OutputFile << "  voltage:\t\t\t"             << funcGetVoltage(SInd)   << " V\n";
				OutputFile << "  current:\t\t\t"             << funcGetCurrent(Sec)    << " A\n";
				OutputFile << "  inductor:\t\t\t"            << funcGetInductor(SInd)*1E3  << " mH\n";
				OutputFile << "    radius:\t\t\t"            << funcGetCoilRadius(SInd) << " cm\n";
				OutputFile << "    number of turns:\t\t"     << funcGetCoilTurns(SInd)  << endl;
				OutputFile << "  capacitor:\t\t\t"           << funcGetCapacitor(SCap)*1E6 << " uF\n";
				OutputFile << "    Sphere radius:\t\t"     << funcCapacitorRadius(SCap)      << " cm\n";
				OutputFile << "    Toroid major radius:\t" << funcCapacitorMajorRadius(SCap) << " cm\n";
				OutputFile << "    Toroid minor radius:\t" << funcCapacitorMinorRadius(SCap) << " cm\n";
				OutputFile << "\n\n";
				OutputFile << "SPECIFICS:\n";
				OutputFile << "  Turn Ratio:\t\t\t"  << (unsigned int)(funcGetVoltage(SInd) / funcGetVoltage(PInd)) <<":1\n";
				OutputFile << "  Primary Resonant Frequency:\t" << funcGetResonantFrequency(Pri) << " kHz\n";
				OutputFile << "  Secondary Resonant Frequency:\t" << funcGetResonantFrequency(Sec) << " kHz\n";
				OutputFile << "  Percentage differnce of:\t" << 
					funcPercentDifference(funcGetResonantFrequency(Pri),funcGetResonantFrequency(Sec))<<"%\n";
				OutputFile << "  Spark Length:\t\t\t" << funcGetSparkLength(Sec) << " cm\n";
				OutputFile.close();
				
				cout << "Print now? ";
				char my_choice;
				cin >> my_choice;
				if (my_choice == 'y' || my_choice == 'Y' ){
					string print_command = "lpr -Psunlpr ";
					print_command += name;
					cout << print_command.data();
					system( print_command.data() );
					cout << "Printed!\n";
				}
				break;
				}
			case 13:							//Quit
					DoLoop=0;
					break;
			default:
					cout<<"You chose an invalid option..."<<endl;
					DoLoop=1;
					break;

        }//end switch statement
	}while (DoLoop);
}
//************************Brain******************************
void ui::Brain(){
	double z=0, Temp=0;
	if (funcGetCapacitor(SCap)>0 && funcGetInductor(SInd)>0 && funcGetResonantFrequency(Sec)==0){
		//need to convert to uF and mH 
		funcSetResonantFrequency(Sec,1/(2*M_PI*sqrt(funcGetCapacitor(SCap)*funcGetInductor(SInd))));
	}
	if (funcGetCapacitor(PCap)>0 && funcGetInductor(PInd)>0 && funcGetResonantFrequency(Pri)==0){
		//need to convert to uf and uH
		funcSetResonantFrequency(Pri,1/(2*M_PI*sqrt(funcGetCapacitor(PCap)*funcGetInductor(PInd))));
	}

	//finding impedence
	if (funcGetCapacitor(SCap)>0 && funcGetInductor(SInd)>0 ){
		funcSetImpedence(SInd, (1/(sqrt(funcGetCapacitor(SCap)*funcGetInductor(SInd))))*funcGetInductor(SInd));
		funcSetImpedence(SCap, 1/(1/(sqrt(funcGetCapacitor(SCap)*funcGetInductor(SInd))))*funcGetCapacitor(SCap));
	}
	if (funcGetCapacitor(PCap)>0 && funcGetInductor(PInd)>0 ){
		funcSetImpedence(PInd, (1/(sqrt(funcGetCapacitor(PCap)*funcGetInductor(PInd))))*funcGetInductor(PInd));
		funcSetImpedence(PCap, 1/(1/(sqrt(funcGetCapacitor(PCap)*funcGetInductor(PInd))))*funcGetCapacitor(PCap));
	}
	if (funcGetImpedence(SCap)>0 && funcGetImpedence(SInd)>0 && funcGetVoltage(SInd)>0){
		z = sqrt(funcGetImpedence(SInd) + 1/funcGetImpedence(SCap));
		funcSetCurrent(Sec,funcGetVoltage(SInd) / z);
	}
	if (funcGetImpedence(PCap)>0 && funcGetImpedence(PInd)>0 && funcGetVoltage(PInd)>0){
		z = sqrt(funcGetImpedence(PInd) + 1/funcGetImpedence(PCap));
		funcSetCurrent(Pri,funcGetVoltage(PInd) / z);
	}
}
//************************Checker****************************
int ui::checkMissingValues(){
	int marker=0;
	if (funcGetVoltage(PInd) == 0){
		cout << "Unknown: Primary voltage.\n";
		marker = 1;
	}
	if (funcGetCurrent(Pri) ==0){
		cout << "Unknown: Primary current.\n";
		marker = 1;
	}
	if (funcGetInductor(PInd) == 0){
		cout << "Unknown: Primary inductance.\n";
		marker = 1;
	}
	if (funcGetCapacitor(PCap) == 0){
		cout << "Unknown: Primary capacitance.\n";
		marker = 1;
	}
	if (funcGetVoltage(SInd) == 0){
		cout << "Unknown: Secondary voltage.\n";
		marker = 1;
	}
	if (funcGetCurrent(Sec)==0){
		cout << "Unknown: Secondary current.\n";
		marker = 1;
	}
	if (funcGetInductor(SInd)==0){
		cout << "Unknown: Secondary inductance.\n";
		marker = 1;
	}
	if (funcGetCapacitor(SCap)==0){
		cout << "Unknown: Secondary capacitance.\n";
		marker = 1;
	}
	if (funcGetResonantFrequency(Pri)==0){
		cout << "Unknown: Resonant frequency.\n";
		marker = 1;
	}
	if (marker = 1) 
		return 1;
	return 0;
}


/***************************Option 2 - Spark Length*****************************/
int ui::findingSparkLength(void){
	char c;
	double i=0;
	if (funcGetVoltage(SInd) > 0 || funcGetSparkLength(Sec) > 0)
    {
        do
        {
            cout << "You already entered a value for either the secondary voltage \n"
                << funcGetVoltage(SInd) << " V or a spark length of "
                << funcGetSparkLength(Sec) <<" cm\n";
            cout << "Enter a new length? ";
            cin.get(c);
			while (c == '\n') cin.get(c);   //takes out carriage return
            char c_junk = 'a';                       //waits for more characters
            while (c_junk != '\n') cin.get(c_junk);//waits for more until carriage $
            switch (c)
				{
            case 'N':
            case 'n':
                    DoLoop = 0;
                    return 0;
                    break;
            case 'Y':
            case 'y':
                    DoLoop = 0;
                    break;
            default:
                    DoLoop = 1;
                    break;
            } //end switch(c)
        }while(DoLoop);
    }
    cout << "Enter requested spark length (cm): ";
    cin >> i;
    funcSetSparkLength(Sec,i);
    funcSetVoltage(SInd,double (funcGetSparkLength(Sec)*15000));   //since 15kv/cm air breakdown
}

/***************************Option 3 - Secondary Voltage***********************/
int ui::findingSecVoltage(void){
    double i=0;
	char c;
	if (funcGetSparkLength(Sec) > 0 || funcGetVoltage(SInd) > 0)
    {
        do
        {
            cout << "You already entered a value for either the secondary voltage \n"
                    << funcGetVoltage(SInd) << " V or a spark length of "
                    << funcGetSparkLength(Sec) <<" cm\n";
            cout << "Enter a new secondary voltage? ";
            cin.get(c);
			while (c == '\n') cin.get(c);   //takes out carriage return
            char c_junk = 'a';                       //waits for more characters
            while (c_junk != '\n') cin.get(c_junk);//waits for more until carriage $
            switch (c)
				{
            case 'N':
            case 'n':
                    DoLoop = 0;
                    return 0;
                    break;
            case 'Y':
            case 'y':
                    DoLoop = 0;
                    break;
            default:
                    DoLoop = 1;
                    break;
            } //end switch(c)
        }while(DoLoop);
    }
	cout << "Enter requested voltage (V): ";
    cin >> i;
    funcSetVoltage(SInd,i);
	//since 15kv/cm air breakdown
    funcSetSparkLength(Sec,double (funcGetVoltage(SInd) / 15000)); 
    return 1;

}
/***************************Option 4 - Resonant Frequency*******************/
int ui::findingResonantFreq(void){
    int DoLoop;
    char c;
	double i=0;
    if (funcGetResonantFrequency(Pri) > 0)
    {
        do{
            cout << "You already have " << funcGetResonantFrequency(Pri)
                            << " kHz as the resonant frequency for the system.\n";
            cout << "Enter a new value? ";
            cin.get(c);
            while (c == '\n') cin.get(c);   //takes out carriage return
            char c_junk = 'a';               //waits for more characters
            while (c_junk != '\n') cin.get(c_junk);//waits for more until carriage
            switch (c)
            {
            case 'N':
            case 'n':
                    DoLoop = 0;
                    return 0;
                    break;
            case 'Y':
            case 'y':
                    DoLoop = 0;
                    break;
            default:
                    DoLoop = 1;
                    break;
            } //end switch(c)
        }while(DoLoop);
    }
    cout << "Enter the oscillation frequency of the system in kHz: ";
	cin >> i;
    funcSetResonantFrequency(Pri,i);
    return 1;
}


/***************************Option 5 - Power Transformer*******************/
int ui::findingPowerTrans(void){
    int DoLoop;
    char c;
	double i=0;
    if (funcGetVoltage(PInd) > 0)
    {
		do{
            cout << "You already entered a transformer voltage of "
                    << funcGetVoltage(PInd) << " V\n";
            cout << "Enter a new voltage? ";
            cin.get(c);
            while (c == '\n') cin.get(c);   //takes out carriage return
            char c_junk = 'a';                      //waits for more characters
            while (c_junk != '\n') cin.get(c_junk);//waits for more until carriage return
            switch (c)
            {
            case 'N':
            case 'n':
                    DoLoop = 0;
                    return 0;
                    break;
            case 'Y':
            case 'y':
                    DoLoop = 0;
                    break;
            default:
                    DoLoop = 1;
                    break;
                } //end switch(c)
         }while(DoLoop);
    }
    cout << "Enter the voltage rating of the power transformer: ";
    cin >> i;
	funcSetVoltage(PInd,i);
    return 1;
}

/***************************Option 7 - Primary Capacitor*******************/
int ui::findingPriCapValue(void)
{
    double TempCap;
    int DoLoop=0;
    char c;
    do
    {
        cout << "\t\t\t\tPRIMARY CAPACITOR\n\n\n";
        cout << "Known (C)apacitance\n";
        cout << "\tNOTE: be sure that the capacitor's voltage rating is\n";
        cout << "\t      higher than the primary voltage!\n";
        cout << "(B)uild Capacitor\n";
        cout << "(H)elp\n";
        cout << "(E)xit\n";
        cin.get(c);
        while (c == '\n') cin.get(c);   //takes out carriage return
        char c_junk = 'a';               //waits for more characters
        while (c_junk != '\n') cin.get(c_junk);//waits for more until carriage return
        switch (c)
        {
        case 'C':
        case 'c':
                cout << "Enter capacitance in micro Farads (uF): ";
                cin >> TempCap;
                funcSetCapacitor(PCap,TempCap*1E-6);
                DoLoop = 0;
                break;
        case 'B':
        case 'b':
                findingParallelPlateCap();
                DoLoop = 0;
                break;
        case 'H':
		case 'h':
                cout << "Help file goes here.";
                DoLoop = 1;
                break;
        case 'E':
        case 'e':
                DoLoop = 0;
                break;
        default:
                cout << "You chose an invalid option...";
                DoLoop = 1;
                break;
        }
    }while (DoLoop);
	return 1;
}

/********************************************************************
*            option 7's      Parallel Plate Capacitor                *
*this has been set aside b/c there are more types of capacitors that *
*can be built by the user.                                           *
********************************************************************/

void ui::findingParallelPlateCap(void)
{
    double EpsilonNot = 8.85E-12;
	double Thickness=0, Area=0, K=0 ,NumPlates=0;
    cout<<"\t\t\t\tPARALLEL PLATE CAPACITOR\n\n\n";
    do
	{           //When the help me list is optioned,
                //use Choice to help determine which list to user
                //for the safety margin
        cout<<"Enter thickness of the dielectric (cm): ";
        cin >>Thickness;
    }while (findingSafetyMargin(Thickness));
    cout<<"Enter the Area of the conductive plate: ";
    cin >> Area;
    cout<<"Enter the dielectric constant: ";
    cin >> K;
    cout<<"Enter the number of conductive plates used: ";
    cin >> NumPlates;
	funcCapacitorThickness(PCap, Thickness);
	funcCapacitorArea(PCap, Area);
	funcCapacitorDielectric(PCap, K);
	funcCapacitorNumPlates(PCap, NumPlates);
	//now in F
    funcSetCapacitor(PCap,(EpsilonNot*K*Area/Thickness*(NumPlates-1))); 
}



/********************************************************************
* option 7's    Safety Margin Function(for both Standard and Metric)*
********************************************************************/

int ui::findingSafetyMargin(double Thickness)
{
    double PriVoltage=0, PunctVolt=0, TempThickness=0;
    if (funcGetVoltage(PInd) <= 0){
        cout << "Enter the voltage of the power supply: ";
        cin >> PriVoltage;
        funcSetVoltage(PInd,PriVoltage);
    }
        cout << "Enter the puncture voltage per micron (um): ";
        cin >> PunctVolt;
    //puncvoltage mult by appropriate conversion to cm
    TempThickness = float( (funcGetVoltage(PInd) * 5.656) / PunctVolt);
    if (Thickness >= TempThickness)
    {
        cout<<"not yet... should go straight to Area...\n";
        return 0;
    }
    else
    {
        cout << "ERROR: at this thickness your capacitor will break down!!\n";
        cout << "because the nature of a Tesla Coil is not a clean sine wave,\n";
        cout << "a thicker layer will need to be used.\n";
        return 1;
    }
}

/***************************Option 8 - Primary Inductor********************/
void ui::findingPriIndValue(void)
{
	int DoLoop;
	//Temp Variables
	double Radius, Turns, Spacing, Width, a, L;
	char c;
	do{
		// write a check value prot.  checks if the inductor is>0 and prompts an option
		cout << "\t\t\t\tPRIMARY COIL\n\n\n";
		cout << "(B)uild primary coil\n";
		cout << "(H)elp\n";
		cout << "(E)xit\n";
		cout << "Choice: ";
		cin.get(c);
		while (c == '\n') cin.get(c);   //takes out carriage return
			char c_junk = 'a';           //waits for more characters
			while (c_junk != '\n') cin.get(c_junk);//waits for more until carriage return
			switch(c)
			{
			case 'B':
			case 'b':
				if (funcGetCoilRadius(SInd) == 0){
					cout << "Enter the the radius of the secondary coil: ";
					cin >> Radius;
					funcSetCoilRadius(SInd, Radius);
				}
				cout << "How many turns? ";
				cin >> Turns;
				cout << "What is the seperation between turns? ";
				cin >> Spacing;

				Width = Turns * Spacing;
				a = 0.5 * Width + funcGetCoilRadius(PInd);
				//already in uH, bu will convert to H
				L = ((a*a/(2.54*2.54)) + Turns * Turns)/((8*a/2.54)+(11*Width/2.54));
				funcSetCoilRadius(PInd, funcGetCoilRadius(SInd) + 1);//add a centimeter
				funcSetCoilSpacing(PInd, Spacing);
				funcSetCoilTurns(PInd, Turns);
				funcSetInductor(PInd, L*1E-6);
				DoLoop=0;
				break;
			case 'H':
			case 'h':
				infoInstance.runPriIndHelp();
				DoLoop=1;
				break;
			case 'E':
			case 'e':
				DoLoop = 0;
				break;
			default:
				cout << "You chose an invalid option..."<<endl;
				DoLoop=1;
				break;
			}// end switch
	}while(DoLoop);
}
/***************************Option 9 - Secondary Inductor*******************/
void ui::findingSecIndValue(void)
{
	int DoLoop;
	char c;
	//Temporary variables
	double MuNot = 1.26E-6, Radius, Length, Area, Turns, L; 
	do{
		cout << "\t\t\t\tSECONDARY COIL\n\n\n";
		cout << "(B)uild secondary coil\n";
		cout << "(H)elp\n";
		cout << "(E)xit\n";
		cout << "Choice: ";
		cin.get(c);
		while (c == '\n') cin.get(c);   //takes out carriage return
			char c_junk = 'a';           //waits for more characters
			while (c_junk != '\n') cin.get(c_junk);//waits for more until carriage return
			switch(c)
			{
			case 'B':
			case 'b':
					cout << "Enter radius of the coil (cm): ";
					cin >> Radius;
					cout << "Enter length of the coil (cm): ";
					cin >> Length;
					cout << "Enter the number of turns: ";
					cin >> Turns;
					//the divide by 100 is to convert cm -> m
					Area =M_PI * Radius * Radius / 10000;
					L = MuNot * Turns * Turns * Area / (Length/100);// in Henries
					funcSetCoilRadius(SInd, Radius);
					funcSetCoilTurns(SInd, Turns);
					funcSetCoilLength(SInd, Length);
					funcSetInductor(SInd, L); // in Henries
					DoLoop=0;
					break;
			case 'H':
			case 'h':
					infoInstance.runSecIndHelp();
					DoLoop=1;
					break;
			case 'E':
			case 'e':
					DoLoop = 0;
					break;
			default:
					cout << "You chose an invalid option..."<<endl;
					DoLoop=1;
					break;
			}// end switch
	}while(DoLoop);
}

/***************************Option 10 - Secondary Capacitor*******************/
void ui::findingSecCapValue(void)
{
    int DoLoop=0;
	//temporary variables
	double EpsilonNot = 8.85E-12, cap;
    char c;
    do
    {
        cout<<"\n\t\t\t\tSECONDARY CAPACITOR\n\n\n";
        cout<<"(S)phere type\n";
        cout<<"(T)oroid type (donut shape)\n";
        cout<<"\trecommended for best charge distribution.\n";
        cout<<"(H)elp"<<endl;
        cout<<"Choice: ";
        cin.get(c);
        while (c == '\n') cin.get(c);   //takes out carriage return
        char c_junk = 'a';               //waits for more characters
        while (c_junk != '\n') cin.get(c_junk);//waits for more until carriage return
        switch(c)
        {
        case 'S':
        case 's':
                float Radius;
                do{
                    cout<<"Enter approximate radius of the sphere (cm): ";
                    cin >>Radius;
                }while (Radius<=0);
				cap = 4*M_PI*EpsilonNot*(Radius/100);// in F
				funcCapacitorRadius(SCap,Radius);
                funcSetCapacitor(SCap,cap);
                DoLoop=0;
                break;
        case 'T':
        case 't':
                float MinorRadius,MajorRadius;
                do{
					cout << "Enter minor radius of the cylinder (cm): ";
                    cin >> MinorRadius;
                    cout << "Enter major radius of the torus (cm): ";
                    cin >> MajorRadius;
                }while (MinorRadius<=0 || MajorRadius<=0 || MajorRadius<=MinorRadius);
            //Need to multiply by conversion from cm to meters = 0.01
                funcCapacitorMajorRadius(SCap, MajorRadius);
		funcCapacitorMinorRadius(SCap, MinorRadius);
		funcSetCapacitor(SCap,(4*M_PI*M_PI*EpsilonNot*MajorRadius*0.01)/ log(8*MajorRadius / MinorRadius));
                DoLoop=0;
                break;
        case 'H':
        case 'h':
                infoInstance.runSecCapHelp();
                DoLoop=1;
                break;
        default:
                cout<<"You chose an invalid option..."<<endl;
                DoLoop=1;
                break;
        }// end switch
    }while (DoLoop);
}


/*
	Class 'information'  From these class definitions, all the help and information
	files can be accessed.
*/
void info::runFactFiction(void)
{
	int Choice = 1, DoLoop = 0;
    char c;

    const int num_pages = 3;
    char *fname[3] = {
            "factsvsfiction1.dat",
            "factsvsfiction2.dat",
            "factsvsfiction3.dat"
    };

    while (1) {
        if (Choice > 0 && Choice < num_pages+1) {
            do 
			{
                fstream facts(fname[Choice-1],ios::in);
                char *fvf = new char[1920];
                for (int i=0; i<1920; i++) fvf[i] = '\0';
                facts.read(fvf, 1920);
                cout << fvf << "\n";
                facts.close();
                delete []fvf;
                if (Choice != num_pages) cout << "(N)ext Page\t";
                if (Choice != 1) cout << "(P)rev Page\t";
                cout << "(E)xit ";
                cin.get(c);
                while (c == '\n') cin.get(c);   //takes out carriage return
                char c_junk = 'a';               //waits for mor$
                while (c_junk != '\n') cin.get(c_junk);//waits for more until c$
                switch (c)
                {
                case 'N':                        //Next $
                case 'n':
                        if (Choice != num_pages) {
                            DoLoop = 0;
                            Choice++;
                        }
                        break;
				case 'P':                         //Previ$
                case 'p':
                        if (Choice != 1) {
                            DoLoop = 0;
                            Choice--;
                        }
                        break;
                case 'E':                         //Exit $
                case 'e':
                        return;
                        break;
                default:
                        DoLoop = 1;
                        break;
                } //end switch(c)
            }while (DoLoop);  //end Do-While Loop
        } //end if statement
		else {
            cout << "You chose an invalid option... " << endl;
        }       //end else statement
    }       //end while(1)
}       //end info::runFactFiction definition


void info::runGenHelp(void)
{
    fstream genhelp("generalhelp.dat",ios::in);
    char *gh = new char[1920];
    for (int i=0; i<1920; i++) gh[i] = '\0';
    genhelp.read(gh, 1920);
    cout << gh << "\n";
    genhelp.close();
    delete []gh;
}

void info::runSecCapHelp(void)
{
    fstream seccaphelp("seccaphelp.dat",ios::in);
    char *sch = new char[1920];
    for (int i=0; i<1920; i++) sch[i] = '\0';
	 seccaphelp.read(sch, 1920);
    cout << sch << "\n";
    seccaphelp.close();
    delete []sch;
}

void info::runPriCapHelp(void)
{
    fstream pricaphelp("pricaphelp.dat",ios::in);
    char *pch = new char[1920];
    for (int i=0; i<1920; i++) pch[i] = '\0';
    pricaphelp.read(pch, 1920);
    cout << pch << "\n";
    pricaphelp.close();
    delete []pch;
}

void info::runSparkGapHelp(void)
{
    int DoLoop = 1;
    do
    {
        fstream sparkgap("sparkgap.dat",ios::in);
        char *sp = new char[1920];
        for (int i=0; i<1920; i++) sp[i] = '\0';
        sparkgap.read(sp, 1920);
        cout << sp << "\n";
        sparkgap.close();
        delete []sp;
        cout << "1) Exit ";
        cin >> DoLoop;
    }while(DoLoop != 1);
}

void info::runPowTranHelp(void)
{
    fstream powtranhelp("powtranhelp.dat",ios::in);
    char *pth = new char[1920];
	for (int i=0; i<1920; i++) pth[i] = '\0';
    powtranhelp.read(pth, 1920);
    cout << pth << "\n";
    powtranhelp.close();
    delete []pth;
}

void info::runPriIndHelp(void)
{
    fstream powtranhelp("priindhelp.dat",ios::in);
    char *pth = new char[1920];
	for (int i=0; i<1920; i++) pth[i] = '\0';
    powtranhelp.read(pth, 1920);
    cout << pth << "\n";
    powtranhelp.close();
    delete []pth;
}

void info::runSecIndHelp(void)
{
    fstream powtranhelp("secindhelp.dat",ios::in);
    char *pth = new char[1920];
	for (int i=0; i<1920; i++) pth[i] = '\0';
    powtranhelp.read(pth, 1920);
    cout << pth << "\n";
    powtranhelp.close();
    delete []pth;
}
