Why won't my class function display in main?

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 #include <list>
#include "Term.h"

using namespace 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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <list>
#include <string>
#include "Term.h"
#include "Polynomial.h"

using namespace 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;
}
Last edited on
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);
Last edited on


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);

Last edited on
Line 26 is giving me this note, which i guess is my problem, how are these not my arguments?

26|note: candidate expects 2 arguments, 0 provided|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 #include <list>
#include "Term.h"

using namespace 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 
Last edited on
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.
Topic archived. No new replies allowed.