-
-
春平网络
丨Lv 1
// SinaAsk.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include<iostream.h> #include<stdio.h> #include<math.h> class cpoint{ public: int Long(int,int); float Long(float,float); }; int cpoint::Long(int a,int b) //求两整型数间距离的函数 { int c; c=(a-b)*(a-b); return c; } float cpoint::Long(float a,float b) ////求两实型数间距离的函数 { float c; c=(a-b)*(a-b); return c; } int main() { int x1,x2,y1,y2,x,y,z; //x=(x1-x2)^2,y=(y1-y2)^2,z=x+y(就是距离) float x3,x4,y3,y4,a,b,c; double h; cpoint mcpoint;cout<<"请输入两个整型数的坐标x1,y1,x2,y2:\n"; cin>>x1; cin>>y1; cin>>x2; cin>>y2; cout<<"两个实型数的坐标x3,y3,x4,y4:\n"; cin>>x3; cin>>y3; cin>>x4; cin>>y4; /*************************************** 求整型数的距离 ****************************************/ x=mcpoint.Long(x1,x2); //此处表达不合法?!! y=mcpoint.Long(y1,y2); z=x+y; h=sqrt(z); //开根 cout<<"两整型点间的距离为"<<h<<endl;//printf("两整型点间的距离为:%d\n",h); /*************************************** 求实型数的距离 ****************************************/ a=mcpoint.Long(x3,x4); //x=(x1-x2)^2 b=mcpoint.Long(y3,y4); c=a+b; h=sqrt(c); //开根 cout<<"两实型点间的距离为"<<h<<endl;;//printf("两实型点间的距离为:%f\n",h); return 0;} /*对上面回答的补充说明:1 类要实例化后才能调用其中的成员函数2 输入的时候,以回车作为分隔。比如,现在计算两个点(1,2)和(3,4)的距离,那么输入的时候,依次输入1,然后回车,输入2,回车,输入3,回车,输入4。*/