Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <sstream>
- #include <string>
- using namespace std;
- class Polinom
- {
- private:
- vector<int> params;
- public:
- Polinom(vector<int> params)
- {
- this->params = params;
- }
- string to_String() const
- {
- string s;
- for (int i = 0; i < params.size(); i++)
- {
- // 12 x^ 3 + x^2 - 4x + 13
- if (params[i] > 0 )
- {
- if (i != 0 )
- {
- s += '+';
- }
- if (params[i] != 1)
- {
- s += to_string(params[i]);
- }
- else if (params[i] == params.size() && params[i] == 1)
- {
- s += to_string(params[i]);
- }
- }
- else if (params[i] == 0)
- {
- continue;
- }
- else
- {
- if (params[i] == -1)
- {
- s += '-';
- }
- else
- {
- s += to_string(params[i]);
- }
- }
- if (i != params.size() - 1)
- {
- s += 'x';
- }
- if (params.size() - 2 <= i)
- {
- continue;
- }
- s += '^' + to_string(params.size() - i - 1);
- }
- return s ;
- }
- Polinom* get_derivative()
- {
- vector<int> par;
- for (int i = 0; i < params.size() - 1 ; i++)
- {
- par[i] = (params[i] * ((int)params.size() - i - 1));
- }
- return new Polinom (par);
- }
- };
- int main()
- {
- vector<int> p = { 36, -1, 2};
- Polinom * obj = new Polinom(p);
- cout << obj->to_String() << endl;
- cout << obj->get_derivative() << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement