Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

main.cpp #include monomio.h int main() { //Declare objects class Monomio m_01, m_02, m_03; cout < < Welcome to the monomial C++ Program! ; cout <

main.cpp #include "monomio.h"

int main() {

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

cout << "Welcome to the monomial C++ Program! "; cout << "I will sum two monomials in the following format [ax^(n)] "; cout << " Enter the first monomial: "; cin >> m_01;

cout << " Enter the second monomial: "; cin >> m_02; cout << " Monomial #01 entered: " << m_01<< endl; cout << "Monomial #02 entered: " << m_02<< endl;

//Sum of monomials m_03 = m_01 + m_02; cout << " The sum of: " << m_01 << " + " << m_02 << " = " << m_03 << endl;

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 << "Destroying objects created... "; }

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 << "Error, exponent must be the same!!!" << endl; exit(1); } }

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 << "Error, exponent must be the same!!!" << endl; exit(1); }

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 <<(ostream & out, const Monomio& tempMonomio) { out << tempMonomio.getCoeficient() << "x^"<< tempMonomio.getExponent(); return out; } istream & operator >> (istream & in, Monomio & tempMonomio) { cout << "Enter the value for the coeficient (a): "; in >> tempMonomio.coeficiente; cout << "Enter the value for the exponent (b): "; in >> 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 << (ostream &, const Monomio &);

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

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

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

Recommended Textbook for

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions

Question

=+ What is the role of government in bargaining?

Answered: 1 week ago

Question

=+ Who is the negotiation partner at company level?

Answered: 1 week ago