C ++: overload function 2 (calculated area)
Time limit (Common/Java): 1000 ms/3000 Ms running memory limit: 65536 Kbyte
Total submissions: 370 pass the test: 241
Description
Defines the overload function area () to calculate the area of the square, rectangle, and triangle respectively.
Input
There are 3 rows in total.
There is a real number in the row 1st, which is the side length of the square;
The second row has two real numbers, which are the two sides of the rectangle;
The fifth row has three real numbers, which are the three sides of the triangle.
Output
Area of a square, rectangle, or triangle (with three decimal places retained ).
Sample Input
3.5
4.2 5.62
3.0 4.0 5.0
Sample output
12.250
23.604
6.000
# Include <iostream>
# Include <iomanip>
# Include <cmath>
Using namespace STD;
Double area (double)
{
Return a *;
}
Double area (double A, double B)
{
Return a * B;
}
Double area (double A, double B, double C)
{
Double S;
S = (A + B + C)/2;
Return SQRT (S * (S-A) * (S-B) * (s-c ));
}
Int main ()
{
Double A, B1, B2, C1, C2, C3;
Cin>;
Cin> B1> B2;
Cin> C1> c2> C3;
Cout <fixed <setprecision (3) <area (a) <Endl;
Cout <fixed <setprecision (3) <area (b1, b2) <Endl;
Cout <fixed <setprecision (3) <area (C1, C2, C3) <Endl;
Return 0;
}
# Include <iostream>
# Include <iomanip>
# Include <cmath>
Using namespace STD;
Int main ()
{
Double A, B, C, D, E, F, T;
Double S1, S2, S3;
Cin> A> B> C> D> E> F;
S1 = A *;
S2 = B * C;
T = (D + E + F)/2;
S3 = SQRT (T * (t-d) * (t-e) * (t-f ));
Cout <fixed <setprecision (3) <S1 <Endl;
Cout <fixed <setprecision (3) <S2 <Endl;
Cout <fixed <setprecision (3) <S3 <Endl;
Return 0;
}