Commit bf4b5787 authored by Hans Buchmann's avatar Hans Buchmann

constructor

 non-dedault
instance variables
 xc/yc
init list
destructor
parent f04addfa
......@@ -7,10 +7,43 @@
#include <fstream>
//---------------------------------------------- Point
// declaration
class Point
{
public:
Point(double x,double y); //constructor x/y position in the plane
//non default constructor
~Point(); //destructor no parameters
private:
double xc; //x-coordinate
double yc; //y-coordinate
};
//---------------------------------------------- Point
// implementation
Point::Point(double x,double y) //x,y parameter
:xc(x),yc(y) //init list:only for construtors
//xc=x,yc=y
{
}
Point::~Point()
{
std::cout<<"destructor of Point "<<xc<<","<<yc<<"\n";
}
//---------------------------------------------- Line
int main(int argc,char**args)
{
//use case
Point p(3.1,4.7);
// | |----------- y-coordinate
// |--------------- x-coordinate
// p is an instance of the class Point
Point q(7.3,2.4);
// | |----------- y-coordinate
// |--------------- x-coordinate
// q is an instance of the class Point
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment