Skip to content

Instantly share code, notes, and snippets.

@tina1998612
Created November 2, 2017 13:00
Show Gist options
  • Save tina1998612/090ff2475587537b9b9f6a6aae3e8a6a to your computer and use it in GitHub Desktop.
Save tina1998612/090ff2475587537b9b9f6a6aae3e8a6a to your computer and use it in GitHub Desktop.
/*
* bigDecimal.h
*/
#ifndef BIGDECIMAL_H_
#define BIGDECIMAL_H_
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct Node {
char data;
Node* next;
};
class BigDecimal {
public:
BigDecimal();
BigDecimal(const char* str);
BigDecimal(int i);
BigDecimal(float f);
BigDecimal(double d);
BigDecimal(const BigDecimal& bi);
~BigDecimal();
/* #### You need to implement from_string(const char*) and to_string(char*) methods. #### */
/**
* Method: void from_string(const char* str)
* Description:
* from_string method will read the number from str.
* If str is valid, it will be parsed and stored into sign and storage, and then return true. Otherwise, false will be returned.
*/
bool from_string(const char* str);
/**
* Method: void to_string(const char* str)
* Description:
* to_string method will output the current number to str.
*/
void to_string(char* str);
/* #### Please add your overloading methods below. #### */
BigDecimal operator+(BigDecimal& b1);
BigDecimal operator+(double& b1);
// miss double + big
BigDecimal operator-(BigDecimal& b1);
BigDecimal operator-(double& b1);
//BigDecimal operator-(const BigDecimal& b1);
BigDecimal operator*(BigDecimal& b1);
BigDecimal operator*(double& b1);
//BigDecimal operator*(const BigDecimal& b1);
BigDecimal operator/(BigDecimal& b1);
BigDecimal operator/(double& b1);
//BigDecimal operator/(const BigDecimal& b1);
BigDecimal& operator=(BigDecimal& b);
BigDecimal& operator=(double& d);
BigDecimal& operator=(int& i);
BigDecimal& operator=(float& f);
BigDecimal& operator++();
BigDecimal operator++(int i);
BigDecimal& operator--();
BigDecimal operator--(int i);
bool operator>(BigDecimal& b1);
bool operator>(double& b1);
bool operator>(int& b1);
bool operator>(float& b1);
bool operator>=(BigDecimal& b1);
bool operator>=(double& b1);
bool operator>=(int& b1);
bool operator>=(float& b1);
bool operator<(BigDecimal& b1);
bool operator<(double& b1);
bool operator<(int& b1);
bool operator<(float& b1);
bool operator<=(BigDecimal& b1);
bool operator<=(double& b1);
bool operator<=(int& b1);
bool operator<=(float& b1);
bool operator==(BigDecimal& b1);
bool operator==(double& b1);
bool operator==(int& b1);
bool operator==(float& b1);
bool operator!=(BigDecimal& b1);
bool operator!=(double& b1);
bool operator!=(int& b1);
bool operator!=(float& b1);
BigDecimal operator^(BigDecimal& b);
istream& operator>>(BigDecimal& b);
ostream& operator<<(const BigDecimal& b);
// helper functions
Node* linkedListFromStr(const string str);
Node* linkedListFromChar(const char* str);
private:
Node* linkedList;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment