首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

输入有关问题

2012-03-04 
输入问题?#includeiostream#includecmathusingnamespacestd//-------------------------classPoint{p

输入问题?
#include   <iostream>
#include   <cmath>
using   namespace   std;
//-------------------------
class   Point
{
protected:
double   x,   y;
public:
    void   Set(double   ix,double   iy)
    {
    x=ix;   y=iy;
    }
//--------------------------
    double   xOffset()
    {
    return   x;
    }
//------------------------------
    double   yOffset()
    {
    return   y;
    }
//----------------------------
    double   angle()
    {
    return   (180/3.1415926)*atan2(y,x);
    }
    //-----------------
    double   radius()
    {
    return   sqrt(x*x+y*y);
    }
}
    //--------------------------
    //-------------------------
    int   main()
    {
    Point   P;
    double   x;
    double   y;

    cout   < <   "输入X的值: "   < <   "\n ";
    cout   < <   "输入Y的值: "   < <   "\n ";
    cin   > >   x   > >   y;

    P.Set(x,y);
            P.Set(x+5.0,y+6.0);
    //P.x+=5;
  //   P.y+=6;

    cout   < <   "angle=   "   < <   P.angle   < <   "\n ";
    cout   < <   "radius=   "   < <   P.radius   < <   "\n ";
    cout   < <   "xOffset=   "   < <   P.xOffset   < <   "\n ";
    cout   < <   "yOffset=   "   < <   P.yOffset   < <   endl;
           
    return   0;
    }
Compiling...
找错.cpp
F:\学习\程序\课后作业P289\ex0801.cpp\找错.cpp(37)   :   error   C2628:   'Point '   followed   by   'int '   is   illegal   (did   you   forget   a   '; '?)
F:\学习\程序\课后作业P289\ex0801.cpp\找错.cpp(57)   :   error   C2664:   '__thiscall   Point::Point(const   class   Point   &) '   :   cannot   convert   parameter   1   from   'const   int '   to   'const   class   Point   & '
                Reason:   cannot   convert   from   'const   int '   to   'const   class   Point '
                No   constructor   could   take   the   source   type,   or   constructor   overload   resolution   was   ambiguous
F:\学习\程序\课后作业P289\ex0801.cpp\找错.cpp(57)   :   error   C2553:   no   legal   conversion   of   return   value   to   return   type   'class   Point   * '


F:\学习\程序\课后作业P289\ex0801.cpp\找错.cpp(58)   :   warning   C4508:   'main '   :   function   should   return   a   value;   'void '   return   type   assumed
Error   executing   cl.exe.

找错.obj   -   3   error(s),   1   warning(s)
没把Point的成员函数设为const为何mian函数定为int且有return   0;会出错


[解决办法]
在 int main 之前,
class Point 定义之后,需要一个 分号
[解决办法]
class Point
{};//这里需要一个分号
int main()
{...
[解决办法]
楼主你粗心了,是错了地方,我帮你改过来了,下面是好用的程序,你马虎的地方我加了注释:

#include <iostream>
#include <cmath>
using namespace std;
//-------------------------
class Point
{
protected:
double x, y;
public:
void Set(double ix,double iy)
{
x=ix; y=iy;
}
//--------------------------
double xOffset()
{
return x;
}
//------------------------------
double yOffset()
{
return y;
}
//----------------------------
double angle()
{
return (180/3.1415926)*atan2(y,x);
}
//-----------------
double radius()
{
return sqrt(x*x+y*y);
}
}; //这里原来少加了分号,类体结束要加分号
//--------------------------
//-------------------------
int main()
{
Point P;
double x;
double y;

cout < < "输入X的值: " < < "\n ";
cout < < "输入Y的值: " < < "\n ";
cin > > x > > y;

P.Set(x,y);
P.Set(x+5.0,y+6.0);
//P.x+=5;
// P.y+=6;

cout < < "angle= " < < P.angle() < < "\n "; //这四个都是函数,都要带(),马虎了吧
cout < < "radius= " < < P.radius() < < "\n ";
cout < < "xOffset= " < < P.xOffset() < < "\n ";
cout < < "yOffset= " < < P.yOffset() < < endl;

return 0;
}

热点排行