Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <math.h>
- using namespace std;
- struct Polinomial
- {
- int coefficient;
- int expX;
- int expY;
- int expZ;
- Polinomial *next;
- };
- typedef Polinomial* Point;
- void Create(Point &List)
- {
- Point P, Last = NULL;
- char ch;
- int counter = 0;
- cout << "Nov element (Y/N) ?:";
- cin >> ch;
- while (ch == 'Y' || ch == 'y')
- {
- counter++;
- P = new Polinomial;
- cout << "Element nomer " << counter << ":" << endl;
- cout << "Vuvedete koeficient na polinoma:";
- cin >> P->coefficient;
- cout << "Vuvedete stepen na x:";
- cin >> P->expX;
- cout << "Vuvedete stepen na y:";
- cin >> P->expY;
- cout << "Vuvedete stepen na z:";
- cin >> P->expZ;
- P->next = NULL;
- if (List == NULL)
- List = P;
- else
- Last->next = P;
- Last = P;
- cout << "Nov element ?:";
- cin >> ch;
- }
- }
- void PrintPolynomial(Point P)
- {
- while (P)
- {
- char sign = ((P->coefficient >= 0) ? '+' : '-'); //Решава какъв знак да сложи преди коефициента (+ или -)
- cout << sign << abs(P->coefficient) << "*x^" << P->expX << "*y^" << P->expY << "*z^" << P->expZ;
- P = P->next;
- }
- cout << endl;
- }
- int CalculatePolynomial(Point List)
- {
- int valueX, valueY, valueZ, total = 0, counter = 0;
- while (List)
- {
- counter++;
- cout << "Element nomer " << counter << ":" << endl;
- cout << "--Vuvedete stoinost na x: " << endl;
- cin >> valueX;
- cout << "--Vuvedete stoinost na y: " << endl;
- cin >> valueY;
- cout << "--Vuvedete stoinost na z: " << endl;
- cin >> valueZ;
- total += List->coefficient * pow(valueX, List->expX) * pow(valueY, List->expY) * pow(valueZ, List->expZ);
- List = List->next;
- }
- return total;
- }
- void main()
- {
- Point List = NULL;
- Create(List);
- PrintPolynomial(List);
- int result = CalculatePolynomial(List);
- cout << "Sumata na polinoma e: " << result << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement