鱼C论坛

 找回密码
 立即注册
查看: 2725|回复: 5

求高手帮忙改一下 !!!

[复制链接]
发表于 2014-3-22 16:17:40 | 显示全部楼层 |阅读模式
1鱼币
#include <iostream>
#include <cmath>
using namespace std;

class Point
{  
public:
        void setCoordinate (int x , int y , int m , int n ,double d );
        void setxy (int x, int y);
        void setmn (int m, int n);
       

        void print() ;
          
private:
        int X ;
        int Y ;
        int M ;
        int N ;
        double D;
        double Distance() ;


};


void Point::setCoordinate(int x, int y, int m, int n,double d)
{
        X=x;
        Y=y;
        M=m;
        N=n;
        D=d;

}

void Point::setxy(int x, int y)
{
   cout<< "请输入坐标一x,y"<< endl;
   cin >> x>> y;

}
void Point::setmn( int m,int n)
{
   cout<< "请输入坐标二m,n"<< endl;
   cin >> m>> n;
}

void Point::print()

{
    double Distance(double d)   
    {
                return sqrt((x-m)*(x-m)+(y-n)*(y-n));
        }
        cout<< "距离为" << Distance(d)<<'/n'<<endl;
}



int main()
{   int x,y,m,n;
    double d;
        Point p;
    p.setxy( x , y);
        p.setmn( m , n);
        p.setCoordinate(x,y,m,n,d);
        p.print();
        return 0;
}

1.cpp
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\作业三\1.cpp(53) : error C2601: 'Distance' : local function definitions are illegal
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\作业三\1.cpp(56) : error C2065: 'd' : undeclared identifier
执行 cl.exe 时出错.



不知道怎么改了   help!!!

最佳答案

查看完整内容

改完了,能实现2点间距离的计算
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-3-22 16:17:41 | 显示全部楼层
改完了,能实现2点间距离的计算


  1. #include <stdio.h>
  2. #include <iostream>
  3. using namespace std;
  4. #include <cmath>
  5. class Point
  6. {  
  7. public:
  8.         void setxy ();
  9.         void setmn ();
  10.         void print() ;
  11. private:
  12.         double X ;
  13.         double Y ;
  14.         double M ;
  15.         double N ;
  16.         double Distance() ;
  17. };
  18. void Point::setxy()
  19. {
  20.         cout<< "请输入坐标一x,y"<< endl;
  21.         scanf("%lf,%lf",&X,&Y);
  22. }
  23. void Point::setmn()
  24. {
  25.         cout<< "请输入坐标二m,n"<< endl;
  26.         scanf("%lf,%lf",&M,&N);
  27. }
  28. double Point::Distance()   
  29. {
  30.         return sqrt(double(X-M)*(X-M)+(Y-N)*(Y-N));
  31. }
  32. void Point::print()
  33. {
  34.         cout<< "距离为" << Distance()<<endl;
  35. }
  36. int main()
  37. {
  38.         Point p;
  39.     p.setxy();
  40.     p.setmn();
  41.     p.print();
  42.         system("pause");
  43.     return 0;
  44. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-3-22 17:36:55 | 显示全部楼层
本帖最后由 Simanzen 于 2014-3-22 18:03 编辑

#include <iostream>
#include <cmath>

using namespace std;

class Point
{  
public:
        void setxy ();
        void setmn ();
        void print() ;
           
private:
        int X ;
        int Y ;
        int M ;
        int N ;
};



void Point::setxy()
{
   cout<< "请输入坐标一x,y"<< endl;
   cin >>X>>Y;

}
void Point::setmn()
{
   cout<< "请输入坐标二m,n"<< endl;
   cin >>M>>N;
}

void Point::print()

{
     cout<< "距离为 " <<sqrt(double((X-M)*(X-M)+(Y-N)*(Y-N))) <<endl;
}


int main()
{
        Point p;
        p.setxy();
        p.setmn();
        p.print();
        return 0;
}

说实话,lz这样使用类不是很好
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2014-3-22 17:50:46 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-3-22 18:02:13 | 显示全部楼层
缦ㄟ兮 发表于 2014-3-22 17:50
我是哪里错了呢  ?  我都改蒙了  ,公有函数里不能带参数吗  ?

是不必要用别的参数,用类的私有数据成员就好了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-5-15 10:59:55 | 显示全部楼层
help????
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-9 18:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表