Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- ///clasa fractie cu nimit si numarat.
- ///sa se supraincarce operatorul + care adun a 2 fractii
- using namespace std;
- class fractie{
- int numitor,numarator;
- public:
- fractie operator+();
- // fractie operator!=();
- //fractie operator+(fractie b); /->METODA
- friend fractie operator+(fractie, fractie b); //->FUNCTIE PRETENA
- fractie(int a=0,int b=1);
- void afisare();
- };
- fractie::fractie(int a,int b){
- numitor=a;
- numarator=b;
- }
- void fractie::afisare(){
- cout<<"numaratorul este: "<<numarator<<" iar numitorul : "<<numitor<<endl;
- }
- /*** METODA
- fractie fractie::operator+(fractie b){
- fractie c; //c=ob.ct+b
- c.numitor=numitor +b.numitor;
- c.numarator=numarator+b.numarator;
- return c;
- }
- *****/
- fractie fractie::operator+(){
- numarator*=-1;
- numitor*=-1;
- }
- /*
- fractie fractie::operator!=(){
- numarator*=-1;
- numitor*=-1;
- cout<<"A MERS CU DIFERIT";
- }
- */
- fractie operator+(fractie a,fractie b){ ///functie pretena
- fractie c;
- c.numitor=a.numitor +b.numitor;
- c.numarator=a.numarator+b.numarator;
- return c;
- }
- int main()
- {
- fractie fr1(2,4),fr2(6,7), g;
- //cout<<(fr1+fr2);
- g=fr1+fr2;
- g.afisare();
- +g;
- g.afisare();
- fr1.afisare();
- // !=fr1;
- fr1.afisare();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement