My program should read five integers from a file called sample.txt, then print out the integers, add them, etc. using the overload functions. I seem to be having a problem with my isElement, insert and remove functions, but I'm not a strong coder so I just can't figure this out!! Here is my code, then my 3 errors follow. Any help you can give is appreciated!!
Code:
#include<iostream.h>
#include<fstream.h>
struct Node{
char digit;
Node *next;
};
class BigInt{
Node *Num;
int cap;
int top;
public:
void insert ( int);
void remove (int);
int isEmpty () {return !top;};
int isElement (int);
int size() {return top;};
friend BigInt operator+(BigInt A, BigInt B);
friend BigInt operator-(BigInt A, BigInt B);
friend istream& operator>>(istream& in, BigInt &B);
friend ostream& operator<<(ostream& o, BigInt &B);
};
int BigInt::isElement (int target)
{
for (int i=0; i < top; i++)
if (Num [i] == target) //ERROR 1
return 1;
return 0;
}
void BigInt::insert (int target)
{
if (isElement(target))
return;
if (top == cap) {
Node *temp = new Node [cap + 5];
for (int i=0; i<top; i++) temp [i] = Num->next [i];
cap =+5;
delete []Num->next;
Num->next = temp;
}
Num->next [top++] = Num.target; //ERROR 2
}
void BigInt::remove (int target)
{
char i;
if (! isElement (target))
return;
for (i = 0; i < cap; i ++)
if (Num[i] == target) //ERROR 3
break;
while (i < cap -1){
Num [i] = Num [i+1];
i++;
}
top --;
}
BigInt operator+(BigInt A, BigInt B)
{
A.Num->digit += B.Num->digit;
return A;
}
BigInt operator-(BigInt A, BigInt B)
{
A.Num->digit -= B.Num->digit;
return A;
}
istream& operator>>(istream& in, BigInt &B)
{
in >> B.Num->digit;
return in;
}
ostream& operator<<(ostream& o, BigInt &B)
{
o << B.Num->digit;
return o;
}
void main()
{
BigInt v1, v2, v3, v4, v5;
ifstream in;
in.open("sample.txt");
in >> v1 >> v2 >> v3 >> v4 >> v5;
cout << v1+v2 << endl;
cout << v3-v4 << endl;
}
errors (line location shown in code above):
1. binary '==' : 'struct Node' does not define this operator or a conversion to a type acceptable to the predefined operator
2. left of '.target' must have class/struct/union type
3. binary '==' : 'struct Node' does not define this operator or a conversion to a type acceptable to the predefined operator
Thanks!!