面向对象程序设计_课堂作业_01_Circle

The 1st classwork of the C++ program

题目:
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.
github链接:Click Here

看着英文题目好虚...不过题目还是挺简单的,就是求所输入半径的圆的面积,用到cin和cout,并把函数定义为外部函数,代码如下:

Circle.h

#pragma once
#include <cmath>
const double PI = acos(-1);

/*extern*/ double CircleArea(double r);

Circle.cpp

#include "Circle.h"

double CircleArea(double r)
{
	return PI * r * r;
}

main.cpp

#include <iostream>
#include "Circle.h"
using namespace std;

int main()
{
	double r;
	cout << "Please input the radius of a circle : " << endl;
	cin >> r;
	cout << "The erea of this circle is : " << endl;
	cout << CircleArea(r) << endl;

//	system("pause");
	return 0;
}

这样子就over了,在main函数里面还心虚的加了提示信息...毕竟第一次作业,完满的画上句号...画上句号。

posted @ 2016-05-05 23:06  酒晓语令  阅读(159)  评论(0编辑  收藏  举报