exercise 3
Tasks marked with a ∗ are assessed coursework. Hand in your solutions to these via email to rn@ic.ac.uk. (Resit students do not need to submit coursework.) Use the subject line “ C++ CW: surname firstname CW3”, where surname firstname CW3.cpp is the attached file that contains your solution. The course will be assessed based on 5 pieces of coursework (25%) and an end of term driving test (75%). Your submission must be your own work (submissions will be checked for plagiarism), and it should compile (and run) with the GNU C++ compiler g++. The deadline for submitting the coursework is 10pm on 24/02/2019.
-
Extra long int
Create a class extralongint that can handle very long integer numbers, say with at least up to 108 digits. Code the mathematical operations +, -, * and /, for this class and provide ways to input and output its objects. Furthermore, overload the relational operators <, > and ==. Let a = 1234567890987654321, b = 9876543210123456789. Compute the following values
(1) a∗b
(2) a∗b/(b−a)
(3) b2 − a2 (d) 51!
(4) Is 2122 > 2221 ? -
Fractions
Design a class fraction that allows you to store numbers in fractional form and do basic arithmetics with them. Your class declaration should include at least the following methods.class fraction { friend ostream &operator<< (ostream &os, const fraction &f); private: int numerator, denominator; void reduce(); public: fraction(int n = 0, int d = 1) : numerator(n), denominator(d) { reduce(); } fraction o