You are to write a program that will multiply two numbers and print out the two numbers and the results.. Your program should handle up to 25 digit integer numbers.
Your input for this program is found in BigNumber.dat
The format is one number per line. You will have several pairs of numbers to process.
//GetNumbers(inData,ptr,size); //use for testing the value but not necessary for the program.
PutInArray(inData);
delete [] ptr;
inData.close();
return 0;
}
//Function to test the output
//void GetNumbers(ifstream& inData,int *p, int size)
//{
// int i;
//
// for(i=0;i<=size;i++)
// {
// inData >> p[i];
// cout << p[i];
//
// }
// cout << endl;
//
//
//}
void PutInArray(ifstream& inData)
{
int i, j, pos, count;
int p[MAX],p1[MAX];
count = 0;
pos = inData.find('\n'); //find the position of new line
while(!inData.eof())
{
for(i=50;i>0;i--) //********************************************
{ //This loop start from 50 and going backward.
if(pos < count) //the array will be right justification.
{ //This loops get the contents of data in first line
inData >> p[i]; //and put the value in the array. If there is no
count++; //value the else statement put the rest of the array
} //fill with zero.
//*********************************************
else
p[i]=0; //put the rest of array fill with zeros
}
inData.seekg(pos); //put the cursor in the current position.
pos = inData.find('\n'); //find the new position of new line in the file.
count = 0; //Reset counter to zero.
for(j=50;j>0;j--) //***********************************
{ //This loop is same as the for loop
if(pos < count) //on the above. but this loop get data
{ //from the second line. and right justification
inData >> p1[i]; //and put the rest of array fill with zeros.
count++; //
} //
else //************************************
p1[i]=0; //put the rest of array fill with zeros
}
count = 0;
inData.seekg(pos); //put the cursor in the current position.
} //end of while loop
//******************************
//array testing
//******************************
for(int k=0;k<156;k++)
{
cout << p[k];
cout << p1[k];
}
}
Do they really expect you to use a bignum lib for this?
Is really bignum such a big deal? Most programming languages have it in standard.
I never understood why they give those stupid assignment questions where the main difficulty is to configure and link a bignum library... As if it proved you could program or not.