Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Assignment Project : Part 1: It occurs to you that when dealing with really large values the computation overflows if you use a fixed

C++ Assignment

Project : Part 1: It occurs to you that when dealing with really large values the computation overflows if you use a fixed size data type like int or long. You plan to design a class that can handle arbitrarily large values and support a few simple operations. Since all the values are nonnegative integers (all calculations are done in pennies and there is no half pennies) you decide to use a string data member to represent the numeric value. Hints: Number.h header file has been given to you. All you need to do is implement Number.cpp. Comment out all functions except Number(), Number(string val), getValue() first and implement those. Once you have tested your simplified class with them, comment back in, one function at a time, pretty much in the order given. Implement the function, test it, move on to the next function, repeat. operator<< relies on print function to do all the work (cout<> relies on read function (cin>>n1 does the same thing as n1.read(cin)) to do all the work. Once you have print and read functions all you have to do is use them in operator << and >>. You may find the Number With Operators example in Unit 14 Demo Source pretty useful for this. For operator + you will need to combine two number strings into a third string which represents the sum of the two, one digit at a time just like in grade school. Once you have that string create a Number with that value and return it. To get the numeric value of a char you can subtract '0' from it, e.g.: string num = "142"; int four = num[1] - '0';

Part 2: Your boss is very happy your Number class can handle really large values but she would also like another number class which has all the capabilities of Number but slightly different behaviors. A FunnyNumber does strange math. For example, 2 + 2 = 22, 100 + 1 = 1001. For equality testing, two funny numbers are considered equal if they both use the same digits, regardless of numeric value. For example 100 == 101 (both use 0 and 1), 123321 == 231, 112 != 223 (one uses 1 and 2, the other uses 2 and 3). It also has a new member function which reverses a number. E.g. 1234 becomes 4321, 1200 becomes 21, 0 stays 0. Hints: Make a FunnyNumber.h header which extends Number.h, add two constructors to it and verify that it works just like a Number Add a void reverse() function and implement it. Override operators + and == in FunnyNumber so they have a different behavior. Deliverables: You should submit a zip file named project5_first_last.zip (where first and last are your first and last name) containing ONLY the files below. Number.cpp, FunnyNumber.h, FunnyNumber.cpp (copy the files from your IDE) * You should not make changes to Number.h, but if you could not implement it fully as given and you had to make changes, please submit Number.h as well report.txt (a short text file saying I have tested this program and it has no issues and a sample output from your program with the given main How you lose points: You make changes for fun to Number.h, breaking the contract and leading to the client code in main to not compile Your function implementation code does not follow good programming practices such as good variable names, comments, etc.

Also add: Support operator for Number to allow subtraction operations. Please note that the result can be negative and your operator+ and the rest of your class should work with negative values as well or the number obtained as a result of a subtraction could be broken.

Given number.h :

#include #include #include

using namespace std;

int main() { cout<<"Math with regular ints:"<

cout<>n1; cout<<"Enter another really big integer: "; cin>>n2; cout<>f1; cout<<"Enter another positive integer: "; cin>>f2; cout<

return 0; }

and a sample main here :

#ifndef NUMBER_H #define NUMBER_H

#include #include

using namespace std;

class Number { public: // Make a number with value 0 Number(); // Make a number with value val Number(string val);

// Get the number's value virtual string getValue() const;

// Print this number to the stream virtual void print(ostream& stream) const;

// Read this number from the stream virtual void read(istream& stream);

// Overload the insertion operator friend ostream& operator <<(ostream& outs, const Number& n);

// Overload the extraction operator friend istream& operator >>(istream& ins, Number& n);

// Operator + virtual Number operator+ (const Number& other) const;

// Operator == virtual bool operator== (const Number& other) const;

protected: string value; };

#endif // NUMBER_H

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

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

=+Is it possible to operate union-free?

Answered: 1 week ago

Question

=+impact member states and MNEs?

Answered: 1 week ago