1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
//graphing calculator. plot points derive and asymptotes.
#include <iostream>
#include <math.h>
using namespace std;
double sub ( double coeff, int power)
{ double der;
der = power*coeff;
return (der);
}
int main()
{
double coeff[11]={0};
double point[11]={0};
double degree, points;
char x;
cout << "Welcome to my graphing utility!\n";
cout << "Would you like to a. derive the function, or b. plot points? \n";
cin >> x;
if ( x== 'a')
{cout << "Insert your equation and the points you want to input and I will do the rest.\n";
cout << "What is the highest degree of your equation: (up to 10) \n";
cin >> degree;
for ( int n = 0 ; n<degree ; n++)
{cout << "what is the coefficient of x^" << n+1 << endl;
cin >>coeff[n+1];}
cout << "What is your constant: \n";
cin >> coeff[0];
cout << "The derivative of \n";
cout << coeff[10] << "x^10 + " << coeff[9] << "x^9 + " << coeff[8] << "x^8 + " << coeff[7] << "x^7 + " << coeff[6] << "x^6 + " << coeff[5] << "x^5 + " << coeff[4] << "x^4 + " << coeff[3] << "x^3 + " << coeff[2] << "x^2 + " << coeff[1] << "x^1 + " << coeff[0];
cout << " is: \n";
cout << sub(coeff[10],10) << "x^9 + " << sub(coeff[9],9) << "x^8 + " << sub(coeff[8],8) << "x^7 + " << sub(coeff[7],7) << "x^6 + " << sub(coeff[6],6) << "x^5 + " << sub(coeff[5],5) << "x^4 + " << sub(coeff[4],4) << "x^3 + " << sub(coeff[3],3) << "x^2 + " << sub(coeff[2],2) << "x + " << coeff[1] << " + 0\n"; }
else
{cout << "Insert your equation and the points you want to input and I will do the rest.\n";
cout << "What is the highest degree of your equation: (up to 10) \n";
cin >> degree;
for ( int n = 0 ; n<degree ; n++)
{cout << "what is the coefficient of x^" << n+1 << endl;
cin >>coeff[n+1];}
cout << "What is your constant: \n";
cin >> coeff[0];
char z;
do {
cout << "How many points do you want to plot: (up to 10) \n";
cin>> points;
for ( int p=0; p<points ; p++)
{cout << "What is point number " << p+1 << ": \n";
cin >> point[p];}
cout << "Your equation is: " << coeff[10] << "x^10 + " << coeff[9] << "x^9 + " << coeff[8] << "x^8 + " << coeff[7] << "x^7 + " << coeff[6] << "x^6 + " << coeff[5] << "x^5 + " << coeff[4] << "x^4 + " << coeff[3] << "x^3 + " << coeff[2] << "x^2 + " << coeff[1] << "x^1 + " << coeff[0] << endl;
cout << "x | y \n";
for ( int p ; p<points ; p++)
{cout << "(" << point[p] << "," ;
//cout << coeff[10]*pow(point[p],10) + coeff[9]*pow(point[p],9) + coeff[8]*pow(point[p],8) + coeff[7]*pow(point[p],7) + coeff[6]*pow(point[p],6) + coeff[5]*pow(point[p],5) + coeff[4]*pow(point[p],4) + coeff[3]*pow(point[p],3) + coeff[2]*pow(point[p],2) + coeff[1]*pow(point[p],1) + coeff[0]*pow(point[p],1);
double sum=0.0;
for( int n=10; n >= 0 ; n-- )
{sum += coeff[n]*pow(point[p],n);}
cout << sum << ")" <<endl;}
cout << endl;
cout << "Do you want to add more points? <y/n> \n";
cin >> z;
} while (z != 'n');}
system("pause");}
|