Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- const double cot = 1/tan(M_PI/7) ;
- double HeptagonArea(double EdgeLength)
- {
- return 7*pow(EdgeLength, 2)*cot/4 ;
- }
- double CircleArea(double radius)
- {
- return M_PI*pow(radius, 2) ;
- }
- bool ApproxEqual(double first, double second, double eps=1e-5)
- {
- return abs(first-second) < eps ;
- }
- int main()
- {
- double elength ;
- double r ;
- cout << "Please enter the edge length of heptagon: " ;
- cin >> elength ;
- cout << "Please enter the radius of circle: " ;
- cin >> r ;
- cout << "The area of given heptagon is: " << HeptagonArea(elength) << " and the are of given circle is: " << CircleArea(r) << endl;
- if (!ApproxEqual(HeptagonArea(1), 3.63391))
- cout << "Oops! Heptagon area(1) != 3.63391\n" ;
- if (!ApproxEqual(HeptagonArea(5), 90.8478, 1e-4))
- cout << "Error! Heptagon area(5) != 90.8478\n" ;
- if (!ApproxEqual(HeptagonArea(10), 363.391, 1e-3))
- cout << "Wrong! Heptagon area(10) != 363.391\n" ;
- if (!ApproxEqual(CircleArea(1), 3.14159))
- cout << "Oh no! Circle area(1) != 363.391\n" ;
- if (!ApproxEqual(CircleArea(5), 78.5398, 1e-4))
- cout << "Stop! Circle area(5) != 363.391\n" ;
- if (!ApproxEqual(CircleArea(10), 314.159, 1e-3))
- cout << "It would seem something is not quite right! Circle area(10) != 314.159\n" ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement