Untitled

 avatar
irfan
plain_text
2 years ago
868 B
2
Indexable
5) Write a program containing Default Constructor, Parameterized Constructor, and Destructor
 
#include <iostream>
using namespace std;
class Line {
public:
double getLength( void );
Line(); // This is the constructor declaration
Line( double len );//This is the parameterized constructor declaration
~Line(); // This is the destructor: declaration
public:
double length;
};
// Member functions definitions including constructor
Line::Line (void)
{
cout << "Object is being created" << endl;
}
Line::Line (double len)
{ //Length=6.0;
length=len;
}
Line::~Line (void)
{ 
cout << "Object is being deleted" << endl;
}
double Line::getLength(void)
{
return length;
}
// Marin function for the program
int main()
{ 
Line linel;
Line line=Line (3.4);
// set Line Length
cout << "Length of line: " << line.getLength() <<endl;
return 0;
}
Editor is loading...
Leave a Comment