c++.定义一个Circle类,包括数据成员R(半径),成员函数Area(),计算圆的面积,定义一个对象C进行测试
展开全部
//Circle.h
#pragma once
#define PI 3.14159
class Circle
{
public:
Circle(double r);
~Circle();
double Area();
public:
double R;
};
//Circle.cpp
#include "Circle.h"
Circle::Circle(double r)
{
R = r;
}
Circle::~Circle(void)
{
}
double Circle::Area()
{
return PI*R*R;
}
//main.cpp
#include <iostream>
#include "Circle.h"
using namespace std;
int main()
{
Circle cir(3.5);
cout<<cir.Area()<<endl;
getchar();
return 0;
}
#pragma once
#define PI 3.14159
class Circle
{
public:
Circle(double r);
~Circle();
double Area();
public:
double R;
};
//Circle.cpp
#include "Circle.h"
Circle::Circle(double r)
{
R = r;
}
Circle::~Circle(void)
{
}
double Circle::Area()
{
return PI*R*R;
}
//main.cpp
#include <iostream>
#include "Circle.h"
using namespace std;
int main()
{
Circle cir(3.5);
cout<<cir.Area()<<endl;
getchar();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询