Week 7 computer task project 2-differences between member functions, friend functions and general functions

Source: Internet
Author: User
Tags gety
01. /* 02. * copyright and version Declaration of the program part 03. * Copyright (c) 2013, Yantai University Computer college student 04. * All rightsreserved. 05. * file name: cpoint. cpp 06. * Author: Zhao guanzhe 07. * Completion Date: April 8, April 12, 2013. * version: v1.0 09. * input Description: 10. * Problem description: 11. */# include <iostream> # include <cmath> using namespace std; class CPoint {private: double x; // abscissa double y; // ordinate public: CPoint (double xx = 0, double yy = 0): x (xx), y (yy) {} void distance1 (CPoint cp); friend void distance2 (CPoint cp1, CPoint cp2); double getx () {return x;} double gety () {return y ;}}; void CPoint: distance1 (CPoint cp) {double dist = sqrt (cp. x-x) * (cp. x-x) + (cp. y-y) * (cp. y-y); cout <"the distance between the two points is:" <dist <endl;} void distance2 (CPoint cp1, CPoint cp2) {double dist = sqrt (cp1.x-cp2.x) * (cp1.x-cp2.x) + (cp1.y-cp2.y) * (cp1.y-cp2.y )); cout <"the distance between two points is:" <dist <endl;} void distane3 (CPoint cp1, CPoint cp2) {double dis = sqrt (cp1.getx () -cp2.getx () * (cp1.getx ()-cp2.getx () + (cp1.gety ()-cp2.gety () * (cp1.gety ()-cp2.gety ())); cout <"the distance between two points is:" <dis <endl ;}int main () {CPoint cp1, cp2 (8, 6); cp1.distance1 (cp2 ); distance2 (cp1, cp2); distanc4( cp1, cp2); return 0 ;}

Running result:

Related Article

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.