Skip to content

Instantly share code, notes, and snippets.

@dillmo
Last active August 29, 2015 13:56
Show Gist options
  • Save dillmo/8842857 to your computer and use it in GitHub Desktop.
Save dillmo/8842857 to your computer and use it in GitHub Desktop.
Random Function Generator
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int a, h, k, b, c, d;
srand (time(NULL));
cout << "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';
}
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';
}
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';
}
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';
}
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';
}
cout << '\n' << "Parent function: y = x^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';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment