Click here to Skip to main content
13,900,451 members
Rate this:
Please Sign up or sign in to vote.
See more:
For example::
class ex
void main()
ex e1(3,5), e2(5,7),e3;

The answer should be 8 q2..
The x of e1 should be added to x of e2....and y of e1 should be added to y of e2...
Thanks ... a s a p..

What I have tried:

I have tried but I didn't got it
Updated 14-Jun-18 21:43pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Seeing this statement and knowing that all applies to the class ex, the function prototype must be
ex add(const ex& e1) const;
and the corresponding implementation is
ex ex::add(const ex& e1) const
    ex result;
    result.a = this->a + e1.a;
    result.b = this->b + e1.b;
    return result;
or shorter using the constructor (and to be placed in the class definition)
ex add(const ex& e1) const
    return ex(this->a + e1.a, this->b + e1.b);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190306.1 | Last Updated 15 Jun 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100