Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ass2 Large Numbers Goals: Understanding operator overloading Design and implement LargeNum class which can be used to represent arbitrarily large numbers and operations on them.

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

Ass2 Large Numbers Goals: Understanding operator overloading Design and implement LargeNum class which can be used to represent arbitrarily large numbers and operations on them. Accept the assignment and create your own private GitHub repository with the started code by clicking on . Do not change the repository name or make it public. file is provided for you. You must implement all the public functions that have been defined. file includes a series of tests to help guide your design and development. Design Choices You have several design choices. Most important choice is how will you store the digits internally. One possibility is using class. Strings can be as long as needed, provide easy access to each index, have and functions to expand and shrink as needed. You may also want to store the digits in reverse order internally so index-0 of two large numbers correspond to the ones unit. For example, storing 12345 and 789 internally as "54321" and "987" means one's digit is at index-0 corresponding to 5 and 9 respectively which will make it easier when adding them. How do we differentiate between positive and negative numbers? I suggest having a boolean variable, that is set to by default. If the number is negated, the variable can be flipped. The number zero is a special case. We will define zero to be a positive number and make sure it is always treated as a positive number. I suggest starting the assignment by commenting almost everything and completing the minimum functions necessary lips \& Hints 1. Pay attention to the output from clang-tidy. Fix it if you can, explain how you tried to fix it in the Readme file if you can not fix it. 2. Correctly format your code. Either set VSC to "format on save" or use "clang-format - i *.cpp". You will unnecessarily lose points if your code is not properly formatted. 3. Keep your function short. Use helper functions. Use the class functions. 4. Do NOT include the "cpp" file from another cpp file. You should compile your code using . or its equivalent. 5. Take advantage of the symmetry of mathematical operations, so you do not replicate code when working with negative numbers is the same as is the same as is the same as is the same as is the same as the result of negated 6. Do not store the "-" sign with the digits. Use a boolean instead to indicate negative values. 7. You can use on strings. You do not need to compare them digit by digit 8. You should never have or in your conditions. Simplify. 9. You can do multiplication as repeated addition. Division can be done as repeated subtraction. 10. You do NOT need to use " " in this assignment. Do not create any objects on the heap. 11. You can use stoi on individual digits, but a LargeNum might be too big to use stoi on. 12. Given a character, you can subtract ' 0 ' to turn it into integer. How do we differentiate between positive and negative numbers? I suggest having a boolean variable, that is set to by default. If the number is negated, the variable can be flipped. The number zero is a special case. We will define zero to be a positive number and make sure it is always treated as a positive number. I suggest starting the assignment by commenting almost everything and completing the minimum functions necessary for passing test1. Once your program successfully completes test1, you can then proceed to satisfy additional tests. This is similar to test-driven development, but in this case the tests are provided for you. Grading Criteria The maximum grade for a program that does not compile and run all the given tests in main.cpp is 50% - Correcteness: 85% - Coding standards: 15% (all functions have comments, clang-format and clang-tidy warnings are addressed or explained in README file, no unnecessary globals, member variables, etc) Submit: Before you submit, run script to create output.txt file The last commit URL for your assignment repository. which will be something like https://github.com/uwbclass/342P2-githubusername/commit/7e76dd658b0c2fffdec8109d515f15c928beaab0 You can find the last commit URL in your GitHub repository by clicking on, under "commits" > "browse repository". Tips \& Hints 1. Pay attention to the output from clang-tidy. Fix it if you can, explain how you tried to fix it in the Readme file if you can not fix it. 2. Correctly format your code. Either set VSC to "format on save" or use "clang-format - i *.cpp". You will unnecessarily lose points if your code is not properly formatted. 3. Keep your function short. Use helper functions. Use the class functions. 4. Do NOT include the "cpp" file from another cpp file. You should compile your code using , or its equivalent. 5. Take advantage of the symmetry of mathematical operations, so you do not replicate code when working with public: // default constructor from string explicit LargeNum(const string \&str = "0"); // constructor from int explicit LargeNum(int anI const LargeNum \&other // use the default copy c use the default copy constructor LargeNum (const LargeNum \&other) = default; // use the default copy assignment operator LargeNum \&operator=(const LargeNum \&other )= default; // use the default destructor LargeNum( ) = default; // returns true if the number is zero bool iszero() const; // negate the number, positive becomes negative, negative becomes pos: // Zero is always positive LargeNum \&negate( ); // add two numbers LargeNum operator + (const LargeNum \&rhs) const; // subtract two numbers LargeNum operator-(const LargeNum \&rhs) const; // multiply two numbers LargeNum ..perator*(const LargeNum \&rhs) const; // divide two numbers. rhs is the divisor // similar to integer division, ignore remainder LargeNum operator/(const LargeNum \&rhs) const; // return true if the numbers are equal bool operator==(const LargeNum \&rhs) const; // return true if the numbers are not equal bool operator!=(const LargeNum \&rhs) const; // return true if the left-hand-side number is less than the // right-hand-side number bool operator(const LargeNum \&rhs) const; // return true if the left-hand-side number is less than or equal to // right-hand-side number bool operator=(const LargeNum \&rhs) const; // prefix increment LargeNum \&operator++(); // postfix increment LargeNum operator++(int); // prefix decrement LargeNum \&operator--(); // postfix decrement

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the WACC at the optimal capital structure?

Answered: 1 week ago