0

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();
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Unimportant
0

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();
}
0
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();
}

Edited by Unimportant: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.