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:
- main.cpp
- area.hpp
- 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:
circlesquare 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started