newbie for C++ want to know what happening in this program specially in last part why rectres and rectparam created??

// friend functions
#include <iostream>
using namespace std;

class CRectangle {
int width, height;
public:
void set_values (int, int);
int area () {return (width * height);}
friend CRectangle duplicate (CRectangle);
};

void CRectangle::set_values (int a, int b) {
width = a;
height = b;
}

CRectangle duplicate (CRectangle rectparam)
{
CRectangle rectres;
rectres.width = rectparam.width*2;
rectres.height = rectparam.height*2;
return (rectres);
}

int main () {
CRectangle rect, rectb;
rect.set_values (2,3);
rectb = duplicate (rect);
cout << rectb.area();
return 0;
Last edited on
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/jEywvCM9/

2) The purpose of the function seems to be to create a CRectangle object that is a copy of the object that's passed in, but with each dimension doubled. The name "duplicate" is misleading, because the function isn't actually creating a duplicate.

rectparam is the parameter to the function, containing the rectangle from which a double-sized copy is to be created.

rectres is the double-sized copy, which is created by the function and passed back as the return value.
thanks for your answer actually i saw this program on net. you can cheak out whole program or concept at
http://www.cpp.thiyagaraaj.com/friendship-and-inheritance-opps

second thing is i have interview for iOS developer but actually i am from electronics background so i was not in touch of programming much. they want proficiency in C and C++ and OOPS concepts.
Last edited on
second thing is i have interview for iOS developer but actually i am from electronics background so i was not in touch of programming much. they want proficiency in C and C++ and OOPS concepts.

I don't mean to sound rude but if you're not familiar with programming, what makes you think this job will be right for you?
i want to change my work field want to make career as a developer i have complited my B.tech in 2013. there are no jobs in core electronics companies so that why...you are a professional C++ developer guide me is it difficult to switch? they were told me they want proficiency in C,C++ languanges. after that they will give training for objective C.
Last edited on
Sounds like it might be difficult to achieve the the required proficiencies in a short time span to be honest. I switched, but i had been hacking about with code for 10 years before i left my last career and started software.
Last edited on
ok...i will try my best..thanks..
Last edited on
Topic archived. No new replies allowed.