circle classes

ok so im suppose to Construct a class Circle with data member radius and methods to initialize the radius to 1.0 change the value of the radius; c) calculate the circumference of the circle; d)calculate the area of the circle; and e)show the value of the radius. them im suppose to declare two objects circle1 and circle2, change the value of the radius of circle2, show the value of circle2 , calculate the circumference of circle1 and display the result in main; and calculate the area of circle2 and display the result in main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  #include <iostream>
#include "circleClass.h"

using namespace std;

int main()


{
  double mycircle;
  double rad;

  cout<<"Please enter a new radius"<<endl;
  cin>>rad;

  mycircle.setradius(rad);
  mycircle.print();

  system("pause");
  return 0;
}

#include <iostream>
using namespace std;

class circleClass
{
 private:
  double radius;
 public:
   circleClass();
  circleClass(double r);
  ~circleClass();
  void setradius(double r);
  double getradius();
  double area();
  double circum();
  double diameter();
  void print();

};


#include <iostream>
#include "circleClass.h"

using namespace std;

const double PI = 3.14159;
circleClass::circleClass()
{
  radius = 1.0;
}
circleClass::circleClass(double rad)
{
  if (rad<=0)
    {
      cout << "An invalid radius has been detected. " <<endl;
      cout << "The radius has been set to 1.0"<<endl;
      radius = 1.0;
    }
  else
    radius =rad;
}

circleClass::~circleClass()
{
  cout << "A circle died"<<endl;
}
void circleClass::setradius(double r)
{
  radius =rad;
}
double circleClass::getradius()
{
  return radius;
}
double circleClass::area()
{
  return (PI * (radius*radius));
}
double circleClass::circum()
{
  return (2 * PI * radius);
}
double circleClass::diameter()
{
  return (2 * radius);
}
void circleClass::print()
{
  cout <<"The info for the circle is as follows"<<endl;
  cout <<"Radius = "<<radius<<endl;
  cout <<"Diameter = "<<diameter()<<endl;
  cout <<"Area = " <<area()<<endl;
  cout <<"Circumference = "<<circum()<<endl;


}

this is what i have so far but i keep getting errors and i dont understand how to do the two circles please help
The identifier "rad" in circleClass::setradius() should be "r"
"mycircle" in main should be a circleClass object, not a double.
ok thanks I got it to work but now can you help me understand the two objects with circle 1 and circle 2 please
These are the six steps that you need to take, as I have understood them based on the information you provided:

1.) declare two objects (circle1 and circle2)

2.) change the value of circle2 radius

3.) show the value(?) of circle2

4.) calculate circle1 circumference

5.) call circle1.print()

6.) call circle2.print()

If you would elaborate on what you mean with "show the value of circle2", I could help you further. Although, this is as straight forward as it gets. What exactly is it that's confusing you?
all i need to do is show the answer to circle two like rge radius that i get and im confused because when i run the program i get this
Please enter a new radius
2
The info for the circle is as follows
Radius = 2
Diameter = 4
Area = 12.5664
Circumference = 12.5664
so does that count as one of the cirlces or do i have to do two other separate circles doing the same thing because i get the circumference and the area already.
Last edited on
i also dont understand how to change the value of the radius of circle2 and show both circle 1 and 2 into main
Last edited on
im really having trouble calling them and doing this part of the assignment
Topic archived. No new replies allowed.