在visual studio用平方根出错。

来源:百度知道 编辑:UC知道 时间:2024/06/03 22:09:17
代码:
// myexample.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "iostream"
#include "math.h"
using namespace std;
class rectangle
{
private:
double Long,Width,diagonal;
public:
rectangle(double,double);
rectangle(double);
double calDiag()
{
double theDiag=sqtr(Long*Long+Width*Width);
return theDiag;
}
void display()const
{
cout<<"The area is :"<<Long*Width<<endl
<<"The diagonal of the rectangle is:"<<diagonal<<endl;
}
};

rectangle::rectangle(double l,double w)
{
Long=l;
Width=w;
}
rectangle::rectangle(double e)
{
Long=Width=e;
}

int _tmain(int argc, _TCHAR* argv[])
{
rectangle ax1(23,45.7);
ax1.display();
rectangle ax2(50);
ax2.display();
return 0;

sqtr --> sqrt

hehe
就是啊
自己都看到错误了
还有既然用到了using namespace std; 命名空间
怎么还要在头文件中“ *.h ”
直接就“iostream”、“math”就行了!