Midterm2-question 6 source code

23 views
Skip to first unread message

Hacer Keles

unread,
May 3, 2013, 12:32:32 PM5/3/13
to com...@googlegroups.com
#include <iostream>
using namespace std;

class A
{
int a;
public:
A(int aa=0)
{
a = aa;
}
void print()
{
cout<<a<<endl;
}
// add function definition
A& add(int x)
{
a+=x;
return *this;
}
// multiply function definition
A& multiply(A& x)
{
a*=x.a;
return *this;
}

};
int main()
{
A a1(2);
A a2(6);
a1.add(3).multiply(a2);
a1.print();
}

int x;

merve bayram

unread,
May 3, 2013, 12:36:59 PM5/3/13
to com...@googlegroups.com
A& multiply(A x)
{
a*=x.a;
return *this;
}


hocam bu soruda 2.fonksiyonu şu şekilde yazmış olsak herhangi bir sorun olmaz değil mi sonuç değişmiyor.


2013/5/3 Hacer Keles <hacer...@yahoo.com>

Hacer Keles

unread,
May 3, 2013, 3:34:23 PM5/3/13
to com...@googlegroups.com
Hayır sorun olmaz. Doğru sonucu verecek alternatif sonuçların hepsi ok.

H.


From: merve bayram <mrv.b...@gmail.com>
To: com...@googlegroups.com
Sent: Friday, May 3, 2013 7:36 PM
Subject: Re: [com102] Midterm2-question 6 source code
Reply all
Reply to author
Forward
0 new messages