首页 > 技术文章 > 第一次随堂作业

zxlmhh 2016-05-05 23:45 原文

题目:Creat a program that asks for the radius of a cricle and prints the area of that cricle.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.
大意是创建两个.cpp文件来计算一个圆的面积,也就是其中的一个文件去调用另一个文件,另一个文件其实就相当于一个函数,用来输出。

以下是代码


cin.cpp文件

#include<iostream>
#include "cout.cpp"
using namespace std;

int main()
{
	double r;
	cin>>r;
	calculate(r);
	return 0;
}


cout.cpp文件

#include<iostream>
using namespace std;
 
#define pi 3.1415926

void calculate(double r)
{
    cout<<pi*r*r<<endl;
} 

推荐阅读