(4) Initializing a data member with a parameter initialization table in a constructor is a more advocated notation. Test the function with the same (1).
#include <iostream>
#include <cmath>
using namespace Std;
Class Triangle
{
Public
Double perimeter ();
Double area ();
void ShowMessage ();
Triangle (double x,double y,double z): A (x), B (Y), C (z) {};
Private
Double a,b,c;
};
void Triangle::showmessage ()
{
cout<< "Triangular three-side lengths are:" <<a<< "<<b<<" <<c<<endl;
cout<< "The circumference of the triangle is" <<perimeter () << ", the area is:" <<area () <<endl<<endl;
}
Double Triangle::p erimeter ()
{
return a+b+c;
}
Double Triangle::area ()
{
Double p,s;
p= (A+B+C)/2;
S=sqrt (p* (p-a) * (p-b) * (p-c));
return s;
}
int main ()
{
Triangle Tri1 (1,1,1);
Tri1.showmessage ();
Triangle Tri2 (1.5,1,1);
Tri2.showmessage ();
Triangle Tri3 (1.5,1.5,1);
Tri3.showmessage ();
Triangle Tri4 (7,8,9);
Tri4.showmessage ();
return 0;
}
Operation Result:
Week four 13 constructors for angular classes-4