calculate dimensions of a circle in c++

Page 1 of 1

9 Replies - 1237 Views - Last Post: 04 July 2013 - 03:42 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=324183&amp;s=3f5f5eee3e81f561943ff71eee5cd98b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 annitaz

Reputation: 0
• Posts: 16
• Joined: 09-January 10

calculate dimensions of a circle in c++

Posted 03 July 2013 - 04:08 PM

```#ifndef CIRCLE_H
#define CIRCLE_H
#include <QString>
#include <string>
using namespace std;

class Circle {
public:
//constructors
Circle();
Circle(double r);
//setter
//getter
//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
};

#endif // CIRCLE_H

```

```#include "circle.h"
#include "math.h"
#include <iostream>
#include <QString>
#include <sstream>
using namespace std;

Circle::Circle()
{
}

Circle::Circle(double r)
{
}

}

}

double Circle::computeDiameter()const{
}

double Circle::computeArea()const {
}

double Circle::computeCircumference()const {
}

```

```#include <iostream>
#include <QTextStream>
#include "circle.h"
using namespace std;

int main(){
QTextStream cout(stdout);

Circle c1,c2;     // input

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.: I have no idea how to implement this function. Can someone explain this in simple english?

Is This A Good Question/Topic? 0

Replies To: calculate dimensions of a circle in c++

#2 jimblumberg

Reputation: 4733
• Posts: 14,757
• Joined: 25-December 09

Re: calculate dimensions of a circle in c++

Posted 03 July 2013 - 04:15 PM

Quote

Can someone explain this in simple english?

You've already explained what you need in plain English? What exactly don't you understand?

Jim

#3 annitaz

Reputation: 0
• Posts: 16
• Joined: 09-January 10

Re: calculate dimensions of a circle in c++

Posted 03 July 2013 - 04:57 PM

my question is: which is the radius of the Circle instance on which the function is invoked and which is the the radius of the Circle instance passed to the function?

#4 annitaz

Reputation: 0
• Posts: 16
• Joined: 09-January 10

Re: calculate dimensions of a circle in c++

Posted 03 July 2013 - 05:06 PM

I don't understand how to implement the isBigger function

#5 jimblumberg

Reputation: 4733
• Posts: 14,757
• Joined: 25-December 09

Re: calculate dimensions of a circle in c++

Posted 03 July 2013 - 06:22 PM

Quote

my question is: which is the radius of the Circle instance on which the function is invoked and which is the the radius of the Circle instance passed to the function?

Since this function is a class member function one instance will be the current instance and the other will be passed as the parameter other.

Jim

#6 annitaz

Reputation: 0
• Posts: 16
• Joined: 09-January 10

Re: calculate dimensions of a circle in c++

Posted 03 July 2013 - 10:51 PM

do u mean circle1 and circle2? something like

```if c1.m_Radius>c2.m_radius then c1.isBigger(c2) else c2.isBigger(c1)?
```

#7 #define

• Duke of Err

Reputation: 1632
• Posts: 5,751
• Joined: 19-February 09

Re: calculate dimensions of a circle in c++

Posted 04 July 2013 - 12:15 AM

annitaz, on 04 July 2013 - 12:57 AM, said:

my question is: which is the radius of the Circle instance on which the function is invoked and which is the the radius of the Circle instance passed to the function?

If you have :

```int main()
{
Circle circle_A(1);
Circle circle_B(2);

if( circle_A.isBigger( circle_B ) )
cout << "circle A is bigger"  << endl;
else
cout << "circle B is bigger"  << endl;

return(0);
}

```

Relating it to the above code the function looks like

```bool Circle::isBigger(const Circle& other) const
{
// the object that the function belongs to is circle A
// the object parameter called other, is circle B
}

```

#8 annitaz

Reputation: 0
• Posts: 16
• Joined: 09-January 10

Re: calculate dimensions of a circle in c++

Posted 04 July 2013 - 02:23 AM

Is this correct?

```bool Circle::isBigger(const Circle& other) const
{
}

```

#9 annitaz

Reputation: 0
• Posts: 16
• Joined: 09-January 10

Re: calculate dimensions of a circle in c++

Posted 04 July 2013 - 02:42 AM

I added this code in main

```if(c1.isBigger(c2))
cout << "circle 1 is bigger"  << endl;
else
cout << "circle 2 is bigger"  << endl;
```

and it works. What do u think? The function is:

```bool Circle::isBigger(const Circle& other) const {
}
```

• Saucy!

Reputation: 6219
• Posts: 23,965
• Joined: 23-August 08

Re: calculate dimensions of a circle in c++

Posted 04 July 2013 - 03:42 AM