Write a set of functions that calculate the volume of a


Project - Winter 2016

The purpose of this project is to write a set of functions that calculate the volume of a slant cylinder (actually a prism) with an irregular pentagonal cross section shown in Figure 1.

You will be given the coordinates of the corners of the pentagon (five pairs of x,y values), and the value h, the vertical height of the prism. You must read the file* and fill the two vectors x and y that will contain the coordinates. x and y are two one-dimensional arrays. Now, we will need to break this problem apart, writing functions to solve each part. Note that the development of these parts will not occur in order necessarily (in fact it is recommended that you write the function in part 4 first (tri_side) and then write the other ones in reverse order.

1. The volume of the prism is the area of the pentagon multiplied by the vertical height. Write a function named polyvol to solve this.

2. The area of the pentagon is the sum of the areas of three triangles as shown in Figure 2. So we need to write a function named pent_area that takes in the area of the three triangles and adds them together.

3. Given the coordinates of the corners of the triangle, we need to write a function named tri_area to calculate the area of the triangle (see Figure 3). To compute the area of the triangle, we need the values a, b, and c. So if we had the lengths of the lines, the area of the triangle is given by Heron's formula:

A = ( s(s-a) (s-b) (s-c) ) where s is half the sum of a, b, and c.

4. Then, we need a function named tri_side that computes the length of a line when given its end points. (You may need to review a bit of high school geometry to write that simple function)

5. Finally, put it all together by writing the main program that will read a data file, then call the polyvol function (and in turn, from it, the other functions) and display the volume of the prism in cubic meters. Test/run your program for each of the two data files (test cases).

Attachment:- p2.rar

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Write a set of functions that calculate the volume of a
Reference No:- TGS01363467

Now Priced at $50 (50% Discount)

Recommended (95%)

Rated (4.7/5)