JanaSabuj / UIUC-object-oriented-ds-coursera

The Coursera course submissions and certificate awarded for completing the course by University of Illinois - Urbana Champaign

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

complete the given program

msabir063 opened this issue · comments

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;
}

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; }