Introduction to C++ Programming Language

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

Introduction to C Programming
User Defined Functions
Chapter Five Functions
BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
16/11/2015 9:05 AM6/11/2015 9:05 AM6/11/2015 9:05 AMFunctions Functions A function consists of: Name Name Arguments (also called parameters) Arguments.
Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Chapter 6: User-Defined Functions I
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Chapter 6: User-Defined Functions
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
Functions Top-down design Breaking a complex problem into smaller parts that we can understand is a common practice. The process of subdividing a problem.
FUNCTIONS AND STRUCTURED PROGRAMMING CHAPTER 10. Introduction A c program is composed of at least one function definition, that is the main() function.
CPS120: Introduction to Computer Science Lecture 14 Functions.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
A First Book of ANSI C, Fourth Edition1 Functions for Modularity 04/24/15.
Introduction to C++ Programming Language Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University,
User defined functions
1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.
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: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
ECE 103 Engineering Programming Chapter 30 C Functions Herbert G. Mayer, PSU CS Status 8/9/2014 Initial content copied verbatim from ECE 103 material developed.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Chapter 9: Value-Returning Functions
Chapter 6: User-Defined Functions I
Chapter 7: User-Defined Functions II
Introduction to C++ computers and programming
Functions Review.
Chapter 10: Void Functions
FIGURE 4-10 Function Return Statements
Chapter 4 Procedural Abstraction and Functions That Return a Value 1
Chapter 5 Functions DDC 2133 Programming II.
Function There are two types of Function User Defined Function
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
CSCI 161: Introduction to Programming Function
User-Defined Functions
Starting Out with Programming Logic & Design
© 2016 Pearson Education, Inc.,Hoboken, NJ. All rights reserved.
FIGURE 4-10 Function Return Statements
User Defined Functions
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Chapter 4 Functions Objectives
6 Chapter Functions.
Writing Functions.
Introduction to C++ Programming Language
Topics discussed in this section:
FIGURE 4-10 Function Return Statements
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Starting Out with Programming Logic & Design
In C Programming Language
Introduction to Problem Solving and Programming
FIGURE 4-10 Function Return Statements
CPS125.
Scope Rules.
Presentation transcript:

Introduction to C++ Programming Language Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea

Announcement on Exam 1 10.8 (Monday) Scope: Chapter 1 ~ Chapter 4 (Until we’ve learned today) Effect on grading: 15% Written exam with closed book Good Luck!!

Chapter 4 Functions

Designing Structured Programs In top-down design, a program is divided into a main module and its related modules. Each module is in turn divided into submodules until the resulting modules are intrinsic; that is, until they are implicitly understood without further division.

Structure Chart

Functions in C++ In C++, a program is made of one or more functions, one and only one of which must be named main. The execution of the program always starts with main, but it can call other functions to do some part of the job.

Structure Chart for a C++ Program

Functions in C++ A function in C++ can have a value, a side effect, or both. The side effect occurs before the value is returned. The function’s value is the value of the expression in the return statement. A function can be called for its value, its side effect, or both.

Functions in C++

User-Defined Functions - Declaring, Calling, and Defining

Functions without Return Value (Only Have Side Effect)

Functions without Return Value (Only Have Side Effect) void functions cannot be used in an expression; they must be a separate statement. Functions that return a value may be used in an expression or as a separate statement.

Functions with Return Value

Function Definition

Function Return Statements

Function Local Variables

Notes on Parameters Formal parameters are variables that are declared in the header of the function definition. Actual parameters are the expressions in the calling statement. The formal and actual parameters must match exactly in type, order, and number. Their names, however, do not need to be the same.

Part of a Function Call The type of the expression in the return statement must match the return type in the function header.

Examples of Function Calls

Pass by Value Different local variables

Pass by Reference

A Bad Exchange

Calculate Quotient and Remainder

Default Parameter Arguments Default values for parameters can be defined in function declaration

Library Functions and the Linker

Standard Library Functions

Floor and Ceiling Functions

abs(), pow(), and sqrt() abs(3)  returns 3 fabs(-3.4)  returns 3.4 pow(3.0, 4.0)  returns 81 (3^4) pow(3.4, 2.3)  returns 16.687893 sqrt(25.0)  returns 5.0

Scope for Global and Block Areas

Scope for Global and Block Areas Variables are in scope from their point of definition until the end of their function or block. It is poor programming style to reuse identifiers within the same scope.