Download presentation
Presentation is loading. Please wait.
Published byNora Osborne Modified over 9 years ago
1
1 ENGI 2420 Structured Programming (Lab Tutorial 3) Memorial University of Newfoundland
2
ENGI 2420 – Structured Programming Lab Tutorial 3 2 3.1Problems in Assignment-2 3.2Some Reminders 3.3Assignment-3 Lab Tutorial 3
3
ENGI 2420 – Structured Programming Lab Tutorial 3 3 3.1 Problems in Assignment-2 It is your responsibility to ensure that your assignN.cpp can be correctly compiled with the other downloadable files (available in the assignment requirement on the web) in an Eclipse project Functions in assign2.cpp should exactly follow the declaration given in assign2.h e.g., for “double rotationalVelocity (double inRotVel, double inTeeth, double outTeeth);”, you should NOT define in assign2.cpp: double rotationalVelocity(double inRotVel, int inTeeth, int outTeeth) 3.1 Problems in Assignment-2
4
ENGI 2420 – Structured Programming Lab Tutorial 3 4 Common Problems Correctly understand the meaning of the parameters on the function argument list e.g., InTeeth => number of teeth on the gear that is being driven by the gear to its left OutTeeth => number of teeth on the gear that is driving the gear on its right double g2RotVel = rotationalVelocity ( inRotVel, g1Teeth, g2OutTeeth ); double g2RotVel = rotationalVelocity(inRotVel, g1Teeth, g2InTeeth); 3.1 Problems in Assignment-2
5
ENGI 2420 – Structured Programming Lab Tutorial 3 5 Common Problems Not calling rotationalVelocity from gearTrainOutput. It is better to use function calls rather than copying the algorithm to multiple places –Makes your program shorter and easier to understand. –The algorithm can be documented once –Errors in the algorithm need only be fixed once
6
ENGI 2420 – Structured Programming Lab Tutorial 3 6 3.2 Some Reminders New Due time: Wednesdays at 11:59pm for all lab sections except 5 and 12 (Wednesday labs), Thursdays at 11:59 for lab sections 5 and 12 Lab Help Centre will be held at 17:00-18:00 on Tuesdays and Wednesdays in Lab 3000/3029 3.2 Some Reminders
7
ENGI 2420 – Structured Programming Lab Tutorial 3 7 3.3 Assignment-3 Structure of C++ files - a3main.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) - assign3.h: contains the declarations for the functions - assign3.cpp: contains your implemented functions Implement three functions as follows 3.3 Assignment-3
8
ENGI 2420 – Structured Programming Lab Tutorial 3 8 Function 1 double deceleration ( double v0, double v1, double delta_t ) - compute the rate of deceleration, in m/s 2, of a body given two speed measurements (v0 and v1) in km/h and the time between the measurements ( delta_t ) in seconds. - hint: consider unit conversion 3.3 Assignment-3
9
ENGI 2420 – Structured Programming Lab Tutorial 3 9 Function 2 double timeToStop( double v0, double delta_v, double delta_t ) - compute the time, in seconds, that a body will take to stop given it's initial speed, in km/h, ( v0 ) and a change in speed in km/h ( delta_v ) and the time taken for that change in speed in seconds ( delta_t ) - This function must call deceleration function to compute the deceleration 3.3 Assignment-3
10
ENGI 2420 – Structured Programming Lab Tutorial 3 10 Function 3 double distanceToStop( double v0, double delta_v, double delta_t ) - compute the distance, in metres, that a body will take to stop given it's initial speed, in km/h, ( v0 ) and a change in speed in km/h ( delta_v ) and the time taken for that change in speed in seconds ( delta_t ) - This function must call timeToStop to compute the time 3.3 Assignment-3
11
ENGI 2420 – Structured Programming Lab Tutorial 3 11 Execution Example (I) Available options: 1 - Test deceleration 2 - Test timeToStop 3 - Test distanceToStop 0 - Quit Please enter a selection: 1 Enter the initial speed in km/h: 13 Enter the second speed in km/h: 10 Enter the seconds elapsed between the speeds: 60 deceleration(13, 10, 60) = 0.0138889 3.3 Assignment-3
12
ENGI 2420 – Structured Programming Lab Tutorial 3 12 Execution Example (II) Available options: 1 - Test deceleration 2 - Test timeToStop 3 - Test distanceToStop 0 - Quit Please enter a selection: 2 Enter the initial speed in km/h: 13 Enter the change in speed in km/h: -3 Enter the seconds elapsed between the speeds: 60 timeToStop(13, -3, 60) = 260 3.3 Assignment-3
13
ENGI 2420 – Structured Programming Lab Tutorial 3 13 Execution Example (III) Available options: 1 - Test deceleration 2 - Test timeToStop 3 - Test distanceToStop 0 - Quit Please enter a selection: 3 Enter the initial speed in km/h: 13 Enter the change in speed in km/h: -3 Enter the seconds elapsed between the speeds: 60 distanceToStop(13, -3, 60) = 469.444 3.3 Assignment-3
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.