c++
#ifndef POLYNOMIAL_H_
#define POLYNOMIAL_H_
#include <iostream>
#include <math.h> // fabs, pow
#include "vector_t.h"
#include "sparse_vector_t.h"
// Clase para polinomios basados en vectores densos de doubles
class Polynomial : public vector_t<double> {
public:
// constructores
Polynomial(const int n = 0) : vector_t<double>(n) {};
Polynomial(const Polynomial& pol)
: vector_t<double>(pol) {}; // constructor de copia
// destructor
~Polynomial() {};
// E/S
void Write(std::ostream& = std::cout, const double eps = EPS) const;
// operaciones
double Eval(const double) const;
bool IsEqual(const Polynomial&, const double = EPS) const;
};
// Clase para polinomios basados en vectores dispersos
class SparsePolynomial : public sparse_vector_t {
public:
// constructores
SparsePolynomial(const int n = 0) : sparse_vector_t(n) {};
SparsePolynomial(const Polynomial& pol) : sparse_vector_t(pol) {};
SparsePolynomial(const SparsePolynomial&); // constructor de copia
// destructor
~SparsePolynomial() {};
// E/S
void Write(std::ostream& = std::cout) const;
// operaciones
double Eval(const double) const;
bool IsEqual(const SparsePolynomial&, const double = EPS) const;
bool IsEqual(const Polynomial&, const double = EPS) const;
};
// E/S
void Polynomial::Write(std::ostream& os, const double eps) const {
os << get_size() << ": [ ";
bool first{true};
for (int i{0}; i < get_size(); i++)
if (IsNotZero(at(i), eps)) {
os << (!first ? " + " : "") << at(i)
<< (i > 1 ? " x^" : (i == 1) ? " x" : "");
if (i > 1)
os << i;
first = false;
}
os << " ]" << std::endl;
}
std::ostream& operator<<(std::ostream& os, const Polynomial& p) {
p.Write(os);
return os;
}
// Operaciones con polinomios
// Evaluación de un polinomio representado por vector denso
double Polynomial::Eval(const double x) const {
double result{0.0};
// poner el código aquí
return result;
}
// Comparación si son iguales dos polinomios representados por vectores densos
bool Polynomial::IsEqual(const Polynomial& pol, const double eps) const {
bool differents = false;
// poner el código aquí
return !differents;
}
// constructor de copia
SparsePolynomial::SparsePolynomial(const SparsePolynomial& spol) {
*this = spol; // se invoca directamente al operator=
}
// E/S
void SparsePolynomial::Write(std::ostream& os) const {
os << get_n() << "(" << get_nz() << "): [ ";
bool first{true};
for (int i{0}; i < get_nz(); i++) {
int inx{at(i).get_inx()};
os << (!first ? " + " : "") << at(i).get_val()
<< (inx > 1 ? " x^" : (inx == 1) ? " x" : "");
if (inx > 1)
os << inx;
first = false;
}
os << " ]" << std::endl;
}
std::ostream& operator<<(std::ostream& os, const SparsePolynomial& p) {
p.Write(os);
return os;
}
// Operaciones con polinomios
// Evaluación de un polinomio representado por vector disperso
double SparsePolynomial::Eval(const double x) const {
double result{0.0};
// poner el código aquí
return result;
}
// Comparación si son iguales dos polinomios representados por vectores dispersos
bool SparsePolynomial::IsEqual(const SparsePolynomial& spol
, const double eps) const {
bool differents = false;
// poner el código aquí
return !differents;
}
// Comparación si son iguales dos polinomios representados por
// vector disperso y vector denso
bool SparsePolynomial::IsEqual(const Polynomial& pol, const double eps) const {
bool differents = false;
// poner el código aquí
return !differents;
}
#endif // POLYNOMIAL_H_
4
8
Better than my grades
Thank you!
8
0
3.9
10
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
Thank you!
10
0
4
1
C++ is a general-purpose programming language created by Bjarne
Stroustrup as an extension of the C programming language, or
"C with Classes".
//as you can also see to your right ---------------------->
C++ still qualifies as a high-level languge, yet the rise of
languages like Ruby and Java have given capabilities that sway
people's opinion towards what is and is not "high-level".
Yet high-level simply means it's farther from machine code and closer
to human-readable form. Hence the need for a compiler/interpreter.
So don't get too worked up about granular specifics.
Thank you!
1
0
3.25
4
C++ is SHEEEEEEEEEEESH
Thank you!
4
0
0
8
God's language
Thank you!
8
0
4
8
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
}
Thank you!
8
0
3.6
5
C++ is a high-level, general-purpose programming language.
//totally not right there ----------------------------------->
Thank you!
5
0
4.14
7
C++ is a general-purpose programming language created by Bjarne Stroustrup
Thank you!
7
0
4
4
#include <bits/stdc++.h>
using namespace std;
int main() {
return 0;
}
Thank you!
4
0
Are there any code examples left?
New code examples in category Other