Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program will need to accept two input arguments: the path of the input file and the path of the output file. See etc/cpp/example.ifstream.cpp for

The program will need to accept two input arguments: the path of the input file and the path of the output file. See etc/cpp/example.ifstream.cpp for the basis of how to do this. Once the input and output file paths have been received, the program will need to open the input and output files, read and process each input file line and create a corresponding output file line, close the input and output files, and then create and output some summary lines to the console. Note that the summary lines can be output to the console before or after the input and output files are closed, but it would be best to output them to the console after the files have been closed. Each input line will either be a comment line or shape specification line. Your program will need to ignore the comments lines and process the shape specification lines. There will be three types of shapes: a circle, a triangle, and a square. Each shape specification lines will be in this form, with the different values separated by spaces: The shape identifier will be an integer, the shape type will be a string, and the shape measure will be a double. So, for example, you might encounter lines like this: # this line is a comment and can be ignoredit starts with the pound/hash character 1 circle 3.51 2 triangle 4.62 3 square 5.73 For comments lines, lines that start with the pound/hash character, you can ignore them. For the other lines, you should calculate the shapes area and create an output line in this form:

< shape area> For circle shape lines, the shape measure represents the radius of a circle (r) and thus the area of the circle is A = PI * r * r (where PI can be a defined constant double of 3.14). For triangle shape lines, the shape measure represents the length of the side of an equilateral triangle (a) and thus the area is A = sqrt(3) / 4 * a * a. For square shape lines, the shape measure represents the length of one side of the square (a) and thus the area is A = a * a. So, for the input file lines above, the output file lines would look like this (with the area values formatted with a precision of three decimal places): 1 circle 38.685 2 triangle 9.242 3 square 32.833

And, the summary lines that should be sent to the console, if the example above represents all of the shape specifications, would look like this: - CS 1336 Assignment 25 Number of circles: 1 Number of triangles: 1 Number of squares: 1 Average circle area: 38.685 Average triangle area: 9.242 Average square area: 32.833 Average shape area: 26.920 In case it is not obvious, the average circle area should be calculated by summing all of the individual circle areas and then dividing by the number of circles. And, the same pattern should be used for the average triangle area and the average square area. Finally, the average shape area should be calculated by adding all of the areas together and dividing by the total number of shapes.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Define and measure service productivity.

Answered: 1 week ago