class program

hi
i tried this class working but theres an error in line mentioned below
plz help me rectify that


/*1. Make a class called "point" with two integer data members x and
y. Show how to create and use two points p1 and p2.*/

#include <iostream>

using namespace std;

class point
{
public:
int x;
int y;
int sum(int,int);
};

int point::sum(int a,int b)
{
cout << "enter any 2 integers";
cin >> a >> b;
x = a;
y = b;

return(x+y);
}

int main()
{
int s;

point D;

s = D.sum(int a,int b); //this line has an error

cout<<s;

return 0;
}

~
~
~
help will be appreciated
thank you
U can't declare int a and int b there. If u want u have 2 choices: first declare int a and b before
s=D.sum(a, b);
or.....better....do something like:
#include <iostream>
using namespace std;

class point
{
public:
int x;
int y;
int sum();
};

int point::sum()
{
cout << "enter any 2 integers";
cin >> x >> y;

return(x+y);
}

int main()
{
int s;

point D;
s = D.sum();

cout<<s;

return 0;}
.
Last edited on
Topic archived. No new replies allowed.