ENGI 2420 Structured Programming (Lab Tutorial 4)
description
Transcript of ENGI 2420 Structured Programming (Lab Tutorial 4)
1
ENGI 2420Structured Programming
(Lab Tutorial 4)
Memorial University of Newfoundland
2 ENGI 2420 – Structured Programming
Lab Tutorial 4
4.1 Problems in Assignment-34.2 How to Recognize a Project in Eclipse4.3 Resubmit Policy4.4 Assignment-4
Lab Tutorial 4
3 ENGI 2420 – Structured Programming
Lab Tutorial 4
4.1 Problems in Assignment-3
Why different answers than those in the lab notes (FAQ)?
- unit conversion
- how to multiply by 1/2?
In C++, use 0.5, 1.0/2, or 1/2.0 etc.
- sign problems Signs for deceleration and delta_v (FAQ):
- deceleration should return a positive number for a decrease in speed (i.e., v1 < v0).
- delta_v should be interpreted as change in speed, so a negative value is a decrease in speed
4.1 Problems in Assignment-3
4 ENGI 2420 – Structured Programming
Lab Tutorial 4
Common Problems Correctly understand the meaning of the parameters on
the function argument list
e.g., declaration: double deceleration ( double v0, double v1, double delta_t );
double decelerationStop2 = deceleration( v0, (delta_v +v0), delta_v);
double decelerationStop2 = deceleration( v0, (delta_v +v0), delta_t);
FAQ: should I document each variable?
- to be on the safe side, We 'd suggest you do.
4.1 Problems in Assignment-3
5 ENGI 2420 – Structured Programming
Lab Tutorial 4
Style point
It isn’t necessary to return the value of a variable double d = (v0-v1) / 3.6 /delta_t; return d ;
Might as well be return (v0-v1) / 3.6 /delta_t;
6 ENGI 2420 – Structured Programming
Lab Tutorial 4
4.2 How to Migrate an Eclipse Project
First work on your assignment on machine-A Copy the project folder from machine-A to M:Drive If you work on machine-B in the lab next time, copy
your project folder from M:Drive to machine-B (say, under My Documents/workspace)
In Eclipse, click File->New->C++ Project and type in the original project name. Ignore the warning message and click Finish. The old project will be recognized in Eclipse on Machine-B
4.2 How to Recognize a Project in Eclipse
7 ENGI 2420 – Structured Programming
Lab Tutorial 4
4.3 Resubmit Policy
Resubmits are permitted automatically on every assignment
- for students who submitted the assignment in the first place
- style will not be marked again
- resubmits are due at 8:55 am on the day shown in the assignment table on the course web-site
- note that resubmits on assignments 4-8 will cost you one mark
4.3 Resubmit Policy
8 ENGI 2420 – Structured Programming
Lab Tutorial 4
4.4 Assignment-4 Structure of C++ files
- a4main.cpp: contains a code that calls the functions using input typed in by the user (Note that you are not expected to understand all of the code in this file at this point in the course)
- assign4.h: contains the declarations for the functions
- assign4.cpp: contains your implemented functions
Implement two functions as follows
4.4 Assignment-4
9 ENGI 2420 – Structured Programming
Lab Tutorial 4
Function 1 double sineSeries(double x, int n)
- computes the nth-order Maclaurin series approximation of sin(x)- where x is an angle in radians in the range (-π, π). n is the degree of the highest term
- note that the even degree terms are all 0. For n=7 or n=8 we have
- returns the magnitude of the difference between the computed approximation and the library function (sin)
4.4 Assignment-4
10 ENGI 2420 – Structured Programming
Lab Tutorial 4
Function 2 double expSeries ( double x, int n)
- computes the nth-order Taylor series approximation of ex
- where x is any number, n is the degree of the highest term
- returns the magnitude of the difference between the computed approximation and the library function (exp)
4.4 Assignment-4
11 ENGI 2420 – Structured Programming
Lab Tutorial 4
Execution Example (I)Available options:
1 - Test sineSeries
2 - Test expSeries
0 - Quit
Please enter a selection:
1
Enter the angle in radians (range -pi, pi): 1.5
Enter the highest order: 9
sineSeries(1.5, 4) = 2.13602e-006
4.4 Assignment-4
12 ENGI 2420 – Structured Programming
Lab Tutorial 4
Execution Example (II)Available options:
1 - Test sineSeries
2 - Test expSeries
0 - Quit
Please enter a selection:
2
Enter the exponent: 1.5
Enter the highest order: 4
expSeries(1.5, 4) = 0.0832516
4.4 Assignment-4