- #1
diredragon
- 323
- 15
Create a class DecimalN which holds decimal numbers using dynamic arrays.
Implement a constructor DecimalN::DecimalN(char* decimal) so that it can be created like for example DecimalN number("23.5698").
Create two class functions (methods) that given the number n it shift the number n places to the right or left depending on the function.
Function prototypes:
DecimalN DecimalN::moveleft(int n); // left
DecimalN DecimalN::moveright(int n); // right
Note: No vectors and no library other than <iostream> allowed.
Here is my work:
I am not sure how to deal with functions that return a DecimalN. I am working with whole and fraction of the original class right? Or am i making another and then doing something with it? Before i start writing i just wanted to ask if i do work with whole and fraction of the first class, what do i return?
Implement a constructor DecimalN::DecimalN(char* decimal) so that it can be created like for example DecimalN number("23.5698").
Create two class functions (methods) that given the number n it shift the number n places to the right or left depending on the function.
Function prototypes:
DecimalN DecimalN::moveleft(int n); // left
DecimalN DecimalN::moveright(int n); // right
Note: No vectors and no library other than <iostream> allowed.
Here is my work:
Code:
#include <iostream>
using namespace std;
class DecimalN {
int *whole, *fraction; //Array that keeps the parts of the number as digits
int lng_whole, lng_frac; //Lengths of those parts.
char sign; //Possibly to know the sign of the function if added like "+3.45"
public:
DecimalN(char* decimal); //This function works properly so take it as doing everything fine and given then number eg. 45.890
//makes whole = [4,5] and fraction = [8,9,0]
~DecimalN() { delete[] whole; delete[] fraction; }; //Destructor
DecimalN moveleft(int n); //The part which i need to write.
};