Friends functions (member friends functions, ordinary friends functions)

Source: Internet
Author: User
# Include <iostream>
# Include <math. h>
Using namespace STD;
Constdoublepi= 3.141593;
Classcircle;
// Classcalculate
//{
// Public:
// Doubledistance (circle & P1, circle & p2 );
//};

Classcircle
{
PRIVATE:
Doublex, Y, R;
Public:
// Constructor
Circle (double xx = 0, double YY = 0, double RR = 0)
{
X = xx; y = YY; r = RR;
}

// Display
Voiddisplay ()
{
Cout <"\ tcenter point: (" <x <"," <Y <")" <Endl;
Cout <"\ tradius:" <r <Endl;
Cout <"\ Tarea:" <this-> area () <Endl;
Cout <"\ tcirculars:" <this-> circular () <Endl;
}

// Area
Doublearea ()
{
Returnpi * r * R;
}

// Perimeter
Doublecircular ()
{
Return 2 * pI * R;
}

// Normal friend Functions
Frienddoubledist (circle & P1, circle & p2 );
// Member functions
// Frienddoublecalculate: distance (circle & P1, circle & p2 );
};
// If you forget this semicolon, an error is returned:
// 'Circle' followed by a double is illegal. (Did you forgot ';'?)
// Doublecalculate: distance (circle & P1, circle & p2)
//{
// Returnsqrt (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y ));
//}
Doubledist (circle & P1, circle & p2)
{
Returnsqrt (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y ));
}

Void main ()
{
Circle C1 (1, 1, 1), C2 (3, 4, 5 );
// Calculatecal; // a calculate object must be declared.
Cout <"circle 1:" <Endl;
C1.display ();
Cout <Endl;

Cout <"circle 2:" <Endl;
C2.display ();
// Cout <"The distance is:" <Cal. Distance (C1, C2) <Endl;
Cout <"The distance is:" <dist (C1, C2) <Endl;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.