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

初学者提问~帮个忙吧!

2012-02-25 
菜鸟提问~~~帮个忙吧!!#includeiostreamusingnamespacestd#include cmathclassFC{public:FC(floata,f

菜鸟提问~~~帮个忙吧!!
#include   <iostream>
using   namespace   std;
#include <cmath>
class   FC
{
public:
FC(float   a,float   b,float   c):x(a),y(b),z(c){}
void   display(float,float,float);
int   fun();
        int   play();
private:
float   x;
float   y;
float   z;

};
void   FC::display(float,float,float)
{
float   a=0;
float   b=0;
float   c=0;
}
int   FC::fun();
{
cout < < "please   enter   three   num: " < <endl;
cin> > a;
        cin> > b;
cin> > c;

}
int   FC::play();
{
        if(a==0)
{
int   x1;
cout < <x1=-c/b < <endl;
}
else
if(b*b-4*a*c <0)
{
cout < < "error ";
}
          else
  {
  int   x1,x2;
  cout < <x1=(-b+sqrt(b*b-4*a*c))/(2*a) < <endl < <x2=(-b-sqrt(b*b-4*a*c))/(2*a) < <endl;

  }
}
int   main()
{
FC   A;
A.fun();
A.play();
return   0;

}

[解决办法]
恩,你做的应该是一个方程求解的程序吧。
首先,你的没有作缺省的构造函数,所以FC A;是会出错的。
然后,你的void display();没有作用,可以改成缺省的构造函数。
最后,你的成员变量,用的是xyz,而在你的成员函数里,你用的abc。。。。
换过来就可以了。

还有lightnut()已经搞好了,没有错的。
[解决办法]
按你这样的写法要这么定义FC A(a,b,c);因为你有三个形参;
缺省的构造函数:
FC::FC()
{
float x=0;
float y=0;
float z=0;
}
或者向lightnut()一样用
FC(float a_=0,float b_=0,float c_=0):a(a_),b(b_),c(c_){}
的构造函数

热点排行