question archive You just need to change the logic for the code but keep in mind that its working remain same but you can change some formatting of the output
Subject:Computer SciencePrice: Bought3
You just need to change the logic for the code but keep in mind that its working remain same but you can change some formatting of the output .
QUESTION:
I am placing a code . that code is done using C++ in object oriented programming . I want the code to be changed in its logic. Mean that you need to change the logic of the program so that your provided code becomes different that my provided code. But the working should be same as my provided program .You can do some changings in the output format as well .
SOURCE CODE:
#include <iostream>
#include<conio.h>
#include<string>
#include<math.h>
using namespace std;
class HugeInteger
{
private:
short integer[40];
public:
HugeInteger(long = 0);
HugeInteger add(const HugeInteger&);
HugeInteger subtract(const HugeInteger&);
bool isEqualTo(HugeInteger&);
bool isNotEqualTo(HugeInteger&);
bool isGreaterThan(HugeInteger&);
bool isLessThan(HugeInteger&);
bool isGreaterThanOrEqualTo(HugeInteger&);
bool isLessThanOrEqualTo(HugeInteger&);
bool isZero();
void output();
short* getInteger()
{
return integer;
}
};
HugeInteger::HugeInteger(long value)
{
for (int i = 0; i < 40; i++)
integer[i] = 0;
for (int j = 39; value != 0 && j >= 0; j--)
{
integer[j] = value % 10;
value /= 10;
}
}
HugeInteger HugeInteger::add(const HugeInteger& op2)
{
HugeInteger temp;
int carry = 0;
for (int i = 39; i >= 0; i--) {
temp.integer[i] = integer[i] + op2.integer[i] + carry;
if (temp.integer[i] > 9)
{
temp.integer[i] %= 10;
carry = 1;
}
else
carry = 0;
}
return temp;
}
void HugeInteger::output()
{
int i;
for (i = 0; (integer[i] == 0) && (i <= 39); i++)
;
if (i == 40)
cout << 0;
else
for (; i <= 39; i++)
cout << integer[i];
}
HugeInteger HugeInteger::subtract(const HugeInteger& op2)
{
HugeInteger temp;
int borrow = 0;
for (int i = 39; i >= 0; i--)
{
if (integer[i] < op2.integer[i])
{
temp.integer[i] = (integer[i] + 10) - op2.integer[i] - borrow;
borrow = 1;
}
else
{
temp.integer[i] = integer[i] - op2.integer[i] - borrow;
borrow = 0;
}
}
return temp;
}
bool HugeInteger::isEqualTo(HugeInteger& x)
{
return integer == x.getInteger();
}
bool HugeInteger::isNotEqualTo(HugeInteger& x)
{
return !(this->isEqualTo(x));
}
bool HugeInteger::isGreaterThan(HugeInteger& x)
{
return integer < x.getInteger();
}
bool HugeInteger::isLessThan(HugeInteger& x)
{
return integer > x.getInteger();
}
bool HugeInteger::isGreaterThanOrEqualTo(HugeInteger& x)
{
return integer <= x.getInteger();
}
bool HugeInteger::isLessThanOrEqualTo(HugeInteger& x)
{
return integer >= x.getInteger();
}
bool HugeInteger::isZero()
{
return (getInteger() == 0);
}
int main()
{
HugeInteger n1(7654321);
HugeInteger n2(7891234);
HugeInteger n3;
HugeInteger n4(5);
HugeInteger n5;
n5 = n1.add(n2);
n1.output();
cout << " + "; n2.output();
cout << " = "; n5.output();
cout << "nn";
n5 = n2.subtract(n4);
n2.output();
cout << " - "; n4.output();
cout << " = "; n5.output();
cout << "nn";
if (n1.isEqualTo(n1) == true)
{
n1.output(); cout << " is equal "; n1.output(); cout << "nn";
}
if (n1.isNotEqualTo(n2) == true)
{
n1.output(); cout << " is not equal to "; n2.output(); cout << "nn";
}
if (n2.isGreaterThan(n1) == true)
{
n2.output(); cout << " is greater than "; n1.output(); cout << "nn";
}
if (n2.isLessThan(n4) == true)
{
n4.output(); cout << " is less than "; n2.output(); cout << "nn";
}
if (n4.isLessThanOrEqualTo(n4) == true)
{
n4.output(); cout << " is less than or equal to "; n4.output();
cout << "nn";
}
if (n3.isGreaterThanOrEqualTo(n3) == true)
{
n3.output(); cout << " is greater than or equal to "; n3.output();
cout << "nn";
}
if (n3.isZero() != true)
{
cout << "n3 contains value "; n3.output(); cout << "nn";
}
return 0;
}