rishamessi (22) Nov 21, 2009 at 9:35pm UTC
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
# include <iostream>
using namespace std ;
class Circle {
private :
static const float pi=3.142 ;
float radius ;
public :
void setRadius ( float ) ;
float getArea () ;
};
void Circle::setRadius( float r)
{
radius = r ;
}
float Circle::getArea()
{
return pi * radius * radius ;
}
int main ()
{
Circle* circles ;
int numberOfCircles ;
float r ;
cout << "Enter Number of Circles : " ;
cin >> numberOfCircles ;
cout << endl << endl ;
circles = new Circle [ numberOfCircles ] ;
for ( int i=0 ; i < numberOfCircles ; i ++ )
{
cout << "Enter radius of Circle " << i+1 << " : " ;
cin >> circles.setRadius(r)[i] ;
cout << endl ;
}
system("pause" ) ;
return 0 ;
}
Last edited on Nov 21, 2009 at 9:35pm UTC
rishamessi (22) Nov 21, 2009 at 9:35pm UTC
there is an error in line 38
what is the error ?????????????????????????????
Bazzy (3180) Nov 21, 2009 at 9:35pm UTC
That line doesn't make sense at all, you should have
rishamessi (22) Nov 21, 2009 at 9:35pm UTC
Thank you Bazzy
really thanks
rishamessi (22) Nov 21, 2009 at 9:35pm UTC
i want this prog to give the same output of the pervious one but i didnt want an array of Circles i want array of float can any one help me ?
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
# include <iostream>
using namespace std ;
class StaticCircle {
private :
static const float pi = 3.142 ;
public :
static float getArea ( float ) ;
};
static float StaticCircle::getArea( float r )
{
return r * r * pi ;
}
int main ()
{
int numberOfCircles ;
cout << "Enter Number of Circle : " ;
cin >> numberOfCircles ;
StaticCircle circle ;
float raduis[numberOfCircles] ;
for ( int i = 0 ; i <numberOfCircles ; i++ )
{
cout << "Enter radius of Circle " << i+1 << " : " ;
cin >> raduis[i] ;
}
for ( int i=0 ; i < numberOfCircles ; i ++ )
{
cout << circle.getArea(i);
}
system("pause" ) ;
return 0 ;
}
Last edited on Nov 21, 2009 at 9:35pm UTC
Bazzy (3180) Nov 21, 2009 at 9:35pm UTC
Line 24: you should have a dynamic array there ( not a fixed-size one )
rishamessi (22) Nov 21, 2009 at 9:35pm UTC
i want to use an array of floats
rishamessi (22) Nov 21, 2009 at 9:35pm UTC
instead of array of Circles i want to use array of floats can i do this ?
Bazzy (3180) Nov 21, 2009 at 9:35pm UTC
You can but you need a dynamic array ( or a std:: container )