473,473 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to solve problem"Huge Integer Class"?

51 New Member
the problem is:
Create a class HugeInteger which use 40-element array of digits to store integers as larg as 40 digits each.Provide methods input, output, add, subtract
how to add to arrays ?
Apr 13 '07 #1
17 12030
r035198x
13,262 MVP
the problem is:
Create a class HugeInteger which use 40-element array of digits to store integers as larg as 40 digits each.Provide methods input, output, add, subtract
how to add to arrays ?
And what have done so far?
Apr 13 '07 #2
khajeddin
51 New Member
well i thought i can add each digit(character) of the string1 and string2 with eachother and put it in the same position of the third string as shown below:
Expand|Select|Wrap|Line Numbers
  1. int[] a1=new int[40];
  2. int[] a2=new int[40];
  3. int[] a3=new int[40]; 
  4. .....
  5. a3[0]=a1[0]+a2[0];
  6.  
and ofcourse have some rule too do this correctly in the program...and do the same thing for subtract...
but my professor didn't accept this algorithm,he said we should get two string of 40-digit number and add or subtract them without convert each digit (each character) into integer and do the same thing as i showd above!
well i do'nt know what to do so?!!!
Apr 13 '07 #3
r035198x
13,262 MVP
the problem is:
Create a class HugeInteger which use 40-element array of digits to store integers as larg as 40 digits each.Provide methods input, output, add, subtract
how to add to arrays ?
What type is the 40-element array?
Apr 14 '07 #4
JosAH
11,448 Recognized Expert MVP
well i thought i can add each digit(character) of the string1 and string2 with eachother and put it in the same position of the third string as shown below:
Expand|Select|Wrap|Line Numbers
  1. int[] a1=new int[40];
  2. int[] a2=new int[40];
  3. int[] a3=new int[40]; 
  4. .....
  5. a3[0]=a1[0]+a2[0];
  6.  
and ofcourse have some rule too do this correctly in the program...and do the same thing for subtract...
but my professor didn't accept this algorithm,he said we should get two string of 40-digit number and add or subtract them without convert each digit (each character) into integer and do the same thing as i showd above!
well i do'nt know what to do so?!!!
Please don't write in ambiguous terms. Does your assignment say that you
have to use a fourty element char array or do you have to use Strings?

If you decide to use the char type for every single digit you do need a bit of
conversion because the numerical value of a digit char is not equal to the digit
itself.

kind regards,

Jos
Apr 14 '07 #5
khajeddin
51 New Member
let me describe from the begining as my professor want:
i have to get two array of 40-digit number(num1 & num2),then convert these two into strings of 40-digit number( array---->string) and then do add and subtract on these two strings.
( NOTE: what not to do : i shouldn't convert every digit(character in strings) into integer and i have do some kind of character add or character subtract on them).
and i have no sugesstion how to do this.please tell some about this!
Apr 14 '07 #6
JosAH
11,448 Recognized Expert MVP
let me describe from the begining as my professor want:
i have to get two array of 40-digit number(num1 & num2),then convert these two into strings of 40-digit number( array---->string) and then do add and subtract on these two strings.
( NOTE: what not to do : i shouldn't convert every digit(character in strings) into integer and i have do some kind of character add or character subtract on them).
and i have no sugesstion how to do this.please tell some about this!
So your professor doesn't want you to convert that String to an int; it can't be
done anyways because a fourty digit number is way too large for an int. You're
not allowed to convert it to a BigInteger either (my guess) and you have to add
those 40 digit numbers yourself. Well here goes:

If you have to add two characters (representing a single decimal digit) plus a
carry value (also representing a single decimal digit), you have to do this:
Expand|Select|Wrap|Line Numbers
  1. char a; 
  2. char b;
  3. char c; // the carry value
  4. char result= (char)(a+b+c-('0'+'0'));
  5. if (result > '9') { 
  6.    // determine new carry and adjust result
  7. }
  8. else
  9.    c= '0'; // no carry
If your professor doesn't like this, tell him/her to give me a call ;-)

kind regards,

Jos
Apr 14 '07 #7
khajeddin
51 New Member
please let me tell you what i understand from this way:
we know that to convert every character to an integer we have to subtract 48 from that character and because charachter 0 is equal to -48 you do that to convert a & b into integers!!!!
thank you very much
iwill write code of this program right away and send this to know your what you think about that...:)
Apr 14 '07 #8
JosAH
11,448 Recognized Expert MVP
please let me tell you what i understand from this way:
we know that to convert every character to an integer we have to subtract 48 from that character and because charachter 0 is equal to -48 you do that to convert a & b into integers!!!!
thank you very much
iwill write code of this program right away and send this to know your what you think about that...:)
Yep, you got it. Best of luck with writing your program code.

kind regards,

Jos
Apr 15 '07 #9
eng200
5 New Member
Yep, you got it. Best of luck with writing your program code.

kind regards,

Jos

hey josah!
i didn't understand wat u meant by the "carry" thing,i mean i understand what it means it's just that i dnt know where to put it in my code i dnt even know where to start from,,,,our professor gave us this question as a bonus so would u please write the whole code>? if ur free,no obligations but i would be very grateful if u sent it ;)


thanks
Oct 21 '07 #10
JosAH
11,448 Recognized Expert MVP
hey josah!
i didn't understand wat u meant by the "carry" thing,i mean i understand what it means it's just that i dnt know where to put it in my code i dnt even know where to start from,,,,our professor gave us this question as a bonus so would u please write the whole code>? if ur free,no obligations but i would be very grateful if u sent it ;)


thanks
Sorry to disappoint you but that's not the way we handle things overhere. You
give it a reasonable try yourself first. If you're stuck come and ask here and we'll
try to help you out but it's *you* who has to do the work, not us. It's your homework
or assignment, not ours. Go and give it a try.

kind regards,

Jos
Oct 21 '07 #11
eng200
5 New Member
Sorry to disappoint you but that's not the way we handle things overhere. You
give it a reasonable try yourself first. If you're stuck come and ask here and we'll
try to help you out but it's *you* who has to do the work, not us. It's your homework
or assignment, not ours. Go and give it a try.

kind regards,

Jos
sorry about thatb,,, this is what i came up with but i get errors and i dnt know how to fix it :




class HugeInteger {

public :

HugeInteger();
HugeInteger(int someArray[]);

int getarray() const;

void input(int inputArray[]);
void output(int []);
void add(int []);
void substract(int []);



bool isEqualto(int *[]);
bool isNotEqualto(int *[]);
bool isGreaterThan(int *[]);
bool isLessThan(int *[]);
bool isGreaterThanOrEqualTo();
bool isLessThanOrEqualTo();

bool isZero();

private :

int a[40];

};
HugeInteger();
HugeInteger(int someArray[]);
HugeInteger(int arraySize);
virtual ~HugeInteger();


HugeInteger::HugeInteger()
{
pNumberArray = null;
}

HugeInteger::HugeInteger(int arraySize)
{
pNumberArray = new int[arraySize];
}

HugeInteger::~HugeInteger()
{
if ( pNumberArray != null )
{
delete [] pNumberArray;
pNumberArray = null;
}
}


#include <iostream>
using namespace std;

#include "H1.cpp"
#include "h1.h"



void main ()


{

HugeInteger A();
A.input();
A.output();
A.add();
A.substract();
A.isEqualto();
A.isGreaterThan();
A.isLessThan();
A.isGreaterThanOrEqualTo();
A.isLessThanOrEqualTo();
A.isZero();


}


when i compile it ,,it says that i have to put class/struct/union type before " .(name of function)" in the main ,,i really dnt know how to fix it i tried to write this much from my lab papers that i have we work on classes but i find them hard to understand,,,,please help me understand,,,

thnx,,
Oct 21 '07 #12
eng200
5 New Member
sorry about thatb,,, this is what i came up with but i get errors ...

It's not working because I didn't write the actual functions :$,,, I also wanted to ask if there is another way to solve this problem other than using arrays.
Oct 21 '07 #13
JosAH
11,448 Recognized Expert MVP
It's not working because I didn't write the actual functions :$,,, I also wanted to ask if there is another way to solve this problem other than using arrays.
You do realize that you posted C++ source code in a Java forum do you?

kind regards,

Jos
Oct 22 '07 #14
eng200
5 New Member
You do realize that you posted C++ source code in a Java forum do you?

kind regards,

Jos

yeah i do realize that but the question was already asked in the java forum so i ddnt want to ask again in the c++ forum and i thought that since u know java then u also know c++ so i posted it here...if u dnt want to help me just tell me it's ok but tell me asap so i can ask someone else coz i really want to know where to fix my code ,,,and i really thought that this site is helpful that's why i joined anyway am sorry again next time i have a question i'll post it in the write forum
Oct 22 '07 #15
JosAH
11,448 Recognized Expert MVP
yeah i do realize that but the question was already asked in the java forum so i ddnt want to ask again in the c++ forum and i thought that since u know java then u also know c++ so i posted it here...if u dnt want to help me just tell me it's ok but tell me asap so i can ask someone else coz i really want to know where to fix my code ,,,and i really thought that this site is helpful that's why i joined anyway am sorry again next time i have a question i'll post it in the write forum
Do you want me to move your question to the C/C++ forum?

kind regards,

Jos
Oct 22 '07 #16
eng200
5 New Member
Do you want me to move your question to the C/C++ forum?

kind regards,

Jos


yes please,,,,i would really appreciate it :)

thnx,,
Oct 22 '07 #17
JosAH
11,448 Recognized Expert MVP
yes please,,,,i would really appreciate it :)

thnx,,
Ok, there you go. (maybe we'll 'see' eachother again there)

kind regards,

Jos
Oct 22 '07 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Joe | last post by:
I have an upload file operation in the web application. UploadForm.asp is the form, and UploadAction.asp is the form processing. //UploadForm.asp <FORM NAME="InputForm"...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
11
by: Joseph Turian | last post by:
Fellow hackers, I have a class BuildNode that inherits from class Node. Similarly, I have a class BuildTree that inherits from class Tree. Tree includes a member variable: vector<Node>...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
10
by: Flip | last post by:
I know the int.Parse("123") will result in an int of 123, but what happens with a null? I believe it give a null exception (seems like I get either NullArgumentException or ArgumentNullException...
1
by: Andreas Poller | last post by:
Hello, I have the following problem: I have a class deriving from ICustomTypeDescriptor: public __gc class TPropertyBag : public ICustomTypeDescriptor { private: ...
11
by: Kimmo Laine | last post by:
I'm flipping my wig here, people. I'm using classes and making each class a file. when I'm including dependet classess, I use require_once to avoid multiple declarations - yet they happen. I put...
0
by: Paul | last post by:
Hi All. We have a custom class which we serialize. This class is regularly updated, and the old requests do not have a problem opening, apart from a couple!!! When it try's to deserialize the...
7
by: Camellia | last post by:
hi all, I wrote a "table of powers" program and made the 5th power the highest, but when I tried to run the program I found a problem. Here's the output: Integer Square power...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.