Lecture 6 Builtin Functions - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Lecture 6 Builtin Functions

Description:

Functions. Blocks of code that perform a specific task ... Purposes of Functions. Make problem solving easier ... Mathematical Functions. Defined in the math.h ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 18
Provided by: jimand
Category:

less

Transcript and Presenter's Notes

Title: Lecture 6 Builtin Functions


1
Lecture 6Built-in Functions
  • ENGR17 Engineering Programming
  • Section 1
  • Fall 2001

9/21/01
2
Outline
  • What are functions
  • Purpose of functions
  • String functions (review)
  • Math functions
  • Other functions

3
Functions
  • Blocks of code that perform a specific task
  • Allow programmers to write programs quickly and
    easily
  • Two Types
  • Built-in Functions
  • User-Defined Functions
  • Some functions that are built into the C
    language
  • pow
  • strcpy
  • Some are created by the programmer
    (programmer-defined functions)
  • main
  • More next week

4
String Functions
All of these functions require include ltstring.hgt
5
Purposes of Functions
  • Make problem solving easier
  • Allow programmers to break large and complex
    problems into small and manageable tasks
  • Speed up program writing by allowing programmers
    to use existing code to perform common tasks
  • Omit the need for duplication of code in
    different parts of the program(can be used as
    many times as necessary)

6
Mathematical Functions
  • Defined in the math.h header file
  • Can be used by entering the include ltmath.hgt
    directive in the program

7
Mathematical Functions
Need math Functions here
8
pow Function
  • Used to raise a number to a power XN
  • Syntax pow(base,exponent)
  • Actual arguments (base, exponent) represent
    information that is sent to a function
  • Function returns the result as type double
  • Need to do a type conversion if you put the
    result of the function into a variable that is
    not a double

9
pow Function
10
sqrt Function
  • Used to calculate the square root of a number
    stored in a variable ?X
  • Syntax sqrt(number)
  • Returns type double

11
Using Math Functions
Add math.h
Use math Functions here
12
Other types of functions
  • There are many other types of built-in functions
  • Input/Output
  • Graphics
  • Others
  • In addition, we can create our own functions
  • Next lecture

13
Summary
  • Understand what functions are and why are they
    used
  • Know the 4 string functions and how they are used
  • Know the 2 math functions and how they are used

14
General Notes on Exam 1
  • In Loma 4 (Lecture Room)
  • Closed book
  • Come early Donuts and Juice starts at 730am
  • Types of Questions (total of 100 points)
  • Short Answer (about 20 questions worth 2 or 3
    points each)
  • 2 or 3 Programs (worth 60 points total)
  • What to study
  • Class notes
  • Questions at end of lectures
  • In-class assignments
  • Labs
  • Homework assignments

15
Exam 1 Review
  • Lecture 1
  • History of PC
  • Components of PC
  • History of Programming Languages
  • Object-oriented languages
  • Control Structures
  • Lecture 2
  • Six problem-solving steps used to create a
    computer program
  • Complete an IPO chart
  • Plan an algorithm using pseudocode and flowcharts
  • Desk-check an algorithm
  • Code and execute the algorithm

16
Exam 1 Review
  • Lecture 3
  • Style
  • Variables
  • Literal Constants
  • Select an appropriate name, data type, and
    initial value for a variable
  • Create and initialize a variable
  • Perform explicit type conversion
  • Lecture 4
  • Named Constants
  • Assignment Statements
  • Writing Equations
  • Precedence
  • Type conversion

17
Exam 1 Review
  • Lecture 5
  • String Data Type
  • Declarations
  • Individual Characters
  • Loading a String Variable
  • String Functions
  • Reading a String from Keyboard
  • Lecture 6
  • What are functions
  • Purpose of functions
  • String functions
  • Math functions
  • Any other questions????
Write a Comment
User Comments (0)
About PowerShow.com