CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Jul 2011
    Posts
    5

    calculate dimensions of a circle in c++

    Code:
    #ifndef CIRCLE_H
    #define CIRCLE_H
    
    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;
    }
    The function isBigger() returns true (or false) if the radius of the Circle instance on which the function is invoked is bigger (or smaller) than the radius of the Circle instance passed to the function.: Can someone help me to implement this function?
    Last edited by annitaz; July 4th, 2013 at 03:48 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured