Monday, 9/23/02, Slide #1 CS 106 Intro to CS 1 Monday, 9/23/02  QUESTIONS??  Today:  Discuss Lab 3  Do Exercises  Introduction to functions  Reading:

Slides:



Advertisements
Similar presentations
1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
Advertisements

Introduction to C++ Functions Chapter 6 Sections 6.1 – 6.3 Computer II.
Monday, 11/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Monday, 11/11/02  Questions? HW 04 due today at 5.  Today – Lists and an introduction to searching.
Introduction to Functions Programming. COMP102 Prog Fundamentals I: Introduction to Functions /Slide 2 Introduction to Functions l A complex problem is.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
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/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
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/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
Functions:Passing Parameters by Value Programming.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
 Wednesday, 9/25/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/25/02  QUESTIONS??  Today: More on functions  Reading: Chapter 3 through 3.7 
Monday, 10/14/02, Slide #1 CS 106 Intro to CS 1 Monday, 10/14/02  QUESTIONS??  Today: More on classes!  Reading: None new  Exercises: Implement and.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
General Computer Science for Engineers CISC 106 Lecture 30 Dr. John Cavazos Computer and Information Sciences 05/04/2009.
 Wednesday, 10/16/02, Slide #1 CS106 Introduction to CS1 Wednesday, 10/16/02  QUESTIONS??  Today:  Return and discuss Test #1  Input from and output.
Chapter 5: Control Structures II (Repetition)
Wednesday, 11/6/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/6/02  QUESTIONS?? – HW # 4 due Monday  Today:  Return HW #3  Arrays (Chap. 10)  Reading:
1 10/30/06CS150 Introduction to Computer Science 1 Functions Chapter 3, page 313.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
CHAPTER 5 FUNCTIONS I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
DATA STRUCTURES LAB 1 TA: Nouf Al-harbi
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
1 CS161 Introduction to Computer Science Topic #3.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
CPS120: Introduction to Computer Science Functions.
 Introduction to Computer Science COMP 51 – Fall 2012 – Section 2 Structures.
Vectors and Grids Eric Roberts CS 106B April 8, 2009.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
Chapter 7 Functions. Types of Functions Value returning Functions that return a value through the use of a return statement They allow statements such.
111/15/2015CS150 Introduction to Computer Science 1 Summary  Exam: Friday, October 17,  Assignment: Wednesday, October 15, 2003  We have completed.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
Functions Overview Functions are sequence of statements with its own local variables supports modularity, reduces code duplication Data transfer between.
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
1 MODULAR DESIGN AND ABSTRACTION. 2 SPECIFYING THE DETAILS OF A PROBLEM INTO A RELATED SET OF SMALLER PROBLEMS.
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 2/2/05CS250 Introduction to Computer Science II Pointers.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Manipulator example #include int main (void) { double x = ; streamsize prec = cout.precision(); cout
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
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.
Basic concepts of C++ Presented by Prof. Satyajit De
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
User Defined Functions
Value returning Functions
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
Chapter 6: User-Defined Functions I
CS150 Introduction to Computer Science 1
Functions Imran Rashid CTO at ManiWeber Technologies.
Introduction to Functions
Functions Divide and Conquer
Presentation transcript:

Monday, 9/23/02, Slide #1 CS 106 Intro to CS 1 Monday, 9/23/02  QUESTIONS??  Today:  Discuss Lab 3  Do Exercises  Introduction to functions  Reading:  New files/handouts: Lab03 exercises, FunctionEx1.cpp, FunctionEx2.cpp

Monday, 9/23/02, Slide #2 Chapter 3: Simple Functions  Modularity:  More complex programs are built by putting previously written “program modules” together  In C++ each “program module” is a function, with a name.  Each C++ program must have at least one function, namely the function named main().  We can define more functions that can then be used (“called”) from main()

Monday, 9/23/02, Slide #3 Example 1: A Function for Lab03Exercise.cpp  This file uses the following code five times:  We can write a function named Continue() that does this code for us (see FunctionEx1.cpp): int num; cout << "Enter a number to continue: " << endl; cin >> num; //Continue() Makes user input number to continue program void Continue() { int num; cout << "Enter a number to continue: " << endl; cin >> num; }

Monday, 9/23/02, Slide #4 Basic Function Syntax  The simplest kind of function is a void function with no parameters (empty parentheses after name). The syntax for function definition is:  To use a void function we define in a program, we can  1. Put its definition above the main() function  2. Use the function name inside main() as a complete statement. void FunctionName() { //declarations and statements }

Monday, 9/23/02, Slide #5 Function parameters  The function Continue() needed no information to do its job.  Some functions must be supplied with data when called in order to work  Example: Again from Lab 03, we could write a function that computes and prints a weighted average  This function must be supplied with homework grade, exam grade, and participation grade  In the line that calls the function these values are put inside the parentheses. The function copies and uses these values

Monday, 9/23/02, Slide #6 Example 2: A function to compute and print a weighted average  See FunctionEx2.cpp: //PrintAverage() Computes and prints a weighted // average of homework, exam, and participation grades void PrintAverage(double hw, double ex, double pa) { double HwWeight = 0.50; double ExWeight = 0.35; double PaWeight = 0.15; double av = hw * HwWeight + ex *ExWeight + pa * PaWeight; cout << endl << "Student average = " << av << endl; }