EGR 126
Program 9 – the Strain and Stress of Programming!
The objective of this Program is to design a program that uses a 2 dimensional array.
Problem definition:
A tensile test was conducted and samples were taken at several points to determine strain and stress data at each point. For each sample point i , xi represents the strain at point i and yi represents the stress at the same point.
The data can be plotted as a series of points with coordinates (xi , yi ):
The Energy required to stretch and break the tensile specimen is the area under the strain-stress curve. The Energy (or area), can be found using the trapezoid rule with successive x and y values as follows:
𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸=�𝐸𝐸1+𝐸𝐸2�(𝑥𝑥 −𝑥𝑥)+�𝐸𝐸2+𝐸𝐸3�(𝑥𝑥 −𝑥𝑥)+⋯+�𝐸𝐸𝑛𝑛−1+𝐸𝐸𝑛𝑛�(𝑥𝑥 −𝑥𝑥 ) 221232 2𝑛𝑛𝑛𝑛−1
The first k strain values (for 1 < k < n ) of the strain-stress data represent the elastic response of the material, where k is the elastic strain cut point.
The Elastic Energy is the area under the curve for the first k strain values. The Total Energy is the area under the curve for all n strain values.
You are to write a C++ program to determine:
the Elastic Energy required to stretch the tensile specimen, and the Total Energy required to break the tensile specimen
For the purposes of this program, disregard any units of measurement, and use the data represented in the graph. This data is provided for you in the data file Prog9data.txt in BlackCanvas.
For completeness, a print of the data file accompanies this document.
Updated 5/27/2017 Page 1 of 2
EGR 126
The first four lines of the file give information on the file purpose and content. Please read in, and print, these lines.
The value given for the elastic strain cut point is the x value (strain) that will determine the data to use in calculating the Elastic Energy. All data with x values less than or equal to that cut point value will be used in the Elastic Energy calculation. All data given will be used for the Total Energy calculation.
The data should be input in the main function. It should be stored in a 2-dimensional array.
Set up one function for Energy Calculation according to the Energy formula given above.
You will call this function twice: once for the Elastic Energy calculation and then again for the Total Energy calculation. You will need to pass the array to the function as a parameter.
You will also need a parameter for the number of data pairs to use for each calculation.
The function will return the calculated energy value to the main function, to be printed.
Do not use any global variables.
Your submission should contain: the number of data pairs
the data values used, appropriately arranged in columns and well labeled the cut point value for the Elastic Energy
the calculated value for the Elastic Energy
the calculated value for the Total Energy
You should use 2 decimal places of precision.
An extension of this program might be to present the data graphically in your output.
Updated 5/27/2017 Page 2 of 2