Scis.regis.edu ● CS-361: Control Structures Week 2 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.

Slides:



Advertisements
Similar presentations
Chapter 6: User-Defined Functions I
Advertisements

User Defined Functions
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Chapter 14: Overloading and Templates C++ Programming: Program Design Including Data Structures, Fifth Edition.
Chapter 14: Overloading and Templates
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 7: User-Defined Functions II.
Chapter 6: User-Defined Functions I
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
1 Chapter 7 User-Defined Methods Java Programming from Thomson Course Tech, adopted by kcluk.
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Top-Down Design with Functions 4 What do programmer’s (not programs!) use as input to the design of a program? –Documentation Problem definition Requirements.
1 Lecture 14:User-Definded function I Introduction to Computer Science Spring 2006.
Chapter 6: User-Defined Functions I
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 7: User-Defined Methods
Guide To UNIX Using Linux Third Edition
Chapter 15: Operator Overloading
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 14: Overloading and Templates.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Chapter 6: User-Defined Functions
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
CHAPTER 5 FUNCTIONS I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
USER-DEFINED FUNCTIONS. STANDARD (PREDEFINED) FUNCTIONS  In college algebra a function is defined as a rule or correspondence between values called the.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
Structure Programming Lecture 8 Chapter 5&6 - Function – part I 12 December 2015.
Scis.regis.edu ● CS-361: Control Structures Week 6 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
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.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
User Defined Methods Methods are used to divide complicated programs into manageable pieces. There are predefined methods (methods that are already provided.
CHAPTER 6 USER-DEFINED FUNCTIONS I. In this chapter, you will: Learn about standard (predefined) functions and discover how to use them in a program Learn.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
CHAPTER 6 USER-DEFINED FUNCTIONS Made By- Kartik Belwal.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
User-Defined Functions II TK1914: C++ Programming.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
USING & CREATING FUNCTIONS. MODULAR PROGRAMMING  Why Modular Programming?  Improves Readability & Understandability  Improve Maintainability  Allows.
Scis.regis.edu ● CS-362: Data Structures Week 6 Part 2 Dr. Jesús Borrego 1.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
TK1924 Program Design & Problem Solving Session 2011/2012
Chapter 9: Value-Returning Functions
Chapter 7 User-Defined Methods.
Chapter 6: User-Defined Functions I
Chapter 7: User-Defined Functions II
Java Programming: Guided Learning with Early Objects
User-Defined Functions
User Defined Functions
FUNCTION CSC128.
Chapter 7: User-Defined Functions II
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
Chapter 10: Void Functions
Presentation transcript:

scis.regis.edu ● CS-361: Control Structures Week 2 Dr. Jesús Borrego Lead Faculty, COS Regis University 1

Topics Homework #1 review Key Terms Chapter 6 (pp ) Activity #1 Chapter 7 (p. 362) Appendix F (pp ) Activity #2 Homework #2 2

Homework 1 Review Program 6, page 173 in the textbook Use coding standards Review inputs and outputs Submit Word documentation Submit to WorldClass/Desire to Learn before week 2 3

Key Terms Compiler – compilador Hard coded variable – valor usado en vez de constante I/O stream – flujo de entradas y salidas Linker – enlazador Object code – código objeto Server – ordenador, servidor, estación de trabajo Source code – código fuente Syntax and semantics – sintaxis y semántica Void type – sin tipo de variable Whitespace – líneas en blanco, espacio, indentar 4

scis.regis.edu ● C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 6: User Defined Functions I 5

Ch. 6: User Defined Functions Functions are like building blocks They allow complicated programs to be divided into manageable pieces Some advantages of functions: ▫A programmer can focus on just that part of the program and construct it, debug it, and perfect it ▫Different people can work on different functions simultaneously ▫Can be re-used (even in different programs) ▫Enhance program readability 6

Predefined Functions In algebra, a function is defined as a rule or correspondence between values, called the function’s arguments, and the unique value of the function associated with the arguments ▫If f(x)= 2x + 5, then  f(1)= 7, f(2)= 9, and f(3)= 11 ▫ 1, 2, and 3 are arguments ▫ 7, 9, and 11 are the corresponding values 7

Some Math Functions Some predefined mathematical functions are: sqrt(x) pow(x, y) floor(x) Predefined functions are organized into separate libraries I/O functions are in iostream header Math functions are in cmath header 8

Sample programs PredefinedFunctions.cpp 9

Activity 1 Type the program on page 323 by hand (Victor) Start with your template Compile and run Verify your output matches the sample run shown Submit the program and output to WorldClass Time: 30 minutes 10

11

12

Examples 13

scis.regis.edu ● C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 7: User Defined Functions II 14

Void Functions Void functions and value-returning functions have similar structures – Both have a heading part and a statement part User-defined void functions can be placed either before or after the function main If user-defined void functions are placed after the function main – The function prototype must be placed before the function main 15

Void Functions II A void function does not have a return type ▫ return statement without any value is typically used to exit the function early Formal parameters are optional A call to a void function is a stand-alone statement 16

Void Functions III 17 Function definition syntax: Formal parameter list syntax: Function call syntax Actual parameter list syntax

Void Functions IV 18

Sample programs VoidFunctions.cpp ASCII.cpp CalcGrade.cpp ▫Make sure you check the output of your programs VoidFunc_NoParam.cpp VoidFunc_Param.cpp 19

Parameters Value parameter: a formal parameter that receives a copy of the content of corresponding actual parameter Reference parameter: a formal parameter that receives the location (memory address) of the corresponding actual parameter 20

Parameter list 21

Value Parameters If a formal parameter is a value parameter ▫The value of the corresponding actual parameter is copied into it The value parameter has its own copy of the data During program execution ▫The value parameter manipulates the data stored in its own memory space 22

Reference Parameters If a formal parameter is a reference parameter – It receives the memory address of the corresponding actual parameter A reference parameter stores the address of the corresponding actual parameter During program execution to manipulate data – The address stored in the reference parameter directs it to the memory space of the corresponding actual parameter 23

Reference Parameters II Reference parameters can: – Pass one or more values from a function – Change the value of the actual parameter Reference parameters are useful in three situations: – Returning more than one value – Changing the actual parameter – When passing the address would save memory space and time 24

Sample Program Larger.cpp 25

Activity 2 We (all of us together) will write a program from scratch. Review textbook programming assignment #3 on page

scis.regis.edu ● C++ Programming: From Problem Analysis to Program Design, Fifth Edition Appendix F: Header Files 27

Header files See HeaderFiles.xlsx ▫Headers tab ▫Constants tab 28

Sample programs CharFunctions.cpp Strcat.cpp Strcat1.cpp 29

Activity 3 Work in groups of 2, but groups should be different from last class. Fix program on pages so that it returns the correct output. Include the header from the coding standards and include the names of the members of the group Submit your corrected program to WorldClass 30 minutes 30

Homework 2 Program 10 on page 174 Follow coding standards Review input and output ▫Create test cases Submit to WorldClass/Desire to Learn before week 3 31