Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- #define MAX 1
- struct object{
- float a, b;
- void input()
- {
- cout << "Input a b: ";
- cin >> a >> b;
- }
- void sim() { a = -a; }
- int check() { return a == 0 || b == 0 ? -1 : 1; }
- int argument(float &x1, float &x2, float y);
- int isPeretyn(float y);
- void output(float x1, float x2, int p);
- };
- int object::argument(float &x1, float &x2, float y)
- {
- float d = 0.0;
- b -= y;
- d =a*a + 4*b;
- if (d > 0) {
- x1 = (-a - sqrt(d))/-2;
- x2 = (-a + sqrt(d))/-2;
- }
- else if (d == 0) {x1 = -a / 2 * -1; x2 = x1;}
- else return 0;
- return 1;
- }
- int object::isPeretyn(float y)
- {
- return y >= 0 ? 1 : -1;
- }
- void object::output(float x1, float x2, int p)
- {
- cout << "x1 = " << setprecision(3) << x1 << " x2 = " << setprecision(3) << x2 << endl;
- cout << "Parabola " << (p == 1 ? "crosses" : "doesn't cross") << " OX\n";
- cout << "-x^2 + " << setprecision(3) << a << "x + " << setprecision(3) << b << "\n";
- }
- int main()
- {
- int v = 0, i;
- float x1, x2;
- object ob[MAX];
- for (i = 0; i < MAX; i++)
- {
- ob[i].input();
- }
- for (i = 0; i < MAX; i++)
- {
- v = ob[i].check();
- if (v == 1) {
- int peret = 0;
- float y = 0.0;
- cout << "\ninput y: ";
- cin >> y;
- if (ob[i].argument(x1, x2, y))
- {
- peret = ob[i].isPeretyn(y);
- ob[i].sim();
- ob[i].output(x1, x2, peret);
- }
- else cout << "error: d < 0\n";
- }
- else
- {
- cout<<"\nIncorrect coefficients\n";
- }
- }
- cin.ignore();
- cin.get();
- return 0;
- }
- /*Квадратична функція y=-x2+Ax+B. Поле first – дійсне число, коефіцієнт A;
- поле second – дійсне число, коефіцієнт B. Реалізувати методи argument(ob) –
- обчислення для заданого y відповідних значень x, isPeretyn(ob) – визначення,
- чи перетинається парабола з віссю OX, sim(ob) – перетворення параболи у симетричну
- до неї параболу відносно осі OY.
- */
Advertisement
Add Comment
Please, Sign In to add comment