Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TP essai création de classe Rational */
- #include <iostream>
- class Rational {
- friend Rational operator+ (Rational a, Rational b);
- friend Rational operator* (Rational a, Rational b);
- private:
- int num;
- int denom;
- public:
- Rational(int n, int d): num(n),denom(d) {
- print();
- }
- void print() {
- std::cout<<num<<'/'<<denom<<std::endl;
- }
- Rational add(Rational a) {
- return Rational(num*a.denom+denom*a.num,denom*a.denom);
- }
- Rational mult(Rational a) {
- return Rational(num*a.num,denom*a.denom);
- }
- double eval(){
- };
- inline Rational operator+ (Rational a, Rational b) {
- return Rational(a.num*b.denom+a.denom*b.num,a.denom*b.denom);
- }
- inline Rational operator* (Rational a, Rational b) {
- return Rational(a.num*b.num,a.denom*b.denom);
- }
- int main() {
- Rational r(1,2);
- Rational t(3,5);
- Rational v=r.add(t);
- Rational w=t.mult(r);
- Rational z=r+w;
- Rational u=t*v;
- t.print(); /*3/5*/
- std::cout<<"coucou"<<"\n";
- std::cout<<"salutcava"<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement