C ++: class and object 2 (circumference and area of the circle)
Time limit (Common/Java): 1000 ms/3000 Ms running memory limit: 65536 Kbyte
Total submissions: 1038 pass the test: 524
Description
Write a program using the class, enter the radius of the circle, and calculate and display the circumference and area of the circle. Circumference rate: 3.14
Input
The input contains N groups of test instances. Row 1st is the number of test groups.
Row 10-row n + 1 test data. Each group of test data has a real number, indicating the radius of the circle.
Output
The circumference and area of the circle (retain 2 decimal places ).
Sample Input
3
4.5
14.6
5.5
Sample output
28.26 63.59
91.69 669.32
34.54 94.98
# Include <iostream. h>
# Include <iomanip. h>
Class circle
{
Double R;
Public:
Circle (Double X)
{R = x ;}
Void disp ()
{
Cout <fixed <setprecision (2 );
Cout <3.14 * r * 2 <"" <3.14 * r <Endl;
}
};
Int main (INT argc, char * argv [])
{
Int N;
Double R;
Cin> N;
While (n --)
{
Cin> r;
Circle C (R );
C. disp ();
}
}
**************************************** * ************* 8
# Include <iostream. h>
# Include <iomanip. h>
Class circle
{
Double R, C, S;
Public:
Circle (Double X)
{R = x; C = 3.14 * r * 2; S = 3.14 * r ;}
Void disp ()
{
Cout <fixed <setprecision (2 );
Cout <C <"<S <Endl;
}
};
Int main (INT argc, char * argv [])
{
Int N;
Double R;
Cin> N;
While (n --)
{
Cin> r;
Circle C (R );
C. disp ();
}
}