创建Circle.h文件和Circle.cpp文件
Circle.h文件
#pragma once
class Circle
{
public:
void setR(double r);
double getR();
double getArea();
double getGirth();
private:
double m_r;
double m_area;
double m_girth;
};
Circle.h文件
#include "Circle.h"
void Circle::setR(double r) {
m_r = r;
}
double Circle::getR() {
return m_r;
}
double Circle::getArea() {
return m_area = m_r * m_r * 3.14;
}
double Circle::getGirth() {
return m_girth = 2 * m_r * 3.14;
}
main.cpp文件
#include<iostream>
#include"Circle.h"
using namespace std;
int main(void) {
Circle c;
c.setR(10);
cout << "面积" << c.getArea() << endl;
return 0;
}