My function won't display in main and i'm not sure why?
This is due at 11:59, professor won't answer so i'm kinda panicking, i'd really appreciate help. I'm trying to just get this to provide user input then multiply. But i just wanted to see the function display before continuing so i'm unsure how to fix it.
#include <list>
#include "Term.h"
usingnamespace std;
#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H
class Polynomial : public Term
{
public:
Polynomial();
~Polynomial();
// function to build a polynomial
list <Term> myList;
list <Term>::iterator(it);
int answer;
float coefficient;
int power;
int AddNewTerm(float coefficient, int power)
{
cout << "Enter polynomial terms" << endl << endl;
do {
// create a polynomial
Term *newTerm = new Term();
// get and set values
cout << "Enter coefficient: " << endl;
cin >> coefficient;
cout << "Enter power: " << endl;
cin >> power;
newTerm->Setcoefficient(coefficient);
newTerm->Setpower(power);
cout << newTerm->Getcoefficient();
cout << newTerm->Getpower();
// find location for new term
poly.insert(it, *newTerm);
// insert the term object into the list.
cout << "Enter more terms (y/n)?";
cin >> answer;
} while ((answer == 'y') || (answer == 'Y'));
}
private:
list <Term> poly; // the list stores the attributes from Term class
// and poly represents the copy n paste shell for
// ex poly1, poly2, etc.. and in "poly" it asks for
// the coefficient and power.
};
#endif // POLYNOMIAL_H
#include <iostream>
#include <list>
#include <string>
#include "Term.h"
#include "Polynomial.h"
usingnamespace std;
int main()
{
list <Term> myList;
list<Term>::iterator(it);
// create a term variable
Term poly1;
// bring in create a poly function
void AddNewTerm();
//
return 0;
}
Line 22 in your second source is a standalone function prototype in main, it has nothing to with your class.
You aren't calling the class member function on your instance of Term. You need to do something like poly1.AddNewTerm(some values, two since that is the number of parameters);
Line 22 in your second source is a standalone function prototype in main, it has nothing to with your class.
You aren't calling the class member function on your instance of Term. You need to do something like
poly1.AddNewTerm(some values, two since that is the number of parameters);
Okay makes sense, so I added Polynomial poly1 to main, and that command. Why am I getting the error expected primary expression before float & int tho? Line 10
1 2 3 4 5 6 7 8 9 10
int main()
{
list <Term> myList;
list<Term>::iterator(it);
Polynomial poly1;
poly1.AddNewTerm(float coefficient, int power);
#include <list>
#include "Term.h"
usingnamespace std;
#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H
class Polynomial : public Term
{
public:
Polynomial();
~Polynomial();
// function to build a polynomial
list <Term> myList;
list <Term>::iterator(it);
int answer;
float coefficient;
int power;
int AddNewTerm(float coefficient, int power)
{
cout << "Enter polynomial terms" << endl << endl;
do {
// create a polynomial
Term *newTerm = new Term();
// get and set values
cout << "Enter coefficient: " << endl;
cin >> coefficient;
cout << "Enter power: " << endl;
cin >> power;
newTerm->Setcoefficient(coefficient);
newTerm->Setpower(power);
cout << newTerm->Getcoefficient();
cout << newTerm->Getpower();
// find location for new term
poly.insert(it, *newTerm);
// insert the term object into the list.
cout << "Enter more terms (y/n)?";
cin >> answer;
} while ((answer == 'y') || (answer == 'Y'));
}
private:
list <Term> poly; // the list stores the attributes from Term class
// and poly represents the copy n paste shell for
// ex poly1, poly2, etc.. and in "poly" it asks for
// the coefficient and power.
};
#endif // POLYNOMIAL_H
You are still trying to declare a function prototype in main. Not gonna work.
In main poly1.AddNewTerm(float coefficient, int power); should probably be poly1.AddNewTerm(coefficient, power); with coefficient and power previously initialized as a double and int respectively.
Or just use actual values in your member function call. For example poly1.AddNewTerm(2.76, 2);
There are probably more problems lurking in your code, but what they are it is nigh um-possible to say. You've kept parts of your code hidden. Your Term class, for instance.