Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Wielomian{
- public:
- Wielomian(){
- wielomian.emplace_back(0);
- }
- Wielomian(std::vector<double> wiel){
- for(auto d : wiel){
- wielomian.emplace_back(d);
- }
- }
- void ustawWspolczynnik(int n, double value){
- if(wielomian.size() < n+1) {
- while (wielomian.size() < n && n != 0) {
- wielomian.emplace_back(0);
- }
- wielomian.emplace_back(value);
- }else{
- wielomian[n] = value;
- }
- }
- double wartosc(double x){
- double result = 0;
- result += wielomian.at(0);
- for(int i=1; i< wielomian.size(); i++){
- result += pow(x,i) * wielomian.at(i);
- }
- return result;
- }
- Wielomian operator+(const Wielomian& other){
- size_t size;
- if(wielomian.size() > other.wielomian.size()){
- size = wielomian.size();
- } else {
- size = other.wielomian.size();
- }
- std::vector<double> res;
- for(int i=0; i< size; i++){
- res.emplace_back(wielomian.at(i) + other.wielomian.at(i));
- }
- Wielomian result(res);
- return result;
- }
- Wielomian operator*(const Wielomian& other){
- size_t size = (wielomian.size())*(other.wielomian.size());
- std::vector<double> res;
- for(int x=0; x<size-1;x++){
- res.emplace_back(0);
- }
- for(int i=0; i<=wielomian.size()-1; i++){
- for(int j=0; j<=other.wielomian.size()-1; j++){
- // std::cout<< i+j <<" - " << wielomian.at(i)*other.wielomian.at(j) << "\n";
- res[i+j] += wielomian.at(i)*other.wielomian.at(j);
- }
- }
- Wielomian result(res);
- return result;
- }
- friend std::ostream& operator<<(std::ostream& out, Wielomian& w);
- friend std::istream& operator>>(std::istream& in, Wielomian& w);
- void wyswietl(){
- for(auto x : wielomian){
- std::cout << x << " ";
- }
- }
- private:
- std::vector<double> wielomian;
- };
- std::ostream& operator<<(std::ostream& out, Wielomian& w){
- for(int i=0; i<w.wielomian.size(); i++){
- out << w.wielomian.at(i) << " ";
- }
- return out;
- }
- std::istream& operator>>(std::istream& in, Wielomian& w){
- // ??????????????????????????/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement