Download presentation
Presentation is loading. Please wait.
Published byAndra Gilmore Modified over 8 years ago
1
1 ENGI 2420 Structured Programming (Lab Tutorial 2) Memorial University of Newfoundland
2
ENGI 2420 – Structured Programming Lab Tutorial 2 2 2.1Problems in the Last Assignment 2.2 Marking Criteria of Programming Style 2.3Some Reminders 2.4Assignment-2 Lab Tutorial 2
3
ENGI 2420 – Structured Programming Lab Tutorial 2 3 2.1 Problems in the Last Assignment Always submit the right file (assignN.cpp) to web-submit (around one student per lab section failed in submitting a proper assign1.cpp file) 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 2.1 Problems in the Last Assignment
4
ENGI 2420 – Structured Programming Lab Tutorial 2 4 Common Problems (I) Functions in assign1.cpp should exactly follow the declaration given in assign1.h e.g., for “double extraStJohns(int days);”, you should NOT define the following functions in assign1.cpp: double extraStJohns(double days); or double testExtraStJohns(int days); How to represent a number in C++/C 205480 205,480 6.67e-3 = 6.67E-3 = 6.67/1000 2.1 Problems in the Last Assignment
5
ENGI 2420 – Structured Programming Lab Tutorial 2 5 Common Problems (II) Sometimes space does matter e.g., 6.67e-3 6.67 e-3 data1 data 1 Some conventional expressions may not be valid in C++/C e.g., distance * distance distance^2 Correct formulas are the most important in computation e.g., return 235.214584 * mpg ; 2.1 Problems in the Last Assignment
6
ENGI 2420 – Structured Programming Lab Tutorial 2 6 Common Problems (III) Pay attention to units used in the formulas e.g., return (6.67428e-11 * mass) / (distance * distance ); How to handle double calculation of integer numbers e.g., (days * 205480) / 181113 => integer (days * 205480.0) / 181113 => double 2.1 Problems in the Last Assignment
7
ENGI 2420 – Structured Programming Lab Tutorial 2 7 2.2 Marking Criteria of Programming Style Three main categories: comments, indentation and naming, and simplicity 0, 0.5, or 1 where start with 1 subtract 0.5 for each minor problem subtract 1 for a major problem 2.2 Marking Criteria
8
ENGI 2420 – Structured Programming Lab Tutorial 2 8 Comments Major problems include - missing initial file comment blocks - missing all the function comment blocks Minor problems include - missing key identification information - poor function comments (e.g. omitting units) - necessary in-line comments for key variables or formulas are missing - meaningless comments or overuse of comments 2.2 Marking Criteria
9
ENGI 2420 – Structured Programming Lab Tutorial 2 9 Two Other Categories Indentation and Naming - minor problems poor indentation poor choice of names for parameters and functions Simplicity - major problems include an algorithm that is totally wacky - minor problems use of global variables where local ones would do redundant or useless computations 2.2 Marking Criteria
10
ENGI 2420 – Structured Programming Lab Tutorial 2 10 2.3 Some Reminders Unless otherwise indicated, all assignments are due at 11:59 pm the day after the lab for your section Late assignments will not be accepted except by special permission of the lecturer Lab Help Centre will be held at 17:00-18:00 on Tuesdays and Wednesdays in Lab 3000/3029 2.3 Some Reminders
11
ENGI 2420 – Structured Programming Lab Tutorial 2 11 2.4 Assignment-2 Structure of C++ files - a2main.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) - assign2.h: contains the declarations for the functions - assign2.cpp: contains your implemented functions Implement two functions as follows 2.4 Assignment-2
12
ENGI 2420 – Structured Programming Lab Tutorial 2 12 Problem Description The implemented functions work together to compute the rotational velocity of the driven (output) gear (g4) of a gear train. In this system the intermediate gears, g2 and g3, are each made up of two different size gears attached to a single axel so that both parts of each turn at the same rate 2.4 Assignment-2
13
ENGI 2420 – Structured Programming Lab Tutorial 2 13 Function 1 double rotationalVelocity(double inRotVel, double inTeeth, double outTeeth) - compute the rotational velocity of a driven gear, with outTeeth teeth, given the rotational velocity (inRotVel) and number of teeth (inTeeth) of the gear that is directly driving it (i.e., for a two gear system) - hint: consider direction change for two rotational velocities (using plus/minus sign) 2.4 Assignment-2
14
ENGI 2420 – Structured Programming Lab Tutorial 2 14 Function 2 double gearTrainOutput(double inRotVel, int g1Teeth, int g2InTeeth, int g2OutTeeth, int g3InTeeth, int g3OutTeeth, int g4Teeth) - compute the output (g4) rotational velocity for the illustrated gear train - for g2 and g3, the InTeeth refers to the number of teeth on the gear that is being driven by the gear to its left, whereas OutTeeth refers to the number of teeth on the gear that is driving the gear on its right - this function must call rotationalVelocity to compute the rotational velocities of the driven gears 2.4 Assignment-2
15
ENGI 2420 – Structured Programming Lab Tutorial 2 15 Execution Example (I) Available options: 1 - Test rotationalVelocity 2 - Test gearTrainOutput 0 - Quit Please enter a selection: 1 Enter the driving rotational velocity: 10 Enter the number of teeth on the driving gear: 6 Enter the number of teeth on the driven gear: 12 rotationalVelocity(10, 6, 12) = -5 2.4 Assignment-2
16
ENGI 2420 – Structured Programming Lab Tutorial 2 16 Execution Example (II) Available options: 1 - Test rotationalVelocity 2 - Test gearTrainOutput 0 - Quit Please enter a selection: 2 Enter the driving rotational velocity: 10 Enter the number of teeth on the driving gear (g1): 5 Enter the number of teeth on the driven gear of g2: 20 Enter the number of teeth on the driving gear of g2: 5 Enter the number of teeth on the driven gear of g3: 30 Enter the number of teeth on the driving gear of g3: 10 Enter the number of teeth on the driven gear g4: 25 gearTrainOutput( 10, 5, 20, 5, 30, 10, 25) = -0.166667 2.4 Assignment-2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.