Managed C++/CLI



Hi my professor gave my class this homework to do without giving us any notes or hints on how to do it. Im so lost and dont know where to start. I've put together some of the member function declarations and one constructor but highly doubt if they're correct.
An array can be used to store large integers one digit at a time. For example, the integer 1234 could bestoredinthearrayabysettinga[0]to1,a[1]to2,a[2]to3,anda[3]to4. However,for this project, you might find it more useful to store the digits backward, that is, place the least significant digit 4 in a[0], 3 in a[1], 2 in a[2], and the most significant digit 1 in a[3].
Design, implement, and test a class in which each object is a large integer with each digit stored in a separate element of a character array. You’ll also need a private member variable to keep track of the sign of the integer (perhaps a Boolean variable), and another private member variable to keep the size (or length) of the integer. The number of digits may grow as the program runs, so the class must use a character pointer (dynamic character array) as a member variable, which stores its value on the dynamic memory freestore (heap). You should also implement other appropriate operators for this class. More specifically, your class should provide default constructor, deepcopy copy constructor, overloaded constructor(s), destructor, deepcopy assignment operator, overloaded arithmetic operators, comparison operators, input and output operators. You should also have a nice driver code to test all implemented member functions and overloaded operators.
#include <iostream>
using namespace std;
class BigInteger
{
private:
bool sign; char * arr; int size;
public:
BigInteger(int size=0); BigInteger( const char* arr); BigInteger( BigInteger& arr); ~BigInteger(); void swap(BigInteger&);
void count( int );
BigInteger& operator=(const BigInteger& arr);
BigInteger& operator+(const BigInteger& arr);
BigInteger& operator(const BigInteger& arr);
bool operator==(const BigInteger & arr) const;
bool operator!=(const BigInteger & arr) const;
bool operator<(const BigInteger & arr) const;
bool operator>(const BigInteger & arr) const;
bool operator>=(const BigInteger & arr) const;
bool operator<=(const BigInteger & arr) const;
friend ostream& operator<<(ostream & output, const BigInteger& arr);
friend istream& operator>>(istream & input, const BigInteger& arr);
};
int main()
{
}
BigInteger::BigInteger(int size) : arr(){
arr= new char[size+1];
for(int i=0;i<size;i++)
{
arr[i]=' ';
}
arr[ size ] = '\0';
}
BigInteger::BigInteger(const char* arr){
}
any help with this program to even get it started would be very appreciated thank you, i'm not asking for just the answer i actually want to know what i'm doing in my class.





Msemler93 wrote: i actually want to know what i'm doing in my class. If you don't know then it's a sure bet that we don't.
If you have specific technical questions then people will try to answer them, but no one is going to do your assignment for you. If you really do not understand the assignment then go and talk to your professor, or find some books or online materials to help you.
One of these days I'm going to think of a really clever signature.





You don't need the null at the end
Your constructor looks ok except that you did not take into account that the first byte might be a sign character.
I am not sure why your teacher thinks it would be better to store it backwards.
I suggest you try to create the following method next.
bool operator==(const BigInteger & arr) const;
To code it THINK (don't code) about the following cases
 The number is exactly the same.
 One number is zero, the other isn't.
 One number have more digits than the other.
 AFTER you do the above then consider what happens if the 'sign' value is set to represent a negative value.
AFTER you think about the above then attempt to code the method.





ok me and my friend have been working on the program and are having trouble getting the arrays to pass to the functions and dont know where the issue is.
#include
using namespace std;
class Integer{
public:
Integer();
Integer(Integer& a);
Integer operator +(const Integer &);
Integer operator (const Integer &);
bool operator<(Integer)const;
void SetArr();
void print();
void addNumbers();
void subNumbers();
private:
bool sign;
int size;
int size2;
int size3;
char * arr1;
char * arr2;
char * arr3;
};
int main()
{
Integer sum,diff, in1,in2;
in1.SetArr();
/*in2.SetArr();
in1.addNumbers();
in1.print();
in1.subNumbers();
in1.print();*/
}
Integer::Integer()
{
size=0;
arr1=NULL;
}
Integer::Integer(Integer& a)
{
a.size=0;
a.arr1=NULL;
}
void Integer::SetArr()
{
cout<<"How many digits is the number?"<<endl;
cin>>size;
int* arr1=new int[size];
cout<<"Enter the sequence of the "<<size<<" integers"<<endl;
for(int i=(size1);i>=0;i)
cin>>arr1[i];
cout<<endl;
for(int i=0;i>size2;
int* arr2=new int[size2];
cout<<"Enter the sequence of the "<<size2<<" integers"<<endl;
for(int i=(size21);i>=0;i)
cin>>arr2[i];
cout<<endl;
for(int i=0;i=size2)
size3=size+1;
else
size3=size2+1;
int* arr3=new int[size3];
int carry=0;
for(int i=0;i=0;i)
cout<<arr3[i];
cout<<endl<<endl;
for(int i=0;iarr2[i])
arr3[i]=arr1[i]arr2[i];
else{
arr1[i+1]=(arr1[i+1]1);
arr1[i]=arr1[i]+10;
arr3[i]=arr1[i]arr2[i];
}
}
cout<<endl;
for(int i=0;i=0;i)
cout<<arr3[i];
}
void Integer::print()
{
for(int i=0;iarr2[i])
arr3[i]=arr1[i]arr2[i];
else{
arr1[i+1]=(arr1[i+1]1);
arr1[i]=arr1[i]+10;
arr3[i]=arr1[i]arr2[i];
}
}
}





Use code tags when you post code.
Focus on the class  not the input/output. For testing you can hard code some values right now.







General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.