ENGG1002 Introduction to Engineering Computations S2 2018 Assignment 2

ENGG1002 Introduction to Engineering Computations S2 2018
Assignment 2 – General rules
Carefully read the instructions before attempting any of the questions. Note that you may lose significant
points by neglecting these rules.
Due date
Week 8, Friday 21 September 2018 @ 23:59 EAST (Australian Eastern Standard Time)
Submission instructions
You will be required to submit your assignment through Blackboard using Turnitin. Please follow Assignment 2
(Turnitin) link and steps outlined there.
By submitting your assignment using Turnitin you will be able to check the originality of your submission and
have the possibility to resubmit the work until the due date. The first originality report will appear straight away,
but for all resubmissions you might have to wait 24 hours for the report to be available. Therefore, use
“Resubmit” diligently.
Your submission must include:
• Assessment Item Cover Sheet with required information (no signature is needed with electronic
• Your report
• A copy of your Visual Basic code (as in Module1.vb or Form1.vb)
• Screenshot of the outputs or windows form (if applicable)
• Include all listed above in one file (DOCX or PDF, preferably DOCX) with the file name consisting of
your student number (no “C”), last name and Assn2 all joined together with no spaces. E.g.,
Each listing of your Visual Basic code must start with a header of the following form (replace text in red with
corresponding numbers/names):
‘ ENGG1002 Assignment 2, Question 1
‘ Student number: 1234567
‘ Last name, first name: YOUR_LASTNAME, YOUR_FIRSTNAME
Answer all questions. You will not lose any points by ignoring the ‘Bonus’ parts, but you will obtain an extra 20%
if you tackle them correctly! Note: bonus points will be added to the final mark only if the total mark without
bonus points is at least 50.
Assignment Notes
For all questions you must provide a listing of your program plus a short report covering:
• Aims: The principal aim(s) of the question in your own words (do not “copy” assignment text or repeat
• Program Design: A description of the program structure and organisation used.
ENGG1002 Introduction to Engineering Computations S2 2018
Page 2 of 8
• Results and Discussion: This section must contain all the important results. The discussion should include
an assessment of the major numerical errors and their effect on the solution. It may be appropriate to
mention any specific difficulties you had in developing your program.
• Conclusion: This should summarise the most important results.
• Appendix: This contains a listing of your program (source code) and relevant data files (copy past the
text into the Word document, screenshots of source code or data files are not accepted).
Use the template provided on Blackboard, see 1234567_LASTNAME_Assn1.docx.
Marking Scheme
The assignments will be assessed according to the following criteria:
• Overall correctness of program: A high-scoring program must produce correct answers and be a correct
implementation of the appropriate algorithm.
• Program Structure: A good program must have the appropriate structure in terms of:
• the order in which the computations are carried out,
• the number and sequence of subprograms, and
• the communication of information to and from the subprograms must be correct and
• Variables Declaration, Annotation and Input/Output:
• A high scoring program should have all variables declared and have sufficient comment
statements to allow the marker (or anyone else) to follow the program’s logic. The input and
output of the data must be done appropriately. For example, results that are accurate to say,
three significant figures, should be output only to that number of significant figures.
• Quality of Report
• The quality of the report will be assessed in terms of the requirements given in the previous
General hints
• You can use the Windows ‘Snipping Tool’ ( ) to make screenshots of the output screen (e.g.,
console or Windows form). It should be located in your toolbar. Alternatively you can also use the
‘Alt+PrtScn’ button on the keyboard to make a screenshot of the current active window. The screenshot
will be copied into the Clipboard and you can paste it into your report by using ‘Ctrl+V’.
• Change the size of the console output window before making the screenshot to avoid large screenshots
with lots of black background or appropriately crop the picture in Word.
• Make sure your code is running on the Engineering Faculty computer system.
• All programs should be commented and formatted (i.e., use indentation) appropriately and variables
should be assigned meaningful names.
• Check significant figures of a number and eventually round.
• Copy/Paste code.
ENGG1002 Introduction to Engineering Computations S2 2018
Page 3 of 8
1. Snapshots of the VB source code will not be accepted, the source code must be presented in text format
in the Word document (or pdf file). Please copy/past the source code into your Word document including
the formatting.
2. Assignments are automatically checked by Turnitin for plagiarism. Please check the originality report.
3. Any student found copying material from another student (current or past), or from an external source
such as the Web, will be regarded as having contravened the university’s plagiarism policy for that
assessment item.
4. If you have done this course in the past make sure you do not submit your old assignment as the
questions might have been changed.

ENGG1002 Introduction to Engineering Computations S2 2018
Page 4 of 8
Assignment 2 – Questions
Question 1
In engineering applications it is often necessary to fit a straight line to a set of points with known coordinates
( , ), where is the counter for the points ( = 1 … ). Under certain assumptions (Least Square Method), the
equation of the line-of-best-fit through points, which also passes through the origin, is given by:
� = ̅ with = ∑


where corresponds to the slope of the line and ̅and � are the coordinates of the line-of-best-fit.
Write a VB Console Application and define a User-defined Data Type (UDT) called MyPoint which includes two
Double variables corresponding to the and coordinates of a point. Write a VB Function (Calc_k) that
receives an array of MyPoint data type with elements from the main program and calculates/returns the
coefficient in the best-fit equation through the origin.
Test your function by computing the coefficient for the line that best fits the following 10 points:

1 1.1 2.5
2 3.3 4.1
3 3.8 7.9
4 5.5 13.5
5 6.1 14.1
6 8.2 21.2
7 10.3 23.1
8 11.1 24
9 12.6 26.2
10 12.9 27
The data should be read from a text file named “points.dat” in Sub Main. The first line of the file should contain
the number of points to be read. The following lines should contain pairs of numbers (separated by a comma)
describing the coordinates of points (one pair per line). The arrays storing the UDTs should be declared in Sub
Main as a static array with the size specified in the input file. The program should write the value of computed
to the screen.
• Create the text file “points.dat”. The first line has one value, e.g. 10, the following lines have two values
each separated by a comma.
• Read the number of points in the first line of the input file before you declare the size of your array.
Note: you can declare variables anytime during the program, it does not have to be at the beginning.
• Use a FOR loop to read the coordinates and to calculate the sums in the given equation.
• Refer to the Truss Example of Week 6.
• You can check your result using MS Excel by addition a linear Trendline to your data set.
ENGG1002 Introduction to Engineering Computations S2 2018
Page 5 of 8
Question 2
In analytical geometry, a convex polygon can be represented by the Cartesian coordinates and of its vertices.
Assume such data of a polygon are stored in a file called “vertices.dat”. Each line of the file contains a pair of
real numbers (separated by a comma) describing the coordinates of points (one pair per line).
Create a VB Console Application called “Polygon” according to the following instructions:
1. In Sub Main, declare all necessary variables including an array with the coordinates of the points, and
an array with the coordinates of the points, etc. Assume static array sizes of max = 100, i.e., allow a
maximum of 100 points. The program should stop with an appropriate message if the user supplies a file
with more than max data points. The main program should call all Subs and Functions discussed in points
2 to 5 below.
2. Write a Sub Open_File which opens the input file “vertices.dat” and reads the coordinates of the points
from the input file.
3. Write a Sub Calc_Length which calculates the length of all sides of the polygon.
4. Write a Function Perimeter which calculates the perimeter of the polygon.
5. Write a Sub Output_File which writes the length of all sides and the perimeter into an output file
called “sides.dat”.
Use the following data in “vertices.dat”:
-3.8, 1
-1.5, 3.8
2, 4
4, 2.2
4.5, -0.9
2.6, -4.1
-0.8, -3.3
Run your program and find the length of all sides of the polygon and its perimeter. Copy/past the values from
your output file “sides.dat” into your report.
• Make sure you only use the specified elements in your calculations and not the maximum array size
max = 100.
• Use an infinite DO loop to read the data and exit it if you reach the end of the file (EOF) or max. Make
sure the input file has no newline at the end.
• For Subs and Functions refer to Lecture Slides of Week 4.
• For reading and writing files, refer to Lecture Slides of Week 5.
Bonus (extra 10%)
Write a Function that calculates the total area of the polygon, assuming it is convex. Calculate and report the
area of the heptagon given above.

ENGG1002 Introduction to Engineering Computations S2 2018
Page 6 of 8
Question 3
A person, ℎ1 (m) tall, attempts to throw a rock through a window in a wall that is (m) away (see figure below).
The window is ℎ2 (m) off the ground and (m) high. The rock is thrown with an initial velocity 0 (m/s), and an
angle of inclination θ (in degrees, assume 0o < θ < 90o). At some time after the rock was thrown, the horizontal distance it has travelled, , is given by = ( 0 cos ) and the height of the rock, ℎ, is given by ℎ = − 1 2 2 + ( 0 sin ) + ℎ1 where = 9.806 m/s2 is the acceleration due to gravity. The time of flight of the rock to reach the wall, , can be calculated as = 0 cos and it follows that the height of the rock when it reaches the wall (or window), ℎ , is ℎ = − 1 2 2 + ( 0 sin ) + ℎ1 If ℎ2 < ℎ < ℎ2 + , then the attempt is successful. Provided the attempt is successful, the total time of flight of the rock is obtained by finding the time at which the rock hits the ground behind the wall (i.e., ℎ = 0). This can be obtained by solving the following quadratic equation for : − 1 2 2 + ( 0 sin ) + ℎ1 = 0 and choosing the appropriate root. Then, the total horizontal distance the rock has travelled, , is obtained according to v0 h1 h2 L θ w ENGG1002 Introduction to Engineering Computations S2 2018 Page 7 of 8 = ( 0 cos ) Part A (GUI and Solve/Exit buttons) Develop a Windows Form Application, as shown above, which allows the user to enter values of h1, h2, w, L, v0, and θ. Your form does not need to look exactly as the one above, but it must contain all graphic controls shown in this form. Replace YOUR STUDENT NUMBER with your student number. The picture to include in the form can be downloaded from Blackboard. After entering the input data, and by clicking the “Solve” button, your application must calculate and show values of and ℎ . If an attempt is successful your program should write “Successful” in the textbox on the right side of the “Attempt:” label, and must compute/show the values for and . Otherwise, it should show “Unsuccessful” and indicate the amount missed in the textbox next to the “Missed by [m]” label. Note that missed refers to above (+) or below (-) the window. You can assume that the rock always reaches the wall. The application should close when the user clicks the “Exit” button. Report the results of your program for the attempts listed in the table below: Attempt [m] [m] [m] [m] [m/s] [deg] 1 1.0 3 1 6 12 30 2 1.6 3 1 12 20 20 3 2.0 3 1 18 18 30 Part B (Trajectory button) By clicking on this button, your application must calculate the trajectory of the projectile, only for a successful attempt, and save it into a text file “trajectory.csv”. Your program must show the name of the output file to the user via a MsgBox. The trajectory information contains time, distance, and height of the projectile during its flying time interval [0, tf]. Subdivide this interval into 50 equal time increments and compute the distance and height of the projectile at each increment. Do not use any arrays in this part. Each line in the output file must contain: Time, distance, height ENGG1002 Introduction to Engineering Computations S2 2018 Page 8 of 8 Note that the output file must contain 51 lines. Find the trajectory of a projectile for all successful attempts of Part A. Copy/paste the contents of the output file into your report. Hints • Only attempt this question after completing Tutorial 6 (Week 7). • Use Doubles in all your calculations. • Convert the angle from degrees to radians before doing any calculation. • Assume all input parameters are positive and the angle is 0o < θ < 90o. • The elements to be used in the form are: GroupBox, PictureBox (Size Mode: Zoom), Label, TextBox, Button. • In the report, summarise your results in form of a table. Bonus (extra 10%) Find the angle (or angles) of inclination for which the rock will pass through the midpoint of the window (i.e., ℎ = h2 + /2) for all unsuccessful attempts in Part A. You will have to solve a quadratic equation for the angle θ (hint: 1/(cos(x)^2 = tan(x)^2 + 1). A “MsgBox” displaying an appropriate message with the results should appear after pressing the “Bonus” button.