github链接:
https://github.com/deepYY/object-oriented/tree/master/Circle
作业题目
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 shouldbedividedinto two source files (.cpp). Hand in the source files and the head files which youcreate
代码如下
main.cpp
#include <iostream>
#include<stdlib.h>
#include "circle_area.h"
using namespace std;
int main(int argc, char** argv)
{
double r,area;
Circle_area ca;
cin >> r;
area = ca.get_area(r);
cout << "S=" << area << endl;
return 0;
}
circle_area.h
#ifndef CIRCLE_AREA_H
#define CIRCLE_AREA_H
#define pi 3.14
#include <iostream>
class Circle_area
{
public:
double get_area(double r);
};
#endif
circle_area.cpp
#include "circle_area.h"
#include<stdlib.h>
#include <iostream>
double Circle_area::get_area(double r)
{
return (r*r*pi);
}