圆面积

github链接https://github.com/leijing000/object-oriented/tree/master/Circle

一、题目描述:

Create a program that asks for the radius of a circle and prints the area of that circle .
Use cin and cout .
The whole program should be divided into two source files(cpp) .
Hand in the source files and the head files which you create .

二、代码实现(包含一个头文件和两个源文件)

  • Circle.h(声明函数,#define)

define pi 3.1415

double calculate(double radius);

  • function.cpp(实现函数功能)

include"Circle.h"

double calculate(double radius)
{
double area;
area = piradiusradius;
return area;
}

  • main.cpp(计算圆的面积,调用函数)

include"Circle.h"

include

using namespace std;
int main()
{
double area;
double radius;

cout << "Please enter the radius of the circle:";
cin >> radius;

area = calculate(radius);

cout << "The area of the circle is: " << area << endl;

return 0;
}

三、遇到的一些问题:

  • 出现这个问题的原因是我在define 后面加了分号,将分号去掉就可以了。

  • 写的过程中还出现了重定义的问题,我将在头文件中定义的变量放到了main.cpp里定义就可以了。

posted @ 2016-05-06 00:45  Leijing000  阅读(289)  评论(0)    收藏  举报