/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <cctype>
#include <string>
#include <math.h>
//#include "koolplot.h"
#include <cstdlib>
using namespace std;
//This program plots a parabolic function for any input of variables//
void printheader () //Print the header
{
cout << "Please Enter A,B and C for the parabolic function below" << endl;
cout << "y=Ax^2+Bx+C" << endl;
}
int getInt (int *x)
{ //check for non-integer input
string theInput;
int inputAsInt;
getline (cin, theInput);
while (cin.fail () || cin.eof ()
|| theInput.find_first_not_of ("-0123456789.") != std::string::npos)
{
cout << "Invalid input. Try again: ";
if (theInput.find_first_not_of ("-0123456789. ") == std::string::npos)
{
cin.clear ();
cin.ignore (1000, '\n');
}
getline (cin, theInput);
}
std::string::size_type st;
inputAsInt = atoi (theInput.c_str());//Turn string into int
*x = inputAsInt;
return *x;
}
/*int MathRun (int A, int B, int C,int a, int b) //plot star points for each result
{
if (A && B && C && a && b != 0)
{
plotdata x(a, b), y=A*x*x+B*x+C;
plot(x,y);
return 0;
}
}*/
int main () //ask for variables of parabolic function
{
bool restart = true;
int *array;
array = new int[5];
printheader ();
while(restart){
for (int y = 0; y <= 4; y++)
{
char NameOfVariable[] = "ABC";
if (y==3)
{
cout<<"Please Enter Plotting Range for "<<endl;
cout <<"X1"<< ":";
getInt (&array[3]);
}
else
if (y==4)
{
cout<<"Please Enter Plotting Range for"<<endl;
cout <<"X2" << ":";
getInt (&array[4]);
}
else
{
cout << "Please Enter An Integery for Variable" << endl;
cout << NameOfVariable[y] << ":";
getInt (&array[y]);
}
int VariableA = array[0];
int VariableB = array[1];
int VariableC = array[2];
int Xrange1 = array[3];
int Xrange2 = array[4];
//MathRun (VariableA, VariableB,VariableC ,Xrange1,Xrange2);
}
cout<<"Do you want to restart the program again? y/n"<<endl;
char c;
cin>>c;
if (c =='y'){
delete[] array;
restart = true;
}
else{
restart = false;
}
}
return 0;
}