473,659 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ 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 12053
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

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

Similar topics

7
4531
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" ACTION="UploadAction.asp" METHOD="POST" enctype=multipart/form-data> <input type="file" name="fileName"> //etc ... </FORM>
205
10592
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
2086
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> nodes; // For clarity, let this be "orig_nodes" BuildTree includes a member variable:
19
6766
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 one, and only one parent. The depth should not exceed 6 or 7 levels. The initial import will have about 6 million leaves, and 3 million branches. I would expect the leaves to grow significantly, in number easily tripling. However, the branches will...
10
5868
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 if I'm running it in a console app or in a web app, what's up with that?). I'm trying to get a counter (int) value out of the Application object. When I do the Convert.ToInt32(Application), the first time (it's null), the method converts it to...
1
2817
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
41077
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 debug_print_backtrace in the file to see how it is included, and here's the output: #0 require_once() called at #1 require_once(\eKirje.textGrid.class.php) called at #0 require_once() called at #1 require_once(\eKirje.kanava.class.php)...
0
1178
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 class I receive "One of the serialized keys is null". I tried to change the constructor "below" to check if the object is null to change is to a new object and set the value but still have the same error. Any ideas? as we need to keep backward...
7
5212
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 3rd power 4th power 5th ------- ------ --------- --------- --------- 1 1 1 1 1
0
8332
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.