Advertisement
Guest User

Untitled

a guest
May 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2. ///clasa fractie cu nimit si numarat.
  3. ///sa se supraincarce operatorul + care adun a 2 fractii
  4. using namespace std;
  5.  
  6. class fractie{
  7. int numitor,numarator;
  8. public:
  9.  
  10. fractie operator+();
  11. // fractie operator!=();
  12. //fractie operator+(fractie b); /->METODA
  13. friend fractie operator+(fractie, fractie b); //->FUNCTIE PRETENA
  14. fractie(int a=0,int b=1);
  15. void afisare();
  16. };
  17. fractie::fractie(int a,int b){
  18. numitor=a;
  19. numarator=b;
  20. }
  21. void fractie::afisare(){
  22. cout<<"numaratorul este: "<<numarator<<" iar numitorul : "<<numitor<<endl;
  23. }
  24. /*** METODA
  25. fractie fractie::operator+(fractie b){
  26. fractie c; //c=ob.ct+b
  27. c.numitor=numitor +b.numitor;
  28. c.numarator=numarator+b.numarator;
  29. return c;
  30. }
  31. *****/
  32. fractie fractie::operator+(){
  33. numarator*=-1;
  34. numitor*=-1;
  35.  
  36. }
  37. /*
  38. fractie fractie::operator!=(){
  39. numarator*=-1;
  40. numitor*=-1;
  41. cout<<"A MERS CU DIFERIT";
  42. }
  43. */
  44. fractie operator+(fractie a,fractie b){ ///functie pretena
  45. fractie c;
  46. c.numitor=a.numitor +b.numitor;
  47. c.numarator=a.numarator+b.numarator;
  48. return c;
  49. }
  50.  
  51. int main()
  52. {
  53.  
  54. fractie fr1(2,4),fr2(6,7), g;
  55. //cout<<(fr1+fr2);
  56. g=fr1+fr2;
  57. g.afisare();
  58. +g;
  59. g.afisare();
  60. fr1.afisare();
  61. // !=fr1;
  62. fr1.afisare();
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement