Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <stdio.h>
- #include <locale.h>
- #include <windows.h>
- using namespace std;
- struct KVY {
- double a;
- double b;
- double c;
- };
- KVY* Create(double a, double b, double c) {
- KVY* yr = new KVY();
- if (aaa == 0) {
- cout << "Введите значение не равное нулю: ";
- cin >> aaa;
- }
- yr->a = a;
- yr->b = b;
- yr->c = c;
- return yr;
- };
- void ref(KVY* f, double* x3, double* x4, int *g) {
- double D = f->b * f->b*1. - 4. * f->a * f->c;
- if (D > 0) {
- *x3 = ((-1 * f->b + sqrt(D)) / (2 * f->a));
- *x4 = ((-1 * f->b - sqrt(D)) / (2 * f->a));
- *g = 2;
- }
- if (D == 0) {
- *x3 = -f->b / (2 * f->a);
- *g = 1;
- }
- if (D < 0) {
- *g = 0;
- }
- }
- void print(KVY* f) {
- double x1, x2;
- int i;
- ref(f, &x1, &x2, &i);
- cout << "Ответ: ";
- if (i == 0) cout << "Решения нет!\n";
- if (i == 1) {
- cout << "x = "<< x1 << "\n";
- }
- if (i == 2) {
- cout << "x1 = " << x1 << " x2 = " << x2 << "\n";
- }
- }
- void printyr(KVY* f) {
- cout << "Введенное уравниение: " << f->a << " * x^2 + " << f->b << " * x + " << f->c << "\n";
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- double a = 0, b = 0, c = 0;
- cout << "Введите числовые коэффициенты A, B, C для A*x^2+B*x+C\n";
- cout << "Введите A не равное нулю: ";
- cin >> a;
- cout << "Введите B: ";
- cin >> b;
- cout << "Введите C: ";
- cin >> c;
- KVY* yrav = Create(a,b,c);
- printyr(yrav);
- print(yrav);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement