Polar Class Example C++
Define polar class where each object represents point in polar
coordinates (angle and radius). Include static data member which keeps track
the number of active objects of the class
#include<iostream>
#include<math.h>
using namespace std;
class polar
{
float real;
float img;
public:
static int count;
void get_polar()
{
count++;
cin>>real>>img;
}
void print_polar()
{
cout<<real<<img;
}
polar()
{
count++;
real=img=0;
}
polar(const polar &p1)
{
count++;
img=p1.img;
real=p1.real;
}
~polar()
{
count--;
cout<<"DESTRUCTOR\n";
}
};
int polar::count;
int main()
{
polar c1,c2,c3,c4;
c1.get_polar();
c2.get_polar();
c3.get_polar();
c4.get_polar();
cout<<polar::count;
c1.~polar();
c2.~polar();
c3.~polar();
c4.~polar();
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
class polar
{
float real;
float img;
public:
static int count;
void get_polar()
{
count++;
cin>>real>>img;
}
void print_polar()
{
cout<<real<<img;
}
polar()
{
count++;
real=img=0;
}
polar(const polar &p1)
{
count++;
img=p1.img;
real=p1.real;
}
~polar()
{
count--;
cout<<"DESTRUCTOR\n";
}
};
int polar::count;
int main()
{
polar c1,c2,c3,c4;
c1.get_polar();
c2.get_polar();
c3.get_polar();
c4.get_polar();
cout<<polar::count;
c1.~polar();
c2.~polar();
c3.~polar();
c4.~polar();
return 0;
}
Comments
Post a Comment