Hello, I started C++ and I have a trouble with this thing. I can't make it work. What I am trying to do is to get the value and calculate the area of a circle using a class type of coding style.
Note that this does not even compile.
"Where should i put the cin"

#include <iostream>

using namespace std;

const double Pi = 3.1415;

class master
{
	private:
		double radius;
	public:
		void setvalue(double);
		double getvalue();
		double area(double);

};
void master :: setvalue(double a)
{
	radius = a;
};
double master :: getvalue()
{
	return radius;
};

double master :: area(radius)
{
	return Pi * radius * radius;
}
int main()
{
	master z01;
	cout << "Please Enter A Radius \n";
	cout << "Press <ENTER> to end... " << endl;
	fflush(stdin);
	cin.get();
}

Recommended Answers

All 2 Replies

Sorry, now it compiles, but I need to add a cin somewhere.

#include <iostream>

using namespace std;

const double Pi = 3.1415;

class master
{
	private:
		double radius;
	public:
		void setvalue(double);
		double getvalue();
		double area(double);

};
void master :: setvalue(double a)
{
	radius = a;
};
double master :: getvalue()
{
	return radius;
};

double master :: area(double radius)
{
	return Pi * radius * radius;
}
int main()
{
	master z01;
	cout << "Please Enter A Radius \n";
	cout << "Press <ENTER> to end... " << endl;
	fflush(stdin);
	cin.get();
}
using namespace std; // don't
 
const double Pi = 3.1415; // why not 3.1416 (3.14159)
int main() {
  master z01;
  double r;
  std::cout << "Please Enter A Radius \n";
  std::cin >> r;
  z01.setvalue(r); // setvalue is really ambiguous, consider changing function name
  std::cout << "The area is: " << z01.area() << std::endl;
  std::cout << "Press <ENTER> to end... " << std::endl;
  fflush(stdin); // consider removing these 2 lines and making the above a loop
  std::cin.get();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.