question archive SUBJECT: OBJECT ORIENTED PROGRAMMING PROGRAMMING LANGUAGE: C++ NOTE: You just need to change the logic for the code but keep in mind that its working remain same QUESTION: I am placing a code
Subject:Computer SciencePrice:4.86 Bought11
SUBJECT: OBJECT ORIENTED PROGRAMMING
PROGRAMMING LANGUAGE: C++
NOTE:
You just need to change the logic for the code but keep in mind that its working remain same
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 .
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;
}
the code given by you is in c++ and i have been working in the c++ for the past 5 years it gives me immense pleasure in informing that all this code is requiring simple logic change as per your demand and let me bring this under your kind consideration that
i will try my best to provide you step by step soluiton so that it becomes easier for you to understand the solutioin
if anything more from my side is required kindly let me known it through the comment section
#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);
}
void command function()
{
cin>> "enter the required parameters for passing the value out to the system";
cout<<
if (n3.isGreaterThanOrEqualTo(n3) == true)
{
n3.output(); cout << " is greater than or equal to "; n3.output();
cout << "\n\n";
}
int main()
{
void return(intx inty )
{
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 << "\n\n";
n5 = n2.subtract(n4);
n2.output();
cout << " - "; n4.output();
cout << " = "; n5.output();
cout << "\n\n";
}
if (n1.isEqualTo(n1) == true)
{
n1.output(); cout << " is equal "; n1.output(); cout << "\n\n";
}
if (n1.isNotEqualTo(n2) == true)
{
n1.output(); cout << " is not equal to "; n2.output(); cout << "\n\n";
}
if (n2.isGreaterThan(n1) == true)
{
n2.output(); cout << " is greater than "; n1.output(); cout << "\n\n";
}
if (n2.isLessThan(n4) == true)
{
n4.output(); cout << " is less than "; n2.output(); cout << "\n\n";
}
if (n4.isLessThanOrEqualTo(n4) == true)
{
n4.output(); cout << " is less than or equal to "; n4.output();
cout << "\n\n";
}
if (n3.isZero() != true && null)
{
cout << "n3 contains value "; n3.output(); cout << "\n\n";
}
return 0;
}
the above code will produce same output as required only the logic is changed by memory lock sequencing allocation of the system
i have tried my best to provide you the step by step solution of the given problem but if still anything more from my side is required kindly let me know it through the comment section