Question: Need help, use C++ to create a simple utility that computes the area of basic geometric shapes defined via a text input file. The shapes

Need help, use C++ to create a simple utility that computes the area of basic geometric shapes defined via a text input file. The shapes you will be supporting are as follows::

  • circle
  • square
  • triangle
  • rectangle

Unlike the previous exercise housed entirely within a single source code file, you are required to organize your solution for this exercise into three files:

  1. main.cpp
  2. area.hpp
  3. area.cpp

The input for this task is a simple ascii input file with one shape defined per line. The shape is designated with a keyword followed by one or more double-precision dimensions that can be used to compute the area. The format for each of the supported shape definitions and associated dimension(s) is outlined as follows:

circle  square  triangle   rectangle  

Note that input shapes can occur in any order and be repeated. An example of a valid input file with real numerical inputs (named inputfile) is as follows:

square 0.25 rectangle 1.25 42.0 square 0.3578 circle 1.0

General high-level requirements for your implementation are as follows:

main.cpp:

  • must house the main() function
  • requires one command-line argument that provides a character string for the name of a shape input file,
  • parses the contents of and saves the input shapes and associated dimensions into memory via a snazzy data structure of your own design
  • after reading the input file, loop over all the defined shapes and call function(s)/method(s) implemented in area.cpp that have the logic to compute the area for each of the supported types
  • after computing all the shape areas, output a single double precision value to stdout that contains a summation of all shape areas

area.cpp

  • owns the code which computes the correct area for each defined shape

area.hpp

  • header file with any datatypes, function prototypes, enumerators, definitions, etc required to facilitate your implementation
  • this file can be included within both main.cpp and area.cpp using the #include directive

An example running this code with the contents of the inputfile listed above is as follows:

$ ./main inputfile 53.4759

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!