In this exercise, we will either have a circle inside a polygon for which we will calculate the circumference, or we shall have a polygon inside a circle for which we will calculate its perimeter (circumference). You are required to write a program that accepts one of two strings: • "CC" which refers to the case Circle Circumference. • "PP" which refers to the case Polygon Perimeter. If the user chooses CC, then the program waits for the user to input the number of sides of the polygon first, then the length of one of its sides. It outputs the circumference of the largest circle that can fit inside this polygon. If the user chooses PP, then the program waits for the user to input the number of sides of the polygon first, then the radius of the circle. It outputs the circumference of the largest polygon that fits inside the circle.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
#include #include #include #include #include using namespace std; int main (){ const double PI = 3.14159265359; return 0; }
In this exercise, we will either have a circle inside
a polygon for which we will calculate the
circumference, or we shall have a polygon inside
a circle for which we will calculate its perimeter
(circumference).
You are required to write a program that accepts
one of two strings:
• "CC" which refers to the case Circle
Circumference.
• "PP" which refers to the case Polygon
Perimeter.
If the user chooses CC, then the program waits
for the user to input the number of sides of the
polygon first, then the length of one of its sides. It
outputs the circumference of the largest circle
that can fit inside this polygon.
If the user chooses PP, then the program waits
for the user to input the number of sides of the
polygon first, then the radius of the circle. It
outputs the circumference of the largest polygon
that fits inside the circle.
M
E
A circle inside a hexagon (polygon with 6 sides)
An octagon (polygon with 8 sides) inside a circle
Hint: To solve this program, it might be easier to
divide the polygon into triangles all connected at
the center. This way, as you already know the
number of sides of the polygon, you can derive
the angles, and use basic geometry and
trigonometry to solve this question.
Transcribed Image Text:In this exercise, we will either have a circle inside a polygon for which we will calculate the circumference, or we shall have a polygon inside a circle for which we will calculate its perimeter (circumference). You are required to write a program that accepts one of two strings: • "CC" which refers to the case Circle Circumference. • "PP" which refers to the case Polygon Perimeter. If the user chooses CC, then the program waits for the user to input the number of sides of the polygon first, then the length of one of its sides. It outputs the circumference of the largest circle that can fit inside this polygon. If the user chooses PP, then the program waits for the user to input the number of sides of the polygon first, then the radius of the circle. It outputs the circumference of the largest polygon that fits inside the circle. M E A circle inside a hexagon (polygon with 6 sides) An octagon (polygon with 8 sides) inside a circle Hint: To solve this program, it might be easier to divide the polygon into triangles all connected at the center. This way, as you already know the number of sides of the polygon, you can derive the angles, and use basic geometry and trigonometry to solve this question.
IMPORTANT NOTE
• The circle and the polygon share the
same center.
• At all times, the sides of the circle and
polygon touch each other.
• The number of polygon sides must
never be less than five; otherwise, the
program outputs invalid.
• The radius and the length of a polygon
side must be positive; otherwise, the
program outputs invalid.
• For any other wrong input, the
program outputs invalid.
• The result must only keep the first two
decimal digits with rounding.
• Circumference and perimeter mean
the same thing.
• Do not add any cout statements
except for the final answer as specified
above.
• Do not add "Enter a nurmber", or any
similar prompts.
• Also note that the automatic grader is
case-sensitive; so "Invalid" is wrong
but "invalid" is correct.
• You may add any librarles needed.
I/0
Program Input:
• A single line that takes in a string value
to determine which shape to calculate
the circumference for.
• A single line that takes in the number
of polygon sides
• A single line that depending on the
case takes in either the circle radius or
the polygon side length.
Program Output:
• A single line that outputs either the
circumference of the circle or the
polygon perimeter rounded to th
nearest two digits.
Sample Testcase 0:
Input:
CC
6
1.5
Output:
8.16
Sample Testcase 1:
Input:
PP
Output:
18.47
Sample Testcase 2:
Input:
PP
3
10
Output:
invalid
Transcribed Image Text:IMPORTANT NOTE • The circle and the polygon share the same center. • At all times, the sides of the circle and polygon touch each other. • The number of polygon sides must never be less than five; otherwise, the program outputs invalid. • The radius and the length of a polygon side must be positive; otherwise, the program outputs invalid. • For any other wrong input, the program outputs invalid. • The result must only keep the first two decimal digits with rounding. • Circumference and perimeter mean the same thing. • Do not add any cout statements except for the final answer as specified above. • Do not add "Enter a nurmber", or any similar prompts. • Also note that the automatic grader is case-sensitive; so "Invalid" is wrong but "invalid" is correct. • You may add any librarles needed. I/0 Program Input: • A single line that takes in a string value to determine which shape to calculate the circumference for. • A single line that takes in the number of polygon sides • A single line that depending on the case takes in either the circle radius or the polygon side length. Program Output: • A single line that outputs either the circumference of the circle or the polygon perimeter rounded to th nearest two digits. Sample Testcase 0: Input: CC 6 1.5 Output: 8.16 Sample Testcase 1: Input: PP Output: 18.47 Sample Testcase 2: Input: PP 3 10 Output: invalid
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY