I'll post the error codes as well.
Test2 error LNK2019: unresolved external symbol "public: int __thiscall Poly::Coefficient(int)" ([email protected]@@[email protected]) referenced in function _main Test2 error LNK2019: unresolved external symbol "public: void __thiscall Poly::changeCoefficient(int,int)" ([email protected]@@[email protected]) referenced in function _main Test2 fatal error LNK1120: 2 unresolved externals
"Poly.h"
class Poly
{
public:
int degree();
int Coefficient(int);
void changeCoefficient(int, int);
};
"Poly.cpp"
#include <iostream>
#include "Poly.h"
using namespace std;
struct polynomial //contains power and coefficient of term
{
int power;
int coefficient;
}
polynomial x1, x2 ,x3;
Poly::Poly()
{
x1.power = 1;
x1.coefficient = 1;
x2.power = 2;
x2.coefficient = 2;
x3.power = 3;
x3.coefficient = 3;
}
int Poly::degree() // returns the degree of the polynomial
{
return (x1.power + x2.power + x3.power);
}
int Poly::Coefficient(int index) //returns the coefficient of a term
{
if(x1.power == index)
return x1.coefficient;
else if(x2.power == index)
return x2.coefficient;
else if(x3.power == index)
return x3.coefficient;
else
cout << "This variable does not exist. Returning zero by default.";
return 0;
}
void Poly::changeCoefficient(int index, int newCoefficient) //changes the coefficient of a term
{
if(x1.power == index)
x1.coefficient = newCoefficient;
else if(x2.power == index)
x2.coefficient = newCoefficient;
else if(x3.power == index)
x3.coefficient = newCoefficient;
else
cout << "This variable does not exist. Unable to replace value.";
}
"main.cpp"
#include <iostream>
#include "Poly.h"
using namespace std;
int main()
{
Poly pol;
int index, newCoefficient;
char answer;
do{
cout << "Enter a power of a variable to see it's coefficient: ";
cin >> index;
cout << pol.Coefficient(index) << endl;
cout << "Enter a power of a variable to change it's coefficient: ";
cin >> index;
cout << endl << "Enter the new coefficient desired: ";
cin >> newCoefficient;
pol.changeCoefficient(index, newCoefficient);
cout << "Do you want to loop this program?" << endl;
cin >> answer;
}while(answer == 'y');
system("PAUSE");
return 0;
}
This post has been edited by falconheart: 19 May 2007 - 03:25 PM

New Topic/Question
Reply



MultiQuote




|