主题:两个程序的比较
[size=3]#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(float len,float width)
{
Length=len;
Width=width;
}
float GetArea() {return Length*Width;}
float GetLength() {return Length;}
float GetWidth() {return Width;}
private:
float Length;
float Width;
};
void main()
{
float Length,Width;
cout<<"请输入矩形的长度:"<<endl;
cin>>Length;
cout<<"请输入矩形的宽度:"<<endl;
cin>>Width;
Rectangle r(Length,Width);
cout<<"长为:"<<Length<<"宽为:"<<Width<<"的矩形面积为:"<<r.GetArea()<<endl;
}[/size]
[color=800000]请输入矩形的长度:
25
请输入矩形的宽度:
25
长为:25宽为:25的矩形面积为:625[/color]
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(float Length,float Width) {};
float GetArea() {return Length*Width;}
float GetLength() {return Length;}
float GetWidth() {return Width;}
private:
float Length;
float Width;
};
void main()
{
float Length,Width;
cout<<"请输入矩形的长度:"<<endl;
cin>>Length;
cout<<"请输入矩形的宽度:"<<endl;
cin>>Width;
Rectangle r(Length,Width);
cout<<"长为:"<<Length<<"宽为:"<<Width<<"的矩形面积为:"<<r.GetArea()<<endl;
}
[color=008000]请输入矩形的长度:
25
请输入矩形的宽度:
25
长为:25宽为:25的矩形面积为:1.15292e+016
[/color]
[color=000080][size=1]请问,这两个程序有什么不同,为什么运行结果会不一样啊?[/size][/color]
using namespace std;
class Rectangle
{
public:
Rectangle(float len,float width)
{
Length=len;
Width=width;
}
float GetArea() {return Length*Width;}
float GetLength() {return Length;}
float GetWidth() {return Width;}
private:
float Length;
float Width;
};
void main()
{
float Length,Width;
cout<<"请输入矩形的长度:"<<endl;
cin>>Length;
cout<<"请输入矩形的宽度:"<<endl;
cin>>Width;
Rectangle r(Length,Width);
cout<<"长为:"<<Length<<"宽为:"<<Width<<"的矩形面积为:"<<r.GetArea()<<endl;
}[/size]
[color=800000]请输入矩形的长度:
25
请输入矩形的宽度:
25
长为:25宽为:25的矩形面积为:625[/color]
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(float Length,float Width) {};
float GetArea() {return Length*Width;}
float GetLength() {return Length;}
float GetWidth() {return Width;}
private:
float Length;
float Width;
};
void main()
{
float Length,Width;
cout<<"请输入矩形的长度:"<<endl;
cin>>Length;
cout<<"请输入矩形的宽度:"<<endl;
cin>>Width;
Rectangle r(Length,Width);
cout<<"长为:"<<Length<<"宽为:"<<Width<<"的矩形面积为:"<<r.GetArea()<<endl;
}
[color=008000]请输入矩形的长度:
25
请输入矩形的宽度:
25
长为:25宽为:25的矩形面积为:1.15292e+016
[/color]
[color=000080][size=1]请问,这两个程序有什么不同,为什么运行结果会不一样啊?[/size][/color]