FALL 2001ICOM 4015 - Lecture 01 ICOM 4015 Advanced Programming Lecture 0 Review of Programming I Reading: LNN Chapters 1-3,5-6.

Slides:



Advertisements
Similar presentations
Chapter 8 Technicalities: Functions, etc. Bjarne Stroustrup
Advertisements

Programming Languages and Paradigms
Chapter 7: User-Defined Functions II
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Software Engineering and Design Principles Chapter 1.
Chapter 14: Overloading and Templates C++ Programming: Program Design Including Data Structures, Fifth Edition.
Chapter 11 Separate Compilation and Namespaces Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program Modules in C 5.3Math Library Functions 5.4Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
COMP205 Comparative Programming Languages Part 1: Introduction to programming languages Lecture 3: Managing and reducing complexity, program processing.
Outline Java program structure Basic program elements
1 Introduction to Computers and Programming Quick Review What is a Function? A module of code that performs a specific job.
1) More on parameter passing: a) Parameter association b) Default parameters c) Procedures as parameters 2) Modules: Ada packages, C modules, C header.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
1 CS 105 Lecture 3 Constants & Expressions Wed, Jan 26, 2011, 4:15 pm.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined.
Guide To UNIX Using Linux Third Edition
Chapter 15: Operator Overloading
1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined functions, classes –Prepackaged: from the.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
FALL 2001ICOM Lecture 21 ICOM 4015 Advanced Programming Lecture 2 Procedural Abstraction Reading: LNN Chapter 4, 14 Prof. Bienvenido Velez.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
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.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Functions in C Programming Dr. Ahmed Telba. If else // if #include using namespace std; int main() { unsigned short dnum ; cout
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Built-In and user-Defined functions Software Design Concepts Lecture IV Dr. Sothy Vignarajah.
38 4/11/98 CSE 143 Modules [Chapter 2]. 39 4/11/98 What is a Module?  Collection of related items packaged together  Examples:  Stereo System Components.
C++ Programming Lecture 11 Functions – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
Manish K Parmar PGT (CS) K V VVNagar Thursday, December 24, 2015 Lesson on USER DEFINED FUNCTION IN C++ Presented by Manish K Parmar PGT Computer Science.
1 MODULAR DESIGN AND ABSTRACTION. 2 SPECIFYING THE DETAILS OF A PROBLEM INTO A RELATED SET OF SMALLER PROBLEMS.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
CSci 162 Lecture 8 Martin van Bommel. Large-scale Programming Up to now we have been writing relatively short programs to solve simple problem Want to.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
Dale Roberts CSCI N305 Functions Declarations Department of Computer and Information Science, School of Science, IUPUI.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
FALL 2001ICOM Lecture 11 ICOM 4015 Advanced Programming Lecture 1 Computer/Human Interaction Readings: LMM 2.3 & 3.3 Prof. Bienvenido Velez.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
TK1924 Program Design & Problem Solving Session 2011/2012
Computing and Statistical Data Analysis Lecture 2
CSC113: Computer Programming (Theory = 03, Lab = 01)
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 5 - Functions Outline 5.1 Introduction
Functions Declarations CSCI 230
Chapter 6 - Functions Outline 5.1 Introduction
Review of C++ Language Basics
Summary of what we learned yesterday
Fundamental Programming
Presentation transcript:

FALL 2001ICOM Lecture 01 ICOM 4015 Advanced Programming Lecture 0 Review of Programming I Reading: LNN Chapters 1-3,5-6

FALL 2001ICOM Lecture 02 Review of Programming I Lecture Outline Course Information C++ Basics Writing modular programs Separate Compilation Definitions and Summary of Concepts

FALL 2001ICOM Lecture 03 Course Information Favor leer el prontuario HOY! Asistencia requerida Correo electronico requerido –asumimos mensaje recibido en 48 horas Laboratorios requeridos Evaluacion –36% Examen Final –34% Examenes parciales (3) –20% Programas –10% Laboratorio Website del curso

FALL 2001ICOM Lecture 04 Roots of 2x 2 + 3x + 4 A monolithic program (A typical INGE3016 approach) > gcc roots1.cc -o roots1 > roots1 root1 = 2.0 root2 = ?? > Hard-coded values user interface (UI) mixed up with main computation monolithic => low modularity => low reusability Potential Runtime error #include int main() { float a = 1.0; float b = 4.0; float c = 4.0; float d = b * b * a * c; float root1 = (-b + sqrt(d)) / (2.0 * a); float root2 = (-b - sqrt(d)) / (2.0 * a); cout << “root1 = ” << root1 << endl; cout << “root2 = ” << root2 << endl; return 0; } roots.cc SHELL

FALL 2001ICOM Lecture 05 Roots of 2x 2 + 3x + 4 A monolithic program Suggest improvements to our design:

FALL 2001ICOM Lecture 06 function contract function parameters local declaration Roots of ax 2 + bx + c Modular design using functions #include #include “roots.h” // roots(a, b, c, r1, r2) - returns the number of // real roots of ax^2 + bx + c. If two roots exists // they are returned is r1 and r2. If only one root // exists, it is returned in r1. Otherwise the value // of r1 and r2 is undetermined. int roots(float a, float b, float c, float& r1, float& r2) { float d = b * b * a * c; if (d < 0) { return 0; } r1 = (-b + sqrt(d)) / (2.0 * a); if (d == 0) { return 1; } r2 = (-b - sqrt(d)) / (2.0 * a); return 2; } roots.cc

FALL 2001ICOM Lecture 07 Roots of ax 2 + bx + c Modular design using functions // rootsUI.cc // Simple text-based interactive user interface for // finding the roots of polynomials #include void readCoefficients(float& a, float& b, float& c) { cout << "Enter coefficient for cuadratic term (a): "; cin >> a; cout << "Enter coefficient for linear term (b): "; cin >> b; cout << "Enter coefficient for constant term (c): "; cin >> c; } void reportRoots(float a, float b, float c, int numRoots, float root1, float root2) { cout << "a = " << a << " b = " << b << " c = " << c << ":: "; switch (numRoots) { case 0: cout << "No real roots" << endl; break; case 1: cout << "One real root: " << root1 << endl; break; case 2: cout << "Two real roots: " << root1 << " and " << root2 << endl; break; default: cout << "Error: bad number of roots" << endl; } rootsUI.cc

FALL 2001ICOM Lecture 08 // rootsMain.cc // Main module for finding the roots of polynomials #include "roots.h" #include "rootsUI.h" int main() { float a,b,c; readCoefficients(a, b, c); float root1, root2; int numRoots = roots(a, b, c, root1, root2); reportRoots(a, b, c, numRoots, root1, root2); } // rootsUI.h // Header File // Simple text-based interactive user interface for // finding the roots of polynomials extern void readCoefficients(float& a, float& b, float& c); extern void reportRoots(float a, float b, float c, int numRoots, float root1, float root2); // roots(a, b, c, r1, r2) - returns the number of // real roots of ax^2 + bx + c. If two roots exists // they are returned is r1 and r2. If only one root // exists, it is returned in r1. Otherwise the value // of r1 and r2 is undetermined. extern int roots(float a, float b, float c, float& r1, float& r2); Roots of ax 2 + bx + c Modular design using functions rootsMain.cc roots.h rootsUI.h Main module glues everything together Keep it simple! Header files provide linkage information

FALL 2001ICOM Lecture 09 Complete Layered Application MAIN rootsMain.cc POLY ROOTS COMPONENT roots.cc API USER INTERFACE rootsUI.cc API rootsUI.hroots.h

FALL 2001ICOM Lecture 010 Separate Compilation object files source files compile roots roots.cc compile roots.o rootsUI.cc compile rootsUI.o rootsMain.cc compile rootsMain.o link time compile time run time executable files

FALL 2001ICOM Lecture 011 Layered Software Design Library/Component Appl Programming Interface (API) GUI Text-based Interactive Interface Text-based Batch Interface

FALL 2001ICOM Lecture 012 An Alternative Use of roots Function Finding the roots of polynomials with integer coefficients in [0, 4) #include #include “roots.h” int main() { for (float a = 0; a < 4; a++) { for (float b = 0; b < 4; b++) { for (float c = 0; c < 4; c++) { float root1 = 0.0; float root2 = 0.0; int rootNo = roots(a, b, c, root1, root2) switch (rootNo) { case 0: cout << “No real roots” break; case 1: cout << “One real root: “ << root1 << endl; break; case 2: cout << “Two real roots: “ << root1 << “ and “ << root2 << endl; break; default: cout << “Ërror: bad number of roots” << endl; } rootsMany.cc

FALL 2001ICOM Lecture 013 Example 3 Factorization of an integer #include int factors(int number) { int factors = 0; int quotient = number; // outer loop computes next quotient while (quotient > 1) { // inner loop finds next factor for (int factor = 2; factor <= quotient; factor++) { if (quotient % factor == 0) { cout << “Next factor is: “ << factor << endl; factors++; break; } quotient /= factor; } return factors; } Challenge: Can we find a faster algorithm? A Brute Force Algorithm: Why?

FALL 2001ICOM Lecture 014 Definitions and Summary of Concepts I Monolithic code –Very few reusable components Modular code –Lots of reusable pieces or “modules” –Modules can be code segments, functions, files, classes, etc. Self-documenting code –Easier to read, understand and maintain –Techniques include: meaningful indentation/alignment meaningful “semantic” naming concise comments when needed simplicity of expressions Abstraction – Hides irrelevant detail –Via naming (e.g. named constants) –Via parameterization (e.g. functions) –Tool for controlling complexity of software Hard-coding –The opposite of parameterization –Parameter values explicitly specified in code

FALL 2001ICOM Lecture 015 Definitions and Summary of Concepts II Scope rules –Local declarations take precedence over global ones –Less need to worry about name collisions –Facilitate modularity Separate compilation (C++ version) –A program can consists of several separate file modules –Compiler links the modules together –Modules import declarations of other modules via #include of header files containing declarations –File modules provide another unit of modularity Library –Reusable object file providing definitions of general purpose constants, variables, functions, types, classes and other objects.

FALL 2001ICOM Lecture 016 Definitions and Summary of Concepts III Compile-time error –Detected by compiler –Examples: Syntax error (missing ;) Undefined identifiers Runtime error –Undetectable (in general) by compiler –Examples Array bounds violation Division by zero Square root of a negative Software development cycle –Gather/Specify requirements –Design –Code –Test –Maintain