/I'm having trouble creating a constructor for degree and *coeffs as well as properly creating the dynamic arrays for the coefficients of the 2 polynomials a and b. I'm just concerned about getting the correct values.
My textbook only gives us eamples of constructos for eamples not well related to my HW question.Due tonight! any help would be much appreciated./
#include <iostream>
#include <cstdlib>
using namespace std;
struct Polynomial
{
int degree;
int *coeffs;
Polynomial();
};
Polynomial* readPoly1();
Polynomial* readPoly2();
void outputPoly(Polynomial* p,char x);
Polynomial* addPoly(Polynomial* a,Polynomial* b);
Polynomial* multPoly(Polynomial* a,Polynomial* b);
void deletePoly(Polynomial* &p);
int main()
{
Polynomial *a;
Polynomial *b;
a = readPoly1();
b = readPoly2();
if(a.coeffs == NULL || b.coeffs == NULL)
{
cout << "Error: Insuficient memory...exiting program..\n";
exit(1);
}
}
Polynomial::Polynomial()
{
a.degree = 0;
b.degree = 0;
a.coeffs = 0;
b.coeffs = 0;
}
Polynomial* readPoly1()
{
int deg1;
int* coefficients1;
coefficients1 = new int[deg1+1];
/*------------------------Read in first polynomial--------------------*/
cout << "Enter degree of first polynomial:";
cin >> deg1;
cout << "Enter the coefficients of first polynomial starting with "
<< "the lowest degree term and ending with the highest degree term:";
for(int i =0;i<deg1+1;i++)
{
cin >> coefficients1[i]
}
/*---------------------------------------------------------------------*/
a = new Polynomial;
a -> degree = deg1;
a -> coeffs = coefficients1;
return a;
}
Polynomial* readPoly2()
{
int deg2;
int* coefficients2;
coefficients2 = new int[deg2+1];
/*------------------------Read in second polynomial--------------------*/
cout << "Enter degree of second polynomial:";
cin >> deg2;
cout << "Enter the coefficients of second polynomial starting with "
<< "the lowest degree term and ending with the highest degree term:";
for(int i =0;i<deg2+1;i++)
{
cin >> coefficients2[i];
}
/*----------------------------------------------------------------------*/
b = new Polynomial;
b -> degree = deg2;
b -> coeffs = coefficients2;
return b;
}
/*
//Here is my error list
C:\MinGW\bin\g++ -pedantic -Wall -Wextra A7.cpp -o A7.exe
A7.cpp: In functionint main()': A7.cpp:24: error: request for member
coeffs' ina', which is of non-class type
Polynomial'
A7.cpp:24: error: request for membercoeffs' in
b', which is of non-class typePolynomial*' A7.cpp: In constructor
Polynomial::Polynomial()':
A7.cpp:34: error:a' was not declared in this scope A7.cpp:35: error:
b' was not declared in this scope
A7.cpp: In functionPolynomial* readPoly1()': A7.cpp:53: error: expected
;' before '}' token
A7.cpp:55: error:a' was not declared in this scope A7.cpp: In function
Polynomial readPoly2()':
A7.cpp:75: error: `b' was not declared in this scope
Exit code: 1
*/