Saturday, January 30, 2010

A Big Number Calculating Approach

Although this is the first post of the blog, I have nothing much to say since I'm testing the syntax highlighter. It's a slick javascript highlighter written by Alex Gorbatchev. 

This Big Number class has been written primary for the 3rd Assignment of a unit called Advanced Programming in my 3rd semester at University of Technology and Engineering, Vietnam National University, Hanoi (you can follow this URI for full documents and exercises but I'm not sure whether it will work in the future). According to the requirement of the assignment, I had to implement a linked-list and use that list to store digits of the number. And then I decided to write some operator overloading methods for the class so I can use native operators with the big number objects. List of operators supported:

  1. Input and Output (<<, >>)
  2. Assigning (==) by another integer or another object
  3. Comparison (>, <). Writing >= or <= should be easy since the compare function (cmp) produce different returning value for larger than, less than or equal to. I just didn't write them because it's not required for my assignment
  4. Calculating: adding, subtracting and multiplying (+, -, *, +=, -=, *=)
Originally, the assignment requires adding and multiplying but in the 4th semester, in other unit, the professor requires subtracting so I used the same old class and wrote the subtracting functionality. I want to finish it with dividing also but, well, at first I'm lazy and it seems to be difficult and I have no much time so that's it for now. Here is the full code. Hope it may help some body