Last active
August 29, 2015 13:56
-
-
Save dillmo/8842857 to your computer and use it in GitHub Desktop.
Random Function Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright(c) dillmo 2014 | |
* Licensed under the MIT License (http://opensource.org/licenses/MIT) | |
* | |
* A program I made for algebra class. Running this program outputs several | |
* functions with their respective parent functions. To take advantage of this | |
* program for studying, it is recommended you run it, then graph the output | |
* for whichever type of function you are studying. | |
*/ | |
#include <iostream> | |
#include <cstdlib> | |
#include <ctime> | |
using namespace std; | |
int main() { | |
int a, h, k, b, c, d; | |
srand (time(NULL)); | |
// Constant function | |
cout << "Parent function: y = a" << '\n'; | |
for(int i = 1; i <= 2; i++) | |
{ | |
a = rand() % 20 - 10; | |
cout << "Trans " << i << ": y = " << a << '\n'; | |
} | |
// Linear function | |
cout << '\n' << "Parent function: y = x" << '\n'; | |
for(int i = 1; i <= 2; i++) | |
{ | |
do | |
{ | |
a = rand() % 20 - 10; | |
} while(a == 0); | |
cout << "Trans " << i << ": y = " << a << "x" << '\n'; | |
} | |
// Absolute value function | |
cout << '\n' << "Parent function: y = |x|" << '\n'; | |
for(int i = 1; i <= 2; i++) | |
{ | |
do | |
{ | |
a = rand() % 20 - 10; | |
} while(a == 0); | |
h = rand() % 20 - 10; | |
k = rand() % 20 - 10; | |
cout << "Trans " << i << ": y = " << a << "|x + (" << -h << ")| + (" << k | |
<< ")" << '\n'; | |
} | |
// Quadratic function | |
cout << '\n' << "Parent function: y = x^2" << '\n'; | |
for(int i = 1; i <= 2; i++) | |
{ | |
do | |
{ | |
a = rand() % 20 - 10; | |
} while(a == 0); | |
h = rand() % 20 - 10; | |
k = rand() % 20 - 10; | |
cout << "Trans " << i << ": y = " << a << "(x + (" << -h << "))^2 + (" << k | |
<< ")" << '\n'; | |
} | |
// Square root function | |
cout << '\n' << "Parent function: y = sqrt(x)" << '\n'; | |
for(int i = 1; i <= 2; i++) | |
{ | |
do | |
{ | |
a = rand() % 20 - 10; | |
} while(a == 0); | |
h = rand() % 20 - 10; | |
k = rand() % 20 - 10; | |
cout << "Trans " << i << ": y = " << a << " * sqrt(x + (" << h << ")) + (" | |
<< k << ")" << '\n'; | |
} | |
// Cubic function | |
cout << '\n' << "Parent function: y = x^3" << '\n'; | |
for(int i = 1; i <= 2; i++) | |
{ | |
do | |
{ | |
a = rand() % 20 - 10; | |
} while(a == 0); | |
b = rand() % 20 - 10; | |
c = rand() % 20 - 10; | |
d = rand() % 20 - 10; | |
cout << "Trans " << i << ": y = " << a << "x^3 + (" << b << ")x^2 + (" << c | |
<< ")x + (" << d << ")" << '\n'; | |
} | |
// Cube root function | |
cout << '\n' << "Parent function: y = x^(1/3)" << '\n'; | |
for(int i = 1; i <= 2; i++) | |
{ | |
do | |
{ | |
a = rand() % 20 - 10; | |
} while(a == 0); | |
h = rand() % 20 - 10; | |
k = rand() % 20 - 10; | |
cout << "Trans " << i << ": y = " << a << "(x + (" << -h << "))^(1/3) + (" | |
<< k << ")" << '\n'; | |
} | |
// Exponential function | |
cout << '\n' << "Parent function: y = a^x" << '\n'; | |
for(int i = 1; i <= 2; i++) | |
{ | |
do | |
{ | |
a = rand() % 20 - 10; | |
} while((a == 0) || (a == 1)); | |
h = rand() % 20 - 10; | |
k = rand() % 20 - 10; | |
cout << "Trans " << i << ": y = " << a << "^(x + (" << -h << ")) + (" << k | |
<< ")" << '\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment