You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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);
}
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;
}
The text was updated successfully, but these errors were encountered: