#ifndef CIRCLE_H
#define CIRCLE_H
#include <QString>
#include <string>
using namespace std;
class Circle {
public:
//constructors
Circle();
Circle(double r);
//setter
void setRadius(double r);
//getter
double getRadius();
//calculate the diameter of a circle
double computeDiameter()const;
//calculate the area of a circle
double computeArea()const;
//calculate the Circumference of a circle
double computeCircumference()const;
//checks if radius of circle is bigger
**bool isBigger(const Circle& other) const;**
private:
//private data members
double m_Radius;
};
#endif // CIRCLE_H
#include "circle.h"
#include "math.h"
#include <iostream>
#include <QString>
#include <sstream>
using namespace std;
Circle::Circle()
{
m_Radius = 0;
}
Circle::Circle(double r)
{
m_Radius = r;
}
void Circle::setRadius(double r){
m_Radius = r ;
}
double Circle::getRadius(){
return m_Radius;
}
double Circle::computeDiameter()const{
return 2* m_Radius;
}
double Circle::computeArea()const {
return ( m_Radius* m_Radius*M_PI);
}
double Circle::computeCircumference()const {
return (2* m_Radius*M_PI);
}
#include <iostream>
#include <QTextStream>
#include "circle.h"
using namespace std;
int main(){
QTextStream cout(stdout);
Circle c1,c2; // input
c1.setRadius(3);
c2.setRadius(7);
cout << "Circle with radius " << c1.getRadius() << " has: " << endl;
cout<< "Diameter " << c1.computeDiameter() << " cm " <<endl;
cout<< "Area " << c1.computeArea() << " cm" <<endl;
cout<< "Circumference " << c1.computeCircumference()<< " cm " <<endl<<endl;
cout << "Circle with radius " << c2.getRadius() << " has: " << endl;
cout<< "Diameter " << c2.computeDiameter() << " cm " <<endl;
cout<< "Area " << c2.computeArea() << " cm" <<endl;
cout<< "Circumference " << c2.computeCircumference()<< " cm " <<endl<<endl;
return 0;
}
如果调用函数的 Circle 实例的半径大于(或小于)传递给函数的 Circle 实例的半径,则函数 isBigger() 返回 true(或 false)。: 我不知道如何实现这个功能。有人可以用简单的英语解释一下吗?