SHARE
TWEET

Untitled

a guest Oct 21st, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. const double cot = 1/tan(M_PI/7) ;
  7.  
  8. double HeptagonArea(double EdgeLength)
  9. {
  10.     return 7*pow(EdgeLength, 2)*cot/4 ;
  11. }
  12.  
  13. double CircleArea(double radius)
  14. {
  15.     return M_PI*pow(radius, 2) ;
  16. }
  17. bool ApproxEqual(double first, double second, double eps=1e-5)
  18. {
  19.     return abs(first-second) < eps ;
  20. }
  21. int main()
  22. {
  23.     double elength ;
  24.     double r ;
  25.     cout << "Please enter the edge length of heptagon: " ;
  26.     cin >> elength ;
  27.     cout << "Please enter the radius of circle: " ;
  28.     cin >> r ;
  29.     cout << "The area of given heptagon is: " << HeptagonArea(elength) << " and the are of given circle is: " << CircleArea(r) << endl;
  30.  
  31.     if (!ApproxEqual(HeptagonArea(1), 3.63391))
  32.         cout << "Oops! Heptagon area(1) != 3.63391\n" ;
  33.     if (!ApproxEqual(HeptagonArea(5), 90.8478, 1e-4))
  34.         cout << "Error! Heptagon area(5) != 90.8478\n" ;
  35.     if (!ApproxEqual(HeptagonArea(10), 363.391, 1e-3))
  36.         cout << "Wrong! Heptagon area(10) != 363.391\n" ;
  37.  
  38.     if (!ApproxEqual(CircleArea(1), 3.14159))
  39.         cout << "Oh no! Circle area(1) != 363.391\n" ;
  40.     if (!ApproxEqual(CircleArea(5), 78.5398, 1e-4))
  41.         cout << "Stop! Circle area(5) != 363.391\n" ;
  42.     if (!ApproxEqual(CircleArea(10), 314.159, 1e-3))
  43.         cout << "It would seem something is not quite right! Circle area(10) != 314.159\n" ;
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top