1 ENGI 2420 Structured Programming (Lab Tutorial 3) Memorial University of Newfoundland.

Slides:



Advertisements
Similar presentations
User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Advertisements

Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
CS1010 Programming Methodology
1 ENGI 2420 Structured Programming (Lab Tutorial 0) Memorial University of Newfoundland.
Chapter 7: User-Defined Functions II
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
CS 201 Functions Debzani Deb.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 1 Introduction.
Chapter 6: Functions.
6 Steps of the Programming Process
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
1 Programming James King 12 August Aims Give overview of concepts addressed in Web based programming module Teach you enough Java to write simple.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Functions in C++ Eric Roberts CS 106B January 9, 2013.
Fruitful functions. Return values The built-in functions we have used, such as abs, pow, int, max, and range, have produced results. Calling each of these.
Course Introduction CS 2302 SPRING Course Introduction In this part we'll discuss course mechanics. Most of this will apply to all sections of the.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm.
CS0004: Introduction to Programming Variables – Strings.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
This material is approved for public release. Distribution is limited by the Software Engineering Institute to attendees. Sponsored by the U.S. Department.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Fundamental Programming: Fundamental Programming Introduction to C++
142 F -1 Functions chapter 3 of the text int main(void) { double x,y,z; … x = cube(y/3.0); … printf(“%f cubed is %f”,x,cube(x)); … return 0; } double cube(double.
1 ENGI 2420 Structured Programming (Lab Tutorial 4) Memorial University of Newfoundland.
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
C++ Programming Lecture 11 Functions – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
Functions Overview Functions are sequence of statements with its own local variables supports modularity, reduces code duplication Data transfer between.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
1 ENGI 2420 Structured Programming (Lab Tutorial 8) Memorial University of Newfoundland.
1 ENGI 2420 Structured Programming (Lab Tutorial 5) Memorial University of Newfoundland.
CS1201: PROGRAMMING LANGUAGE 2 FUNCTIONS. OVERVIEW What is a Function? Function Prototype Vs Decleration Highlight Some Errors in Function Code Parameters.
The Hashemite University Computer Engineering Department
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
1 ENGI 2420 Structured Programming (Lab Tutorial 1) Memorial University of Newfoundland.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
Week 6 - Friday.  What did we talk about last time?  Loop examples.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
1 Project 5: Leap Years. 222 Leap Years Write a program that reads an integer value from the user representing a year and determines if the year is a.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
1 ENGI 2420 Structured Programming (Lab Tutorial 2) Memorial University of Newfoundland.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
DEVRY CIS 170 C I L AB 2 OF 7 D ECISIONS Check this A+ tutorial guideline at decisions For.
DEVRY CIS 170 C I L AB 5 OF 7 A RRAYS AND S TRINGS Check this A+ tutorial guideline at
User-Written Functions
Chapter 7: User-Defined Functions II
Completing the Problem-Solving Process
Testing and Debugging.
CSCI 161: Introduction to Programming Function
Outline Altering flow of control Boolean expressions
User-defined Functions
Programming Funamental slides
Looping III (do … while statement)
A car is decelerated to 20 m/s in 6 seconds
Session 2: Introduction to Object Oriented Programming
Functions continued.
Code-development strategies
Compiler Structures 1. Overview Objective
SPL – PS3 C++ Classes.
Presentation transcript:

1 ENGI 2420 Structured Programming (Lab Tutorial 3) Memorial University of Newfoundland

ENGI 2420 – Structured Programming Lab Tutorial Problems in Assignment-2 3.2Some Reminders 3.3Assignment-3 Lab Tutorial 3

ENGI 2420 – Structured Programming Lab Tutorial 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

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

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

ENGI 2420 – Structured Programming Lab Tutorial 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/ Some Reminders

ENGI 2420 – Structured Programming Lab Tutorial 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

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

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

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

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) = Assignment-3

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) = Assignment-3

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) = Assignment-3