C++ Assignment: Octagon Geometry

Thu Aug 14 2025
Updated: Fri Aug 15 2025
Facebook share linkTwitter/X share linkLinkedIn share linkReddit share linkReddit share link

Problem Description

A sign company that creates roadway signs has enlisted your help to write a program to help them calculate how much vinyl they will need for their signs. Specifically, the company needs to know some information on signs in the shape of octagons, such as stop signs.

For this assignment, write a program that:

  1. Asks for the side length of the octagon, and reads the side length into a floating-point variable in main memory.
  2. Calculates the area of the octagon using the formula below, then saves that value into a floating-point variable in main memory. You will need to use <cmath> to perform this calculation.
  3. Calculates the circumcircle radius of the octagon using the formula below, then saves that value into a floating-point variable in main memory. You will need to use <cmath> to perform this calculation.
  4. Calculates the incircle radius of the octagon using the formula below, then saves that value into a floating-point variable in main memory. You will need to use <cmath> to perform this calculation.
  5. Outputs the values from the steps above in the format of the formatting example below. The <iomanip> library will need to be used to properly match the formatting.

Formulas

Area of an octagon:

AREA=2a2(1+2)AREA = 2 * a^2 * (1 + √2)

Circumcircle radius of an octagon:

RADIUSc=(1/2a)(4+22)RADIUS_c = (1/2 * a) * √(4 + 2√2)

Incircle radius of an octagon:

RADIUSi=(1/2a)(1+2)RADIUS_i = (1/2 * a) * (1 + √2)

Input/Output Formatting

Input/Output should be displayed in the following manner (matching the output exactly):

Enter octagon's side length: 10.5 +--------------+--------------+--------------+--------------+ | side length | area | circumcircle | incircle | +--------------+--------------+--------------+--------------+ | 10.50 | 532.33 | 13.72 | 12.68 | +--------------+--------------+--------------+--------------+

See CodeGrade for more examples.

Note: The line breaks after the inputs in the example output formatting above are the default ones C++’s cin and getline() automatically apply after reading an input from the user. CodeGrade supplies input in a different manner (Linux redirection) to programs so in CodeGrade's auto tests there will not be line breaks after the inputs.


Table Formatting Tips

As with every assignment your output must match CodeGrade perfectly. Below are some tips to help match the formatting:

  1. The columns of the table should be left aligned.
  2. The headers rows can just be output as strings and the same separator can be used in both tables. The separator is:
+--------------+--------------+--------------+--------------+
  1. The ends of the row with numerical outputs and separator between data pieces are produced by outputting: "| ", " | ", or " |". (The | is a pipe, not a lowercase l or capital I).
  2. Each numerical value should be output with a width of 12.
  3. The default fill should be used.
  4. All numerical values should be output in fixed point notation.
  5. All numerical values should be output with a precision of 2.

Submission Instructions

  1. Save: Save your code as main.cpp. Do not ignore this step or save your file(s) with different names.

  2. Submit: Your program source code must be submitted via CodeGrade as a properly named .cpp file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.