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

Slides:



Advertisements
Similar presentations
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Advertisements

Team 5220 Roboknights. Outline  Getting Started  Hardware Setup/Wiring  Software Setup/Pragmas  Programming with RobotC  Grammar/Syntax  Basic Statements.
1 ENGI 2420 Structured Programming (Lab Tutorial 0) Memorial University of Newfoundland.
Lecture 2 Introduction to C Programming
Introduction to C Programming
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 Midterm Review COMP 102. Tips l Eat a light meal before the exam l NO electronic devices (including calculators, dictionaries, phones, pagers, etc.)
Basic Elements of C++ Chapter 2.
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Chapter 5: Control Structures II (Repetition)
FALL 2001ICOM Lecture 21 ICOM 4015 Advanced Programming Lecture 2 Procedural Abstraction Reading: LNN Chapter 4, 14 Prof. Bienvenido Velez.
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
Copyright © 2012 Pearson Education, Inc. Chapter 6: Functions.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Chapter 5 Control Structure (Repetition). Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
1 ENGI 2420 Structured Programming (Lab Tutorial 4) Memorial University of Newfoundland.
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
1 Structure of a C Program (continued) Presentation original from Dr. Turner’s class USF - COP C for Engineers Summer 2008.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
1 ENGI 2420 Structured Programming (Lab Tutorial 8) Memorial University of Newfoundland.
Chapter Functions 6. Modular Programming 6.1 Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules.
Chapter 7 Implementation. Implementation Approaches F Big bang –Code entire system and test in an unstructured manner F Top-down –Start by implementing.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
1 ENGI 2420 Structured Programming (Lab Tutorial 1) Memorial University of Newfoundland.
1 ENGI 2420 Structured Programming (Lab Tutorial 3) Memorial University of Newfoundland.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 6: Functions.
Comments, Conditional Statements Continued, and Loops Engineering 1D04, Teaching Session 4.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Lecture 4 – Function (Part 1) FTMK, UTeM – Sem /2014.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Testing Programs with Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1 ENGI 2420 Structured Programming (Lab Tutorial 2) Memorial University of Newfoundland.
Learning Javascript From Mr Saem
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
Chapter # 2 Part 2 Programs And data
Chapter Topics The Basics of a C++ Program Data Types
Introduction to Programming
Basic Elements of C++.
C++ Basic Syntax – Homework Exercises
Functions, variables, operators, loops Modularity
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
6 Chapter Functions.
Module 2: Understanding C# Language Fundamentals
CMSC 202 Java Primer 2.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Based on slides created by Bjarne Stroustrup & Tony Gaddis
1-6 Midterm Review.
DATA TYPES There are four basic data types associated with variables:
Instructor: Hidayah Elias Course: COMPUTER PROGRAMMING (BFC 2042)
Standard Version of Starting Out with C++, 4th Edition
Did a few weeks ago. tag would work..
Presentation transcript:

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

ENGI 2420 – Structured Programming Lab Tutorial 5 2 Assignment 4 -- Style  Readability –No or incorrect indentation. –Poor choice of names  Too many redundant parentheses Too many parentheses hurt readability sum = ((sum)+((sign)*(power(x,i)/factorial(i))) ; A few redundant parentheses can reinforce precedence rules. This is fine. sum = sum + (sign * power(x,i) * factorial(i)) ; Spacing reinforces precedence rules. Also fine. sum = sum + sign*power(x,i)*factorial(i) ;  Unneeded if statements  Variables declared before loop rather than in the loop.  Comments –No documentation of local variables. –No function header comments

ENGI 2420 – Structured Programming Lab Tutorial 5 3 Assignment 4 -- Correctness  Compilation –Failing to declare a function before it is used.  Bugs –Summing the wrong number of terms –Failing to initialize variables before they are used. –Make a habit of declaring variables only when they are ready to be initialized. –Incorrect factorial calculation. –Infinite loops.

ENGI 2420 – Structured Programming Lab Tutorial 5 4 Assignment 4 -- Copying  Many assignments were copied  We will be dealing with these cases  The effect was plainly visible on the midterm.  Doing the assignments is integral to understanding the material,  which (if you need further motivation) is important come exam time.

ENGI 2420 – Structured Programming Lab Tutorial 5 5 Assignment-5  Structure of C++ files - assign5.h: contains the declarations for the functions - assign5.cpp: contains your implemented functions (submit this one via web-submit) - your own test code in a separate.cpp file (do NOT submit your test code)  Implement two functions as follows

ENGI 2420 – Structured Programming Lab Tutorial 5 6 Function 1  bool lineParameters(double x1, double y1, double x2, double y2, double& a, double& b)  Given the (x,y) coordinates of two points, find the parameters, a and b for the equation of a line, y = a*x + b, going through the two points, if possible (using the slope and y-intercept approach)  If the line can't be represented in this form then the function should return false, otherwise it should return true.  Must define and call at least two additional functions to i) compute the slope of the line connecting the points and ii) find the y-intercept of the line given its slope and a point on the line.

ENGI 2420 – Structured Programming Lab Tutorial 5 7 Execution Example (I)  (0.0, 0.0) and (10.0, 10.0) will return true –and give 1.0*x  (3.0, 3.0) and (6.0, 4.0) will return true –and give 0.333*x  (3.0,3.0) and (3.0, 4.0) will give a false result –there is no need to assign to the a and b parameters

ENGI 2420 – Structured Programming Lab Tutorial 5 8 Function 2  double outstandingDebt (double principle, double interestRate, double payment, int periods)  Returns the amount that will be outstanding on a loan after periods payments of $payment have been made, assuming that the original loan amount was $principle and that the interest rate per period is interestRate, as a decimal (i.e., 0.05 represents a rate of 5%)  Interest should be computed once per period and added to the principle before the payment is deducted  Use loops to do the calculation iteratively

ENGI 2420 – Structured Programming Lab Tutorial 5 9 Execution Example (II) outstandingDebt (100.00, 0.10, 20.0, 3) Periods passedDebt

ENGI 2420 – Structured Programming Lab Tutorial 5 10 Top-down design & bottom-up testing  Top down design –First I pseudo code lineParameters –As I write lineParameters I specify its auxiliary functions. –Then I write the auxiliary functions  Bottom up testing –First I test functions that call no others –I only test a function once I am certain all functions it calls are working.