Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete the given program #2

Open
msabir063 opened this issue Jun 8, 2020 · 1 comment
Open

complete the given program #2

msabir063 opened this issue Jun 8, 2020 · 1 comment

Comments

@msabir063
Copy link

Create a class called Pair that has two public integer member variables named "a" and "b", and a public member function named sum() that has no arguments but adds the two member variables together and returns their sum.

class Pair{
public:
float Pair;
int a,b,sum();

};
int main()
{
Pair p;
p.a = 100;
p.b = 200;
if (p.a + p.b == p.sum()) {
std::cout << "Success!" << std::endl;
} else {
std::cout << "p.sum() returns " << p.sum() << " instead of " << (p.a + p.b) << std::endl;
}
return 0;
}

@Yuvraj3905
Copy link

Create a class called Pair that has two public integer member variables named "a" and "b", and a public member function named sum() that has no arguments but adds the two member variables together and returns their sum.

#include
using namespace std;

class Pair{ public: float Pair; int a,b;
int sum(){
return (a+b);
}

}; int main() { Pair p; p.a = 100; p.b = 200; if (p.a + p.b == p.sum()) { std::cout << "Success!" << std::endl; } else { std::cout << "p.sum() returns " << p.sum() << " instead of " << (p.a + p.b) << std::endl; } return 0; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants