-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfraccion.cpp
47 lines (41 loc) · 1.07 KB
/
fraccion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <sstream>
#include "fraccion.h"
using namespace std;
Fraccion::Fraccion() {};
Fraccion::Fraccion(int n, int d) {
this->n = n; //Numerador
this->d=d; //Denominador
};
Fraccion::Fraccion(const Fraccion &orig) {
this->n = orig.n;
this->d = orig.d;
};
Fraccion::~Fraccion() {
};
Fraccion& Fraccion::operator=(const Fraccion &rhs) {
this->n = rhs.n;
this->d = rhs.d;
return *this;
};
void Fraccion::operator+(const Fraccion &rhs){
this->n = (this->n * rhs.d) + (this->d * rhs.n) ;
this->d = this->d * rhs.d;
};
void Fraccion::operator-(const Fraccion &rhs){
this->n = (this->n * rhs.d) - (this->d * rhs.n) ;
this->d = this->d * rhs.d;
};
void Fraccion::operator*(const Fraccion &rhs){
this->n = this->n * rhs.n;
this->d = this->d * rhs.d;
};
void Fraccion::operator/(const Fraccion &rhs){
this->n = this->n * rhs.d;
this->d = this->d * rhs.n;
};
string Fraccion::operator~() {
stringstream s("", ios_base::app | ios_base::out);
s<<"La fraccion es: " << n << "/" << d << endl;
return s.str();
};