Functions Divide and Conquer

Slides:



Advertisements
Similar presentations
Introduction to Functions Programming. COMP102 Prog Fundamentals I: Introduction to Functions /Slide 2 Introduction to Functions l A complex problem is.
Advertisements

1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 11/05/07CS150 Introduction to Computer Science 1 Functions Chapter 6, page 303.
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
CS150 Introduction to Computer Science 1
1 9/8/08CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
1 9/26/07CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
111/15/2015CS150 Introduction to Computer Science 1 Summary  Exam: Friday, October 17,  Assignment: Wednesday, October 15, 2003  We have completed.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
1 COMS 261 Computer Science I Title: Functions Date: October 12, 2005 Lecture Number: 17.
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
Introduction to Functions.  A complex problem is often easier to solve by dividing it into several smaller parts, each of which can be solved by itself.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
1 2/2/05CS250 Introduction to Computer Science II Pointers.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
1 11/12/04CS150 Introduction to Computer Science 1 More Arrays.
13/15/2016CS150 Introduction to Computer Science 1 Summary  Assignment due on Wednesday, October 29,  Tutor will be in the lab on Tuesday evening,
Computer Skills2 / Scientific Colleges 1 Arrays Topics to cover: Arrays Data Types One-dimensional Arrays Two-dimensional Arrays.
Chapter five exercises. a. false; b. true; c. false; d. true; e. true; f. true; g. true; h. false.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
What Actions Do We Have Part 1
for Repetition Structures
C++ Arrays.
לולאות קרן כליף.
Function Basics.
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Modular Programming with Functions
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
switch Selection Structure
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Functions Divide and Conquer
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
CS150 Introduction to Computer Science 1
Arithmetic Operations
CS150 Introduction to Computer Science 1
do/while Selection Structure
What Actions Do We Have Part 1
CS150 Introduction to Computer Science 1
Fundamental Programming
CS250 Introduction to Computer Science II
Reading from and Writing to Files
CS150 Introduction to Computer Science 1
Life is Full of Alternatives
CS150 Introduction to Computer Science 1
Introduction to Functions
Reading from and Writing to Files Part 2
CS150 Introduction to Computer Science 1
Life is Full of Alternatives Part 3
Reading from and Writing to Files
Presentation transcript:

Functions Divide and Conquer 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Last Time We Completed discussing reading from and writing to files Today we will Begin learning about functions and modularity in C++ 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Problem Write a function that sums integers in a particular range Write a program that uses the above function 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Example #include <iostream> char isEven(int); int getVal(); int main(void) { int num; while ((num = getVal()) != -9999) if (isEven(num) == ‘E’) cout << “EVEN” << endl; else cout << “ODD” << endl; } return 0; 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Example (cont.) char isEven(int number) { const char even = ‘E’; const char odd = ‘O’; char answer; if (number % 2 == 0) answer = even; else answer = odd; return answer; } 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Example (cont.) int getVal() { int number; cout << “Enter an integer number: “; cin >> number; return number; } 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Program Write a program that calculates the area of a circle Write a program that calculates the area of a circle using three functions, getRadius, calcArea and outputArea 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Program Write a program that draws the following stick figure using functions and top down design. * * * * * / \ / \ / \ ------- 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Program Write a function that takes as input two numbers and returns the larger Write a function that takes as input two numbers and returns the smaller Write a function that computes the average given a sum and number of elements 10/25/04 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Summary In today’s lecture we covered Library functions Programmer defined functions Readings P. 170 - 180 10/25/04 CS150 Introduction to Computer Science 1