Running Codes
#include
#include
using namespace std;
class Point
{
int x,y;
public:
Point()
{
}
Point(int x,int y)
{
this->x=x;
this->y=y;
}
int getX()
{
return this->x;
}
int getY()
{
return this->y;
}
};
// Display the vector contents by looping with size
void display(vector &v)
{
cout << endl;
for(int i=0;i<5;i++)
{
cout << "(" << v[i].getX() << "," << v[i].getY() << ") ";
}
cout << endl;
}
// Display the vector contents by iterator
void show(vector &v)
{
cout << endl;
vector::iterator p;
for(p=v.begin();p!=v.end();p++)
{
cout << "(" << (*p).getX() << "," << (*p).getY() << ") ";
cout << "(" << p->getX() << "," << p->getY() << ") ";
}
cout << endl;
}
int main()
{
vector v;
// Initial Size : 0
cout << "Initial Size : " << v.size() << endl;
for(int i=0;i<10;i++)
{
Point pt(i,i);
v.push_back(pt);
}
// Display
display(v);
cin.get();
return 0;
}
#include
using namespace std;
class Point
{
int x,y;
public:
Point()
{
}
Point(int x,int y)
{
this->x=x;
this->y=y;
}
int getX()
{
return this->x;
}
int getY()
{
return this->y;
}
};
// Display the vector contents by looping with size
void display(vector
{
cout << endl;
for(int i=0;i<5;i++)
{
cout << "(" << v[i].getX() << "," << v[i].getY() << ") ";
}
cout << endl;
}
// Display the vector contents by iterator
void show(vector
{
cout << endl;
vector
for(p=v.begin();p!=v.end();p++)
{
cout << "(" << (*p).getX() << "," << (*p).getY() << ") ";
cout << "(" << p->getX() << "," << p->getY() << ") ";
}
cout << endl;
}
int main()
{
vector
// Initial Size : 0
cout << "Initial Size : " << v.size() << endl;
for(int i=0;i<10;i++)
{
Point pt(i,i);
v.push_back(pt);
}
// Display
display(v);
cin.get();
return 0;
}
No comments:
Post a Comment