Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the class Monomio as class part. Make a class all called Polinomio where you will have an array of private objects Monomial an integer

Using the class Monomio as class part. Make a class all called Polinomio where you will have an array of private objects Monomial an integer type and handle the totoal of monomials in the form:

ax^n + bx + c

The program must be able to evaluate for F (x). Do operator overloading of cin / cout.

Output:

Monomial # 1:

Enter coefcient "a": 1

Enter exponent "n": 2

Monomial #2:

Enter coefcient "a": 5

Enter exponent "n": 1

Monomial #3:

Enter coefcient "a": 6

Enter exponent "n": 0

Equation F(x) = x^2 + 5x + 6

Enter x: 2

F(2) = 20

main.cpp #include "monomio.h"

int main() {

//Declare objects class Monomio m_01, m_02, m_03;

cout > m_01;

cout > m_02; cout

//Sum of monomials m_03 = m_01 + m_02; cout

return 0; }

Monomio.cpp

#include "monomio.h" using namespace::std;

Monomio::Monomio() {

setCoeficient(1); setExponent(2);

}

Monomio::Monomio(int tempCoeficient, int tempExponent) {

setCoeficient(tempCoeficient); setExponent(tempExponent);

}

Monomio::Monomio(const Monomio & tempMonomio) { this->coeficiente = tempMonomio.coeficiente; this->exponente = tempMonomio.exponente; }

Monomio::~Monomio() { //cout

void Monomio::setCoeficient(int a) { this->coeficiente = a; }

void Monomio::setExponent(int n) {

this->exponente = n; }

int Monomio::getCoeficient() const { return this->coeficiente; }

int Monomio::getExponent() const { return this->exponente; }

Monomio Monomio::operator+(const Monomio & tempMonomio) { if (this->exponente == tempMonomio.getExponent()) { Monomio monomio; monomio.setCoeficient(this->coeficiente + tempMonomio.getCoeficient()); monomio.setExponent(this->exponente); return monomio; } else { cerr

Monomio Monomio::operator-(const Monomio & tempMonomio) { if (this->exponente == tempMonomio.getExponent()) { Monomio monomio; monomio.setCoeficient(this->coeficiente - tempMonomio.getCoeficient()); monomio.setExponent(this->exponente);

return monomio; } else cerr

Monomio Monomio::operator*(const Monomio & tempMonomio) { Monomio monomio; monomio.setCoeficient(this->coeficiente * tempMonomio.getCoeficient()); monomio.setExponent(this->exponente + tempMonomio.getExponent());

return monomio; }

Monomio & Monomio::operator=(const Monomio & tempMonomio) {

this->coeficiente = tempMonomio.getCoeficient(); this->exponente = tempMonomio.getExponent();

return (*this); }

//istream & ostream... ostream & operator > (istream & in, Monomio & tempMonomio) { cout > tempMonomio.coeficiente; cout > tempMonomio.exponente; return in; }

Monomio.h

#pragma once #ifndef MONOMIO_H #define MONOMIO_H #include using namespace::std;

class Monomio { friend istream & operator >> (istream & in, Monomio &); friend ostream & operator

private: int coeficiente, exponente, monomio, variable; public: Monomio(); //default constructor Monomio(int, int); //constructor with parameters Monomio(const Monomio &); //copy constructor ~Monomio();

//setters void setCoeficient(int); void setExponent(int);

//void setVariable(int);

//getters int getCoeficient() const; int getExponent() const;

//operators Monomio operator+ (const Monomio & tempMonomio); Monomio operator- (const Monomio & tempMonomio); Monomio operator* (const Monomio & tempMonomio); Monomio & operator= (const Monomio & tempMonomio);

};

#endif // !MONOMIO_H

image text in transcribed

NOW NEED THE NEXT

sh-4.2$ g std c++11 -o main *.cpp sh-4.2$ main Welcome to the monomial C++ Program I will sum two monomials in the following format [ax (n) j Enter the first monomial: Enter the value for the coeficient (a) 2 Enter the value for the exponent (b) 3 Enter the second monomial Enter the value for the coeficient (a) 5 Enter the value for the exponent (b) 3 Monomial 101 entered 2x13 Monomial 102 entered. 5xa3 The sum of: 2x 3 5x 3 7x 3 sh-4.2$ sh-4.2$ g std c++11 -o main *.cpp sh-4.2$ main Welcome to the monomial C++ Program I will sum two monomials in the following format [ax (n) j Enter the first monomial: Enter the value for the coeficient (a) 2 Enter the value for the exponent (b) 3 Enter the second monomial Enter the value for the coeficient (a) 5 Enter the value for the exponent (b) 3 Monomial 101 entered 2x13 Monomial 102 entered. 5xa3 The sum of: 2x 3 5x 3 7x 3 sh-4.2$

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. How do rituals and routines express organizational values?

Answered: 1 week ago

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago