## jtylerboy222

Creating a program with a circle class that has 3 private variables and 3 public functions and then have accessor & mutator functions.

I know this isn't right, but I've gone through the book and my notes and I feel like I've mixed up a few ways of doing it and combined it together...just need a little guidance from where I'm at now.

This is what I have so far.

``````#include <iostream>
using namespace std;

const float PI = 3.14;

class Circle
{
public:
double CalculateArea();
double CalculateCircumference();
void DisplayOutPut();

private:
double circumference;
double area;
};

int main()
{
Circle myCircle;
myCircle.CalculateArea;
myCircle.CalculateCircumference;
myCircle.DisplayOutPut;

}
{
}
double Circle::CalculateArea()
{
}
double Circle::CalculateCircumference()
{
}
void Circle::DisplayOutPut();
{
cout << "Circumference: " << circumference << endl;
cout << "Area: " << area << endl;
}``````

## firstPerson 761

Your function delcared with a return type of double should return a double.

Here is what you should do :

``````double Circle::getArea(){ return _area; }
double Circle::getCircumference(){ return _circumference; }``````

``````Circle::Circle(float radius){
}``````

## jtylerboy222

I don't understand...

does this go in my class?

``````double Circle::getArea(){ return _area; }
double Circle::getCircumference(){ return _circumference; }``````

and I am not using constructors...

``````Circle::Circle(float radius){
}``````

## firstPerson 761

The point is to use the constructors. Its there exactly for this job, to initialize
things. Not using it is just a bad and redundant idea.

## griswolf 304

@firstPerson: Disagree that you need to greedy calculate the various things about the circle: If the program never uses that information, it was a waste of space and CPU. Minimize... Of course, once the program uses it, it might be cached to avoid re-calculate (or not: A simple multiply is very inexpensive)... of course you are correct if the class really does have those three data members: I'm suggesting that it should not.

When you design a Circle, you think: "What does a Circle need to know about itself?" and the minimum answer is very often the right one: It needs a radius (and probably a center point).

@jtylerboy222: You are using constructors: The default that the language gives you (which approximately zero-initializes class members). And yes, you need to both declare class member functions and provide the implementations of them (define them). Definitions can be inline in the header file, or out of line in a file that will be compiled to object file and later linked, when used.

## firstPerson 761

@griswolf:

You really shouldn't have to worry about pre-optimizations. This is will not affect
the program. And for the record, if Area() is called a lot, then the function calculateArea() will be more expensive than if it were already pre calculated.

## jtylerboy222

It may be better to use constructors, but the assignment says NOT to use them.

## kes166 37

You don't need one, it auto initializes everything.

``````double getRadius();
double CalculateArea();
double CalculateCircumference();``````

You need a return statement in each one of those. Also, you need to assign what is returned to a variable. I think if it errors or gives a warning is dependant on what compiler you use. In your main, you don't assign the returned value to anything. change CaluclateArea and CalculateCircumference to voids.

I also think you need

``myCircle = new Circle;``

Do you get any errors when you compile or run?

Edit:

## jtylerboy222

Got it.

``````#include <iostream>
using namespace std;
const double PI = 3.14;
class Circle
{
public:
double CalculateArea();
double CalculateCircumference();
void DisplayOutPut();
private:
double circumference;
double area;
};
int main()
{
Circle myCircle;
myCircle.CalculateArea();
myCircle.CalculateCircumference();
myCircle.DisplayOutPut();
}
{
}
{
}
double Circle::CalculateArea()
{