Q.WAP using the above class to define an array of 10 points and input
the data in the array.Then for each point tell if it lies on any axis
(x-axis or y-axis).
#include<iostream.h>
#include<conio.h>
#include<math.h>
int i;
class Point
{
private:
int x,y;
public:
Point()
{
x=0;
y=0;
}
void getinfo()
{
cout<<"Enter co-ordinates of the point:";
cin>>x>>y;
}
void print()
{
cout<<"("<<x<<","<<y<<")";
}
int return_X()
{
return x;
}
int return_Y()
{
return y;
}
};
void main()
{
clrscr();
Point P[10];
for(i=0;i<10;i++)
{
P[i].getinfo();
}
for(i=0;i<10;i++)
{
if(P[i].return_Y()==0)
{
cout<<endl<<"Point:";
P[i].print();
cout<<endl<<"Lie on x-axis.";
}
if(P[i].return_X()==0)
{
cout<<endl<<"Point:";
P[i].print();
cout<<endl<<"Lie on y-axis.";
}
if(P[i].return_X()==0 && P[i].return_Y()==0)
{
cout<<endl<<"Origin";
}
}
getch();
}
the data in the array.Then for each point tell if it lies on any axis
(x-axis or y-axis).
#include<iostream.h>
#include<conio.h>
#include<math.h>
int i;
class Point
{
private:
int x,y;
public:
Point()
{
x=0;
y=0;
}
void getinfo()
{
cout<<"Enter co-ordinates of the point:";
cin>>x>>y;
}
void print()
{
cout<<"("<<x<<","<<y<<")";
}
int return_X()
{
return x;
}
int return_Y()
{
return y;
}
};
void main()
{
clrscr();
Point P[10];
for(i=0;i<10;i++)
{
P[i].getinfo();
}
for(i=0;i<10;i++)
{
if(P[i].return_Y()==0)
{
cout<<endl<<"Point:";
P[i].print();
cout<<endl<<"Lie on x-axis.";
}
if(P[i].return_X()==0)
{
cout<<endl<<"Point:";
P[i].print();
cout<<endl<<"Lie on y-axis.";
}
if(P[i].return_X()==0 && P[i].return_Y()==0)
{
cout<<endl<<"Origin";
}
}
getch();
}
Not working
ReplyDelete