第一次课堂作业之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.测试样例:
相关文章推荐
- 随笔-2016.5.5
- OC中, unichar跟char有什么不同?unichar 是什么?
- [置顶] android开发之集成zxing,二维码,以及扫描二维码的功能实现。带源代码下载
- 二分查找
- uvaoj1398/ LA3950
- 开源库的使用,jar包的导入
- wc统计数量
- 三个 DAL 相关的Java代码小工具
- 第十周学习进度表
- 常用清除浮动样式
- 基于keepalived实现nginx的高可用
- Dubbo项目实战初探(一)
- 四大湖问题
- net WebApi中使用swagger
- Java中流的概念
- 管道与IO重定向之输出重定向
- Log
- 自定义控件 AnimationView 动画View
- 事务传播行为种类
- ARC 的实现