4003-231: CS1 Homework Programs #4 Due: Thur. week 10 ARRAYS & CLASS & METHODS (oh my) ===================== Grading Policy =================================== Each question below has a number of points associated with it, you are required to turn in 3 points worth of problems. ===================== Things to Turn in ================================ You should turn in a printout of your program (make sure you name and the homework number is at the top. In addition, you should turn in a printout of the running of your program. To get a file that contains the output of everything that is printed on the screen (in Unix) you can use the "script" command. For information on how to use the command type man script on the Unix command line. When providing output from your program you should run your program multiple times, with a couple of the runs using data not provided in the examples. ===================== Homework Programs ================================ 1. (3 points) Write your own string class called MyString which saves the letters of the string in an array of characters. So the string "hi mom" could be saved in an array of 6 (char type) elements like: +---+---+---+---+---+---+ |'h'|'i'|' '|'m'|'o'|'m'| +---+---+---+---+---+---+ Some things you might want your class to do are: a) ability to convet a normal String into a MyString (using a constructor). b) ability to make a copy of another MyString (using a constructor). c) ability to convert MyString back to a string (using a "toString" method). d) some standard String functions like: charAt substring indexOf concat toUpperCase toLowerCase ... Note that these methods should take/return MyString's as opposed to String's. You will need to write a main program to test your class. Your main program should include calls to all the methods you implement. 2. (3 points) Write yourself a MyBigInt class which allows you to work with integers of any length. This class will not be able to store the number in an int (because ints can't be bigger than 2.1billion) instead, it can store each digit of the number as an element of an array. So the number 1234871718923877 could be stored in a array with 16 (int type) elements like: +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 1 | 2 | 3 | 4 | 8 | 7 | 1 | 7 | 1 | 8 | 9 | 2 | 3 | 8 | 7 | 7 | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ You will need to come up with some way to represent that the number is negative. Some things you might want your class to do are: a) ability to convert an integer to a MyBigInt (constructor) b) ability to convert a String containing a number to a MyBigInt (constructor) c) ability to convert a MyBigInt to a string for printing (using a "toString" method) d) ability to convert the MyBigInt into a double e) math functions like: add sub Note that these methods should take and return MyBigInt's You will need to write a main program to test your class. Your main program should include calls to all the methods you implement.