C++: Shapes program: read data from txt,calculate area, perimeter,Write results to txt and the console screen

Relax! Stop worrying about deadlines and let our professional writers help you. Hire an essay writer helper and receive a professional assignment before your deadline. We provide writing services for all types of academic assignments.


Order a Similar Paper Order a Different Paper

The Shapes Program

Write a C++ program named shapes.cpp to calculate area, perimeter, surface area, and volume of common 2D and 3D shapes. The calculations for 7 shapes include:

area and perimeter of a square

area and perimeter of a rectangle 

area and perimeter of a circle

area and perimeter of an equilateral triangle 

  • surface area and volume of a cube
  • surface area and volume of a box
  • surface area and volume of a cylinder
  • NOTE: The “perimeter” of a circle is more commonly referred to as “circumference”, but we’re calling it perimeter.
  • See http://www.purplemath.com/modules/geoform.htm (Links to an external site.) for a primer on these calculations.
  • INPUT:  Copy-and-paste this data into your input file (please name it “shapes.txt”) — this is the exact data set that I’ll use to evaluate your code:
  • CIRCLE 3.2 0 0
    SQUARE 4.6 0 0
    TRIANGLE 12.5 0 0
    RECTANGLE 12.4 53.2 0
    SPHERE 12.2 0 0
    PYRAMID 14.2 6.34 0
    BOX 12.2 13.3 14.4
    SQUARE 14.5 0 0
    SQUARE 0 0 0
    RECTANGLE 14.5 4.65 0
    CIRCLE 14.5 0 0
    CUBE 13 0 0
    BOX 1 2 3
    SPHERE 0 0 0
    CYLINDER 1.23 6 0
    CYLINDER 50 1.23 0
    TRIANGLE 1.2 0 0

Note the format of this input file consists of: (1) an object type in uppercase (SQUARE, RECTANGLE, CIRCLE, TRIANGLE, CUBE, BOX, CYLINDER), and (2) the dimensions of the object as follows:

for square, 1 dimension: “side”

for rectangle, 2 dimensions: “length” and “width”

for circle, 1 dimension: “radius”

for triangle, 1 dimension: “side”

for cube, 1 dimension: “side”

for box, 3 dimensions: “length”, “width”, and “height”

for cylinder, 2 dimensions: “radius” and “height”

INPUT FILE FORMAT: The first token is the object name (for example, "SQUARE"). The second through fourth tokens are dimensions. Some calculations need only one dimension (CIRCLE, SQUARE, CUBE, and TRIANGLE); others need two (RECTANGLE, CYLINDER) or three (BOX). 

Your input file may contain 0’s for unneeded tokens if desired. For example, an input line for a CIRCLE may look like:

CIRCLE 3.2 0 0  <– since you just need radius for a circle.

INPUT FILE VALIDATION: the input file*also* has some invalid shapes, not part of the valid set of 7 that our program will process. When your program encounters an invalid shape, it should state such.

OUTPUT: Write results to two different sources — the console screen and a TXT text file. 

CONSOLE OUTPUT FORMAT. Output the object name, its dimensions (1, 2, or 3 of them), and calculated results on one line. If the object is not recognized as one of the 7 allowable object types, produce output to this effect: “SPHERE invalid object”.  The results for the above input should be as follows. Note the identifications of the dimensions and the calculated values. 

CIRCLE radius=3.20 area=32.17 perimeter=20.11
SQUARE side=4.60 area=21.16 perimeter=18.40
TRIANGLE side=12.50 area=67.66 perimeter=37.50
RECTANGLE length=12.40 width=53.20 area=659.68 perimeter=131.20
SPHERE invalid object
PYRAMID invalid object
BOX length=12.20 width=13.30 height=14.40 volume=2336.54 surface=1058.92
SQUARE side=14.50 area=210.25 perimeter=58.00
SQUARE side=0.00 area=0.00 perimeter=0.00
RECTANGLE length=14.50 width=4.65 area=67.43 perimeter=38.30
CIRCLE radius=14.50 area=660.52 perimeter=91.11
CUBE side=13.00 volume=2197.00 surface=1014.00
BOX length=1.00 width=2.00 height=3.00 volume=6.00 surface=22.00
SPHERE invalid object
CYLINDER radius=1.23 height=6.00 volume=28.52 surface=55.88
CYLINDER radius=50.00 height=1.23 volume=9660.40 surface=16094.38
TRIANGLE side=1.20 area=0.62 perimeter=3.60

FILE OUTPUT FORMAT. Output to a text file named “output.txt” in exactly the same format as the console output. But unlike the console output, skip invalid shapes — only output valid shapes. 

ROUNDING: Format the calculated results to 2 digits after the decimal. 

DO open your outputted TXT file in a text editor to see if it is formatted the same as the console output.

Submit shapes.cpp for grading. Do NOT submit any text input or output files.

Great students hand in great papers. Order our essay service if you want to meet all the deadlines on time and get top grades. Professional custom writing is the choice of goal-focused students. Word on the online streets is... we're simply the best!

Get a 15% discount on your order using the following coupon code SAVE15


Order a Similar Paper Order a Different Paper