Question: Need help to write code for largenum.cpp // default constructor from string LargeNum::LargeNum(const string &str) { // TODO } // constructor from int LargeNum::LargeNum(int anInteger)
Need help to write code for largenum.cpp 
// default constructor from string
LargeNum::LargeNum(const string &str) {
// TODO
}
// constructor from int
LargeNum::LargeNum(int anInteger) {
// TODO
}
// returns true if the number is zero
bool LargeNum::isZero() const {
// TODO
}
// negate the number, positive becomes negative, negative becomes positive
// Zero is always positive
LargeNum &LargeNum::negate() {
// TODO
}
// add two numbers
LargeNum LargeNum::operator+(const LargeNum &rhs) const {
// TODO
}
// subtract two numbers
LargeNum LargeNum::operator-(const LargeNum &rhs) const {
// TODO
}
// multiply two numbers
LargeNum LargeNum::operator*(const LargeNum &rhs) const {
// TODO
}
// divide two numbers. rhs is the divisor
// similar to integer division, ignore remainder
LargeNum LargeNum::operator/(const LargeNum &rhs) const {
// TODO
}
// return true if the numbers are equal
bool LargeNum::operator==(const LargeNum &rhs) const {
// TODO
}
// return true if the numbers are not equal
bool LargeNum::operator!=(const LargeNum &rhs) const {
// TODO
}
// return true if the left-hand-side number is less than the
// right-hand-side number
bool LargeNum::operator
// TODO
}
// return true if the left-hand-side number is greater than the
// right-hand-side number
bool LargeNum::operator>(const LargeNum &rhs) const {
// TODO
}
// return true if the left-hand-side number is less than or equal to the
// right-hand-side number
bool LargeNum::operator
// TODO
}
// return true if the left-hand-side number is greater than or equal to the
// right-hand-side number
bool LargeNum::operator>=(const LargeNum &rhs) const {
// TODO
}
// prefix increment
LargeNum &LargeNum::operator++() {
// TODO
}
// postfix increment
LargeNum LargeNum::operator++(int) {
// TODO
}
// prefix decrement
LargeNum &LargeNum::operator--() {
// TODO
}
// postfix decrement
LargeNum LargeNum::operator--(int) {
// TODO
}
// output number with a comma after ever 3 digits,
// e.g. 1234567890 -> 1,234,567,890
ostream &operator
// TODO
}
main.cpp
#include "largenum.h"
#include
#include
#include
using namespace std;
// check printing and addition
void test1() {
// stringstream strs;
// LargeNum num0("1234567890123456789");
// strs
// assert(strs.str() == "1,234,567,890,123,456,789");
// strs.str("");
// LargeNum num1(12345);
// strs
// assert(strs.str() == "12,345");
// strs.str("");
// LargeNum num2(11115);
// LargeNum num3 = num1 + num2;
// strs
// assert(strs.str() == "23,460");
// strs.str("");
// LargeNum num4(99);
// LargeNum num5 = num1 + num4;
// strs
// assert(strs.str() == "12,444");
// strs.str("");
// LargeNum num6(99000);
// LargeNum num7 = num1 + num6;
// strs
// assert(strs.str() == "111,345");
// cout
}
// check comparator operators
void test2() {
// assert(LargeNum(99) == LargeNum(99) && LargeNum(99) != LargeNum(100));
// assert(LargeNum(99) > LargeNum(7) && LargeNum(7)
// assert(LargeNum(105) >= LargeNum(100) && LargeNum(100)
// assert(LargeNum(99) > LargeNum(-7) && LargeNum(-7)
// assert(LargeNum(-5) > LargeNum(-10) && LargeNum(-10)
// assert(!(LargeNum(5) > LargeNum(5)));
// cout
}
// check negative numbers
void test3() {
// stringstream strs;
// LargeNum num0("-1234567890123456789");
// strs
// assert(strs.str() == "-1,234,567,890,123,456,789");
// strs.str("");
// LargeNum num1(-12345);
// strs
// assert(strs.str() == "-12,345");
// strs.str("");
// LargeNum numZero(-0000);
// strs
// assert(strs.str() == "0");
// assert(LargeNum(0).isZero() && LargeNum(-0).isZero());
// assert(LargeNum(0) == LargeNum(-0));
// assert(LargeNum(0).negate() == LargeNum(-0));
// assert(LargeNum(100) - LargeNum(100) == LargeNum(0));
// assert(LargeNum(100) + LargeNum(-100) == LargeNum(0));
// assert(LargeNum(100) - LargeNum(-100) == LargeNum(200));
// assert(LargeNum(-100) - LargeNum(-100) == LargeNum(0));
// assert(LargeNum(-100) + LargeNum(100) == LargeNum(0));
// assert(LargeNum(100) - LargeNum(7) == LargeNum(93));
// assert(LargeNum(7) - LargeNum(100) == LargeNum(-93));
// assert(LargeNum(-7) + LargeNum(-100) == LargeNum(-107));
// cout
}
// check multiplication
void test4() {
// assert(LargeNum(25) * LargeNum(0) == LargeNum(0));
// assert(LargeNum(25) * LargeNum(5) == LargeNum(125));
// assert(LargeNum(-25) * LargeNum(-5) == LargeNum(125));
// assert(LargeNum(-25) * LargeNum(5) == LargeNum(-125));
// assert(LargeNum(25) * LargeNum(-5) == LargeNum(-125));
// assert(LargeNum("123456789123456789") * LargeNum("123456789123456789") ==
// LargeNum("15241578780673678515622620750190521"));
// cout
}
// check division
// use small numbers to avoid excessive computation
void test5() {
// assert(LargeNum(0) / LargeNum(5) == LargeNum(0));
// assert(LargeNum(25) / LargeNum(5) == LargeNum(5));
// assert(LargeNum(-25) / LargeNum(-5) == LargeNum(5));
// assert(LargeNum(-25) / LargeNum(5) == LargeNum(-5));
// assert(LargeNum(25) / LargeNum(-5) == LargeNum(-5));
// assert(LargeNum("25") / LargeNum("7") == LargeNum("3"));
// assert(LargeNum("7") / LargeNum("25") == LargeNum("0"));
// cout
}
// check prefix and postfix operators
void test6() {
// LargeNum num0(10);
// assert(num0++ == LargeNum(10));
// assert(num0 == LargeNum(11));
// assert(--num0 == LargeNum(10));
// assert(num0-- == LargeNum(10));
// assert(num0 == LargeNum(9));
// assert(++num0 == LargeNum(10));
// assert(num0-- == LargeNum(10));
// assert(num0 == LargeNum(9));
// num0.negate();
// assert(++num0 == LargeNum(-8));
// assert(--num0 == LargeNum(-9));
// LargeNum num1(1);
// assert(--num1 == LargeNum(0));
// assert(--num1 == LargeNum(-1));
// assert(++num1 == LargeNum(0));
// cout
}
// run all tests
int main() {
test1();
test2();
test3();
test4();
test5();
test6();
cout
}
Design and implement LargeNum class which can be used to represent arbitrarily large numbers and operations on them. Accept the assignment and create your own private GitHub repository with the started code by clicking on this link .. Do not change the repository name or make it public. file is provided for you. You must implement all the public functions that have been defined. file includes a series of tests to help guide your design and development. Design Choices You have several design choices. Most important choice is how will you store the digits internally. One possibility is using class. Strings can be as long as needed, provide easy access to each index, have and functions to expand and shrink as needed. You may also want to store the digits in reverse order internally so index-0 of two large numbers correspond to the ones unit. For example, storing 12345 and 789 internally as "54321" and "987" means one's digit is at index-0 corresponding to 5 and 9 respectively which will make it easier when adding them. How do we differentiate between positive and negative numbers? I suggest having a boolean variable, that is set to by default. If the number is negated, the variable can be flipped. The number zero is a special case. We will define zero to be a positive number and make sure it is always treated as a positive number. I suggest starting the assignment by commenting almost everything and completing the minimum functions necessary for passing test1. Once your program successfully completes test1, you can then proceed to satisfy additional tests. This is similar to test-driven development, but in this case the tests are provided for you
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
