I am having problems with my big class I am getting the error that there is no m
ID: 3651671 • Letter: I
Question
I am having problems with my big class I am getting the error that there is no mach for operator- in many of my lines for my big operator+ and operator- functions. I can't seem to find what i need to do to fix these so i can move on with my program. I am assuming that my errors are coming from how I am referencing them or issues in other functions, but I am unsure.header file:
#include<iostream>
using namespace std;
class big
{
private:
int *array;
int sign; // 1 or -1
public:
big();
big(int other);
big(big& other);
big(const char a[20], int s);
friend big operator+ (const big& lhs, const big& rhs);
friend big operator- (const big& lhs, const big& rhs);
/*friend big operator* (const big& lhs, const big& rhs);
friend big operator/ (const big& lhs, const big& rhs);
friend big operator% (const big& lhs, const big& rhs);
*/
friend int operator== (const big& lhs, const big& rhs);
friend int operator!= (const big& lhs, const big& rhs);
friend int operator<= (const big& lhs, const big& rhs);
friend int operator>= (const big& lhs, const big& rhs);
friend int operator< (const big& lhs, const big& rhs);
friend int operator> (const big& lhs, const big& rhs);
friend istream& operator>> (istream& lhs, big& rhs);
friend ostream& operator<< (ostream& lhs, const big& rhs);
big operator++(int); // post
big operator--(int); // post
/*
big& operator++();
big& operator--();
*/};
big.cpp
#include "big.h"
#define SIZE 20
// initalize the array to 0
big::big()
{
int i;
array = new int[20];
sign = 1;
for(i = 0; i < 20; i++)
array[i] = 0;
}
// check to see if positive or negative
big::big(int other)
{
int i;
array = new int[20];
bool end = false;
for(i = 0; i < 20; i++)
{
while(array[i] > 9)
{
array[i] -= 10;
array[i + 1]++;
}
if(array[i] <= 9)
{
end = true;
}
}
if(other >= 0)
sign = 1;
else
sign = -1;
}
big::big(big& other)
{
int i;
array = new int[20];
for(i = 0; i < 20; i++)
{
array[i] = other.array[i];
}
sign = other.sign;
}
big::big(const char a[20], int s)
{
int i;
for(i = 0; i < SIZE; i ++)
{
array[i] = a[i];
}
sign = s;
}
istream& operator>>(istream& lhs, big& rhs)
{
char ival;
int count;
char holder[SIZE];
int done;
int i;
int spot;
lhs >> ival;
if(ival == '+')
{
rhs.sign = -1;
lhs >> ival;
}
if(ival == '-')
{
rhs.sign = -1;
lhs >> ival;
}
count = 0;
done = 0;
while(done == 0)
{
holder[count] = ival - '0';
count++;
lhs.get(ival);
if((ival < '0') || (ival > '9'))
{
done = 1;
}
if(count == SIZE) done = 1;
}
spot = 0;
for(i = count - 1; i >= 0; i--)
{
rhs.array[spot] = holder[i];
spot++;
}
return lhs;
}
ostream& operator<<(ostream& lhs, const big& rhs)
{
int i;
if(rhs.sign < 0)
{
cout << "-";
}
else
cout << "+";
for(i = 19; i >= 0; i--)
{
lhs << rhs.array[i];
}
return lhs;
}
big operator+(const big& lhs, const big& rhs)
{
big newbie;
int i, carry;
if((lhs < 0) && (rhs >= 0))
{
newbie = operator-(rhs, -lhs);
}
if((rhs < 0) && (lhs >= 0))
{
newbie = operator-(lhs, -rhs);
}
if((rhs < 0) && (lhs < 0))
{
newbie = operator+(-lhs, -rhs);
}
if((rhs >= 0) && (lhs >= 0))
{
carry = 0;
for(i = 0; i < SIZE; i++)
{
newbie.array[i] = lhs.array[i] + rhs.array[i] + carry;
if(newbie.array[i] > 9)
{
newbie.array[i] -= 10;
carry = 1;
}
else carry = 0;
}
}
return newbie;
}
big operator-(const big& lhs, const big& rhs)
{
big newbie;
int i, carry;
if((lhs < 0) && (rhs >= 0))
{
newbie = operator-(lhs, rhs);
}
if((rhs < 0) && (lhs >= 0))
{
newbie = operator+(lhs, -rhs);
}
if((rhs < 0) && (lhs < 0))
{
newbie = operator-(-lhs, -rhs);
}
if(lhs < rhs)
{
newbie = operator-(rhs, lhs);
}
if((rhs >= 0) && (lhs >= 0))
{
carry = 0;
for(i = 0; i < SIZE; i++)
{
newbie.array[i] = lhs.array[i] + rhs.array[i] + carry;
if(newbie.array[i] > 9)
{
newbie.array[i] -= 10;
carry = 1;
}
else carry = 0;
}
}
return newbie;
}
int operator==(const big& lhs, const big& rhs)
{
int i;
if(lhs.sign != rhs.sign)
return 1;
for(i = 19; i >= 0; i--)
{
if(lhs.array[i] != rhs.array[i])
{
return 1;
}
}
return 0;
}
int operator!=(const big& lhs, const big& rhs)
{
return ~(lhs == rhs);
}
int operator<(const big& lhs, const big& rhs)
{
int i;
if(lhs.sign > 0 && rhs.sign < 0)
{
return (lhs > rhs);
}
for(i = 19; i >= 0; i--)
{
if((lhs.array[i] < rhs.array[i]) || (lhs.sign < rhs.sign))
{
return 1;
}
}
return 0;
}
int operator>(const big& lhs, const big& rhs)
{
int i;
for(i = 19; i >= 0; i--)
{
if((lhs.array[i] > rhs.array[i]) || (lhs.sign > rhs.sign))
{
return 1;
}
}
return 0;
}
int operator<=(const big& lhs, const big& rhs)
{
return (lhs == rhs) || (lhs < rhs);
}
int operator>=(const big& lhs, const big& rhs)
{
return (lhs == rhs) || (lhs > rhs);
}
/*
big operator++(int)
{
}
big operator--(int)
{
}
*/
test1.cpp
#include "big.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
big a;
big b;
big c;
cout << "Enter 1st number: ";
cin >> a;
cout << "Enter 2nd number: ";
cin >> b;
Explanation / Answer
header file: #ifndef BIG_H #define BIG_H #includeusing namespace std; class big { private: int *array; int sign; // 1 or -1 public: big(); big(int other); big(big& other); big(const char a[20], int s); //friend big operator+ (const big& lhs, const big& rhs); friend big operator- (const big& lhs, const big& rhs); /*friend big operator* (const big& lhs, const big& rhs); friend big operator/ (const big& lhs, const big& rhs); friend big operator% (const big& lhs, const big& rhs); */ friend big operator + (const big& lhs, const big& rhs); friend int operator== (const big& lhs, const big& rhs); friend int operator!= (const big& lhs, const big& rhs); friend int operator= (const big& lhs, const big& rhs); friend int operator< (const big& lhs, const big& rhs); friend int operator> (const big& lhs, const big& rhs); friend istream& operator>> (istream& lhs, big& rhs); friend ostream& operator 9) { array[i] -= 10; array[i + 1]++; } if(array[i] = 0) sign = 1; else sign = -1; } big::big(big& other) { int i; array = new int[20]; for(i = 0; i < 20; i++) { array[i] = other.array[i]; } sign = other.sign; } big::big(const char a[20], int s) { int i; for(i = 0; i > (istream& lhs, big& rhs) { char ival; int count; char holder[SIZE]; int done; int i; int spot; lhs >> ival; if(ival == '+') { rhs.sign = -1; lhs >> ival; } if(ival == '-') { rhs.sign = -1; lhs >> ival; } count = 0; done = 0; while(done == 0) { holder[count] = ival - '0'; count++; lhs.get(ival); if((ival < '0') || (ival > '9')) { done = 1; } if(count == SIZE) done = 1; } spot = 0; for(i = count - 1; i >= 0; i--) { rhs.array[spot] = holder[i]; spot++; } return lhs; } ostream& operator= 0)) { carry = 0; for(i = 0; i 9) { newbie.array[i] -= 10; carry = 1; } else carry = 0; } } return newbie; } big operator-(const big& lhs, const big& rhs) { big newbie; int i, carry; if((lhs < 0) && (rhs >= 0)) { newbie = operator-(lhs, rhs); } if((rhs < 0) && (lhs >= 0)) { newbie = operator+(lhs, 0-rhs); } if((rhs < 0) && (lhs < 0)) { newbie = operator-(0-lhs, 0-rhs); } if(lhs = 0) && (lhs >= 0)) { carry = 0; for(i=0; i 9) { newbie.array[i] -= 10; carry = 1; } else carry = 0; } } return newbie; } int operator==(const big& lhs, const big& rhs) { int i; if(lhs.sign != rhs.sign) return 1; for(i = 19; i >= 0; i--) { if(lhs.array[i] != rhs.array[i]) { return 1; } } return 0; } int operator!=(const big& lhs, const big& rhs) { return ~(lhs == rhs); } int operator 0 && rhs.sign < 0) { return (lhs > rhs); } for(i = 19; i >= 0; i--) { if((lhs.array[i] = 0; i--) { if((lhs.array[i] > rhs.array[i]) || (lhs.sign > rhs.sign)) { return 1; } } return 0; } int operator rhs); } /* big operator++(int) { } big operator--(int) { } */ #include "big.h" #include #include #include using namespace std; int main() { big a; big b; big c; cout > a; cout > b; errors removed that you mentioned so please rate meRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.