C++作业:Circle_area
Github链接: Circle_area
代码:
main.cpp
#include "circle_area.h"
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int main()
{
double r;
Circle_area area;
r = area.Input();
double s;
s = area.Calculate(r);
cout << "The circle's area is : " << setprecision(4) << s << endl;
return 0;
}
Circle_area.h
#ifndef CIRCLE_AREA_H
#define CIRCLE_AREA_H
#include <cstdio>
#include <iostream>
#define pi 3.1415926
using namespace std;
/*
* C++随堂作业
* 学号: 031502209
* 姓名: 陈翔
*
* 作业目的: 输入圆的半径,输出圆的面积。
*/
class Circle_area
{
public:
double Input();
double Calculate(double r);
};
#endif // CIRCLE_AREA_H
Circle_area.cpp
#include "circle_area.h"
#include <iostream>
#include <cstdio>
#include <stdlib.h>
using namespace std;
/*
* Input():
* 用于输入圆的半径的方法。
*/
double Circle_area :: Input()
{
double r;
cout << "Please input the radius of a circle : ";
cin >> r;
return r;
}
/*
* Calculate():
* 用于计算圆的面积的方法。
*/
double Circle_area :: Calculate(double r)
{
double S = 0;
S = pi*r*r;
return S;
}
To improve is to change, to be perfect is to change often.