您的位置:首页 > 其它

第一次课堂作业之Circle

2016-05-05 23:39 225 查看

1.问题描述:


Create a program that asks for the radius of a circle and prints the area of that circle, using 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.


2.解题想法:


题目本身不难,主要就是把函数定义在main.cpp的外面,还要拆成.h声明和.cpp实现,百度了一下问题也不大。看到群里的讨论,本来想写成类里面的函数的我又跑去看了书上的外部函数。然后这次作业刚开始没有把几个文件放在一个项目里,一直找不到哪里错了。。。


3.最终代码:


main.cpp:

#include<iostream>
using namespace std;
int main()
{
extern double Area (double);
double r;
cin>>r;
cout<<Area(r)<<endl;
return 0;
}

area.h

#define area.h
#define pai 3.14
double Area(double);
#endif

area.cpp

#include"area.h"
extern double Area(double t)
{
return pai*t*t;
}

其实后来把'extern'、'#define area.h'和'#endif' 去掉再调试,结果还是一样。。。

然后这是:GITHUB的链接


4.测试样例:







内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: