Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <sstream>
- using namespace std;
- class myInt{
- protected:
- int num;
- public:
- myInt(){}
- myInt(int num) : num(num) {}
- int get(){
- return num;
- }
- virtual void set(int num){
- this->num = num;
- }
- myInt operator+(myInt& rhs){
- return myInt(this->get() + rhs.get());
- }
- myInt operator+(myDouble& rhs){
- return myInt(this->get + rhs.getWh());
- }
- };
- class myInt99 : public myInt{
- public:
- myInt99() {}
- myInt99(int num){
- this->set(num);
- }
- virtual void set(int num){
- if (num > 99 || num < -99) throw("NOOOOOOOOOOO!");
- this->num = num;
- }
- };
- class myDouble : public myInt, public myInt99{
- private:
- myInt whole;
- myInt99 frac;
- void cast(stringstream& ss){
- int a, b;
- char c;
- ss >> a >> c >> b;
- while (abs(b) > 99) b /= 10;
- whole.set(a);
- frac.set(b);
- }
- public:
- myDouble() {}
- myDouble(string s){
- stringstream ss(s);
- cast(ss);
- }
- myDouble(double d){
- stringstream ss(d);
- cast(ss);
- }
- myDouble(myInt mI, myInt99 mI99){
- whole = mI;
- frac = mI99;
- }
- myDouble(int mI, int mI99){
- whole.set(mI);
- frac.set(mI99);
- }
- myDouble operator+(myDouble& rhs){
- return myDouble(this->whole.get() + rhs.getWh(), this->frac.get() + rhs.getFr());
- }
- myDouble operator+(myInt& rhs){
- return myDouble(this->whole.get() + rhs.get(), this->frac.get());
- }
- virtual void set(double d){
- stringstream ss(d);
- cast(ss);
- }
- int getWh(){
- return this->whole.get();
- }
- int getFr(){
- return this->frac.get();
- }
- };
- int main(){
- myInt a(2), b(3);
- myInt c(a + b);
- cout << c.get() << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement