Question
I have a char Array. The constructor converts the int in to a char array. Right now, I can print the int object . But
I have a char Array. The constructor converts the int in to a char array. Right now, I can print the int object . But I need to be able to overload the operator += such that I can print out the sum of the ints(basically parse them back together to sum the int objects)
Class MyArr{
private:
char* data;
int length;}
//Constructor MyArray::MyArray(unsigned int n){
//initializng to n unsigned int value= n;
//declaring the char array data = new unsigned char[1000000000];
//converting int to char array int i=0; value=n; while(value>0){
data[i] = ('0'+(temp%10)); value = value/10;
i++;
} }
//HELP HERE PLEASE
MyArray& MyArray:: operator +=(const MyArray& rhs){
MyArray numArr;
for(int i=0; i
data[i] = numArry[i]; //copy char array into numArr
}
for(int j= 0; j
{ numArry[j] += rhs.data[i];
} return *this; }
main(){
myArr obj1(1000000);
myArry obj2(2000000);
//need it to print out
obj1+=obj2;
cout<< obj1;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started