CS 108 Computing Fundamentals Notes for Tuesday, September 19, 2017

Slides:



Advertisements
Similar presentations
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Advertisements

Chapter 13 – Introduction to Classes
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
Using CourseCompass Features You must already be registered or enrolled in a current class.
Using MyMathLab Features You must already be registered or enrolled in a current class.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 6 Functions.
1 11/05/07CS150 Introduction to Computer Science 1 Functions Chapter 6, page 303.
Using CourseCompass Features You must already be registered or enrolled in a current class.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
 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!
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Need your MyMathLab card with your access code Need a Valid Address Need to know Purdue’s zip code is and your course ID for your Class You.
Using MyMathLab Features You must already be registered or enrolled in a current MyMathLab class in order to use MyMathLab. If you are not registered or.
1 10/30/06CS150 Introduction to Computer Science 1 Functions Chapter 3, page 313.
CS 108 Computing Fundamentals Notes for Thursday, February 12, 2015.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
Using McGraw Hill’s Connect Dr. Capers. You will need publisher code from your book (comes with purchased textbook) Click on link for your class to find.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
CS 108 Computing Fundamentals Notes for Thursday September 10, 2015.
CS 108 Computing Fundamentals Notes for Tuesday, February 10, 2015.
CHAPTER 5 FUNCTIONS I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Using MyMathLab Features of MyMathLab You must already be registered or enrolled in a current MyMathLab class in order to use MyMathLab. If you are not.
ME 142 Engineering Computation I Exam 2 Review VBA.
Creating Programs on UNIX This term you can create programs on UNIX or you can create programs using a C++ compiler on your PC. This set of slides steps.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
CS 108 Computing Fundamentals Notes for Tuesday, September 22, 2015.
Chapter Functions 6. Modular Programming 6.1 Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Today’s Activity Solving Multi-Step Equations. Instructions You should have a baggie of colored strips. Using the strips provided, have each person of.
Chapter 6 Functions. 6-2 Topics 6.1 Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5.
Starting Out with C++, 3 rd Edition 1 Chapter 13 – Introduction to Classes Procedural and Object-Oriented Programming Procedural programming is a method.
1 Class 19 Chapter 13 – Creating a class definition.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Class Definitions: The Fundamentals Chapter 6 3/30/15 & 4/2/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Chapter 9: Value-Returning Functions
User-Written Functions
Let’s Get A Few Things Straight
Classes.
CS 108 Computing Fundamentals Notes for Thursday, September 14, 2017
CMSC202 Computer Science II for Majors Lecture 08 – Overloaded Constructors Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
Implementing Functions from a Detailed Design Quick Tips
Algorithm development
CS 108 Computing Fundamental Notes for Thursday, October 5, 2017
Using MyMathLab Features
Extra.
Announcements General rules about homeworks
6 Chapter Functions.
CS150 Introduction to Computer Science 1
For Wednesday No new reading No quiz.
CS 2308 Exam II Review.
Using MyMathLab Features
Announcements Homework 1 will be assigned this week,
Review for Final Exam.
Lecture 5- Classes, Objects and Methods
Using CourseCompass Features
Part 6 Q26 to Q30 of National 5 Prelim
Based on slides created by Bjarne Stroustrup & Tony Gaddis
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Announcements General rules about homeworks
Warm-Up #9 (Tuesday, 9/22/15)
Standard Version of Starting Out with C++, 4th Edition
Introduction to Methods and Interfaces
Agenda for Unit 3: Functions
Presentation transcript:

CS 108 Computing Fundamentals Notes for Tuesday, September 19, 2017

Review Quiz

Review GHP #8

Exam #1 (1) Tuesday, September 26 Chapters 2, 3, and UNIX tutorial only for closed-book part… up through and including programmer-created functions (PCFs) and GHP #8 for open-book part Use "Quick Check Exercises" and "Review Questions" in the textbook plus MPL exercises

Exam #1 (2) If you need to take the exam in the Learning Center Send me an e-mail reminding me Visit the Learning Center ASAP to make sure they are ready for you On Thursday I will collect official paperwork for accommodations if you have not already provided it Homework: do last semester’s Exam #1 I will e-mail is to you Do not make the mistake of thinking that your Exam #1 will be a copy of last semester's Exam #1 I'm showing you last semester's exam to give you a flavor of what could be on the exam and to give you an idea of what an exam looks like and what to expect (generally)

Let's Go Through an Entire Example (1) Let's write a program that calculates the area and the perimeter and of rectangle once the user provides a length and width input… let’s start by developing an algorithm Maximize the use of functions (like GHP #8) main( ) merely passes values and control to programmer-created functions (PCFs) We are going to violate the "Urban Inside-Out One Step at a Time Method" this time to view functions from a slightly different perspective

Let's Go Through an Entire Example (2) /********************************** Algorithm 1. Greet user 2. Ask for length 3. Read/record the length 4. Ask for width 5. Read/record the width 6. Calculate area (area = length * width ) 7. Calculate perimeter (perimeter = 2 * length + 2*width) 8. Display answer 9. Terminate **********************************/

Let's Go Through an Entire Example (3) /********************************** Algorithm 1. Greet user ………………………………………….…..…. PCF #1 2. Ask for length …………….……………………….….….. PCF #2 3. Read/record the length ……………………………….….. PCF #2 4. Ask for width .……………….………………………..….. PCF #3 5. Read/record the width ………………….…………….…... PCF #3 6. Calculate area (area = length * width ).………………….… PCF #4 7. Calculate perimeter (perimeter= 2 * length + 2* width.)…. PCF #5 8. Display answer ………………………………………….…. PCF #6 9. Terminate ………………………………………………..…. main( ) **********************************/ This link below shows the beginning of the source-code file with the algorithm at the top each algorithm step inside the main ( ) http://web.cs.sunyit.edu/~urbanc/cs_108_sep_19_1.txt

Let's Go Through an Entire Example (4) /********************************** Algorithm 1. Greet user ………………………………………….….…. PCF #1 2. Ask for length …………….……………………….…….. PCF #2 3. Read/record the length ………………………………….. PCF #2 4. Ask for width .……………….……………………….….. PCF #3 5. Read/record the width ………………….…………….….. PCF #3 6. Calculate area (area = length * width ).………………….… PCF #4 7. Calculate perimeter (perimeter= 2 * length + 2* width)…. PCF #5 8. Display answer ……………………………………………. PCF #6 9. Terminate …………………………………………………. main( ) *********************************/ In-class exercise: Given the algorithm above with the additional guidance about PCFs, develop, on paper, the prototypes for each of the 6 PCFs (use identifiers of your choice).

Let's Go Through an Entire Example (5) /********************************** Algorithm 1. Greet user ……………………………………………. .…PCF #1 2. Ask for length ……………….…………………………... PCF #2 3. Read/record the length ………………………………….. PCF #2 4. Ask for width .……………….…………………………... PCF #3 5. Read/record the width ………………….………………... PCF #3 6. Calculate are (area = length * width ).………………….… PCF #4 7. Calculate perimeter (perimeter= 2 * length + 2* width)…..PCF #5 8. Display answer ……………………………………………. PCF #6 9. Terminate ………………………………………………….. main( ) *********************************/ void intro_msg (void) ; // PCF #1 Prototype float get_length (void) ; // PCF #2 Prototype float get_width (void) ; // PCF #3 Prototype float calc_area (float , float) ; // PCF #4 Prototype float calc_perimeter (float , float) ; // PCF # 5 Prototype void display_answer (float , float) ; // PCF # 6 Prototype

Let's Go Through an Entire Example (6) In-class exercise: Given the prototypes below, develop, on paper, the calls for each of the 6 PCF prototypes … answers on next slide. void intro_msg (void) ; // PCF #1 Prototype float get_length (void) ; // PCF #2 Prototype float get_width (void) ; // PCF #3 Prototype float calc_area (float , float) ; // PCF #4 Prototype float calc_perimeter (float, float) ; // PCF # 5 Prototype void display_answer (float , float) ; // PCF # 6 Prototype

Let's Go Through an Entire Example (7) In-class exercise: Given the prototypes below, develop, on paper, the calls for each of the 6 PCF prototypes … calls below in green. void intro_msg (void) ; // PCF #1 Prototype float get_length (void) ; // PCF #2 Prototype float get_width (void) ; // PCF #3 Prototype float calc_area (float , float) ; // PCF #4 Prototype float calc_perimeter (float, float) ; // PCF # 5 Prototype void display_answer (float , float) ; // PCF # 6 Prototype intro_msg( ) ; length = get_length( ) ; width = get_width ( ) ; area = calc_area( length , width) ; perimeter = calc_perimeter( length , width ) ; display_answer ( area , perimeter ) ;

Let's Go Through an Entire Example (8) In-class exercise: Given the prototype and call below, develop, on paper, the declaration necessary. void intro_msg (void); // PCF #1 Prototype intro_msg( ) ; // PCF #1 Call

Let's Go Through an Entire Example (9) In-class exercise: Given the prototype and call below, develop, on paper, the declaration necessary. void intro_msg (void); // PCF #1 Prototype intro_msg( ) ; // PCF #1 Call // PCF #1 Declaration, no formal parameters and no return value void intro_msg (void) { printf("\n\nThis program does very little.\n\n\n"); return ; } http://web.cs.sunyit.edu/~urbanc/cs_108_sep_19_2.txt

Let's Go Through an Entire Example (10) In-class exercise: Given the prototype and call below, develop, on paper, the declaration necessary. float get_length (void); // PCF #2 Prototype length = get_length( ) ; // PCF #2 Call

Let's Go Through an Entire Example (11) In-class exercise: Given the prototype and call below, develop, on paper, the declaration necessary. float get_length (void); // PCF #2 Prototype length = get_length( ) ; // PCF #2 Call // PCF #2 Declaration, no formal parameters, a single float value // returned to the calling environment float get_length (void) { float llength =0.0; // Local variable llength declared printf("\nEnter the length of the rectangle: "); scanf("%f", &llength); // http://web.cs.sunyit.edu/~urbanc/cs_108_sep_19_3.txt return ( llength ); }

Let's Go Through an Entire Example (11b) In-class exercise: developing the get_width( ) declaration is very similar to developing the get_length( ) declaration http://web.cs.sunyit.edu/~urbanc/cs_108_sep_19_4.txt

Let's Go Through an Entire Example (12) In-class exercise: Given the prototype and call below, develop, on paper, the declaration necessary. float calc_area (float , float); // PCF #4 Prototype area = calc_area( length , width) ; // PCF #4 Call

Let's Go Through an Entire Example (13) In-class exercise: Given the prototype and call below, develop, on paper, the declaration necessary. float calc_area (float , float); // PCF #4 Prototype area = calc_area( length , width) ; // PCF #4 Call // PCF # 4 Declaration, two formal parameters // and a single float value returned float calc_area ( float ca_length, float ca_width ) { float ca_area = 0.0; // Local variable declared ca_area = ca_length * ca_width; return ( ca_area ); } http://web.cs.sunyit.edu/~urbanc/cs_108_sep_19_5.txt

Let's Go Through an Entire Example (14) PCF #5 is very similar to PCF #4… PCF #6 displays the answer http://web.cs.sunyit.edu/~urbanc/cs_108_sep_19_6.txt Complete example at this link : http://web.cs.sunyit.edu/~urbanc/cs_108_sep_19_7.txt