Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- double sekret_punktow( int x1, int y1, int x2, int y2, int x3, int y3 )
- {
- double wspolczynnik_b = ((y1-y3) * (x1*x1 - x2*x2) - (x1*x1 - x3*x3)*(y1-y2)) / ((x1-x3)*(x1*x1 - x2*x2) - (x1-x2)*(x1*x1-x3*x3));
- double wspolczynnik_a = (y1 - y2 - wspolczynnik_b*(x1 - x2)) / (x1*x1 - x2*x2);
- double wspolczynnik_c = (wspolczynnik_a *x1*x1 + wspolczynnik_b * x1 - y1) * -1;
- return wspolczynnik_c;
- }
- int main()
- {
- srand(time(NULL));
- int sekret = 0;
- cout << "podaj sekretna liczbe: " << endl;
- cin >> sekret;
- int a = (rand() % 5) + 1;
- int b = (rand() % 5) + 1;
- cout << "wybrany wielomian: " << a << "x^2" << " + " << b << "x" << " + " << sekret << endl << endl;
- int lx = rand() % 15 + 3;
- float x1 = lx;
- float y1 = a * lx * lx + b * lx + sekret;
- cout << "x1: " << x1 << " y1: " << y1 << endl;
- lx = rand() % 10 + 15;
- float x2 = lx;
- float y2 = a * lx * lx + b * lx + sekret;
- cout << "x2: " << x2 << " y2: " << y2 << endl;
- lx = rand() % 15 + 7;
- float x3 = lx;
- float y3 = a * lx * lx + b * lx + sekret;
- cout << "x3: " << x3 << " y3: " << y3 << endl;
- cout << "czy chcesz odszyfrowac sekret na podstawie punktow? (y/n)" << endl;
- string input;
- cin >> input;
- if(input == "y")
- {
- double sekretna_liczba = sekret_punktow( x1, y1, x2, y2, x3, y3 );
- cout << "sekret to: " << sekretna_liczba << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement