How do i fix this error? I understand it needs a function before the command but i'm not doing this in my int main(), so what else can go before. LINE 26
include\Polynomial.h|27|error: expected unqualified-id before 'do'|
include\Polynomial.h|45|error: expected unqualified-id before 'while'|
#include <string>
#include <iostream>
#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 request;
do {
// create a term object
Term *terms = new Term();
// prompt the user for coefficient and power values and set them into the term object
// use an iterator to add the term object to the list...push_front
// insert the term object into the list
} while (()
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
So I have used do.. while in my int main() functions but what type of function would I add to this class? It has a purpose of adding a terms to the Term class. By that I mean I can add, remove or multiply polynomials.
include\Polynomial.h|46|error: expected unqualified-id before 'while'|
What you appear to be doing here is declaring the class Polynomial in a header file, your .h file. You'll need another file (in your case something like Polynomial.cpp) which will contain any definitions of the declarations you've made in the .h header file. What you're trying to do in your code is writing executable code outside of a function definition.
Inside your Polynomial .h, declare a public function <return-Type> AddNewTerm(<parameters>), for example. You'll have to figure out the return-Type and parameters. Put your do-while code in the function's definition contained in the .cpp.
Suggest you research how to compile a C++ program and the use of the #include preprocessor directive before you go much further with the development of your class.
In one of your previous posts you said.... Theres the answer your looking for
I've gotten this far, but now i'm confused on what to do next. Do I write more in the Get and Set functions? and then for the multiplying do poly3 = poly1 * poly2 ?
Thanks! I think I kind of got the hang of it, i tried putting the function into my main to see if it'd prompt the user correctly and for some reason the function does nothing, can someone explain why?
#include <string>
#include <iostream>
#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;
void AddNewTerm()
{
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(m_coefficient);
newTerm->Setpower(m_power);
// 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