1-6 Midterm Review.

Slides:



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

Chapter 5 C Functions The best way to develop and maintain a large program is to divide it into several smaller program modules, each of which is more.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program Modules in C 5.3Math Library Functions 5.4Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Review for midterm exam Dilshad M. Shahid Spring NYU.
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
 2007 Pearson Education, Inc. All rights reserved C Functions.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
 2007 Pearson Education, Inc. All rights reserved C Functions.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined.
C Lecture Notes Functions (Cont...). C Lecture Notes 5.8Calling Functions: Call by Value and Call by Reference Used when invoking functions Call by value.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined functions, classes –Prepackaged: from the.
Repetition (Loops) Want to do some repetitive sequence of actions: print vertical line of *s * Corresponding program: printf(“*\n”);
FunctionsFunctions Systems Programming Concepts. Functions   Simple Function Example   Function Prototype and Declaration   Math Library Functions.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
1 Storage Classes, Scope, and Recursion Lecture 6.
 2006 Pearson Education, Inc. All rights reserved Arrays.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
18-2 Understand “Scope” of an Identifier Know the Storage Classes of variables and functions Related Chapter: ABC 5.10, 5.11.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
 2007 Pearson Education, Inc. All rights reserved C Functions.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Chapter 6: User-Defined Functions
Chapter 6 Arrays Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 2007 Pearson Education, Inc. All rights reserved C Functions -Continue…-
Chapter 5 - Functions Outline 5.1Introduction 5.2Program Modules in C 5.3Math Library Functions 5.4Functions 5.5Function Definitions 5.6Function Prototypes.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Lecture 13: Working with Multiple Programmers. Headers Header files: Each standard library has a corresponding header. The function prototype for all.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Dale Roberts CSCI 230 Functions Scope, Parameter Passing, Storage Specifiers Department of Computer and Information Science, School of Science, IUPUI Dale.
EPSII 59:006 Spring Call-by-value example #include void increment(int); //prototype for increment function int main(void) { int a=1; printf("Value.
KIC/Computer Programming & Problem Solving 1.  Header Files  Storage Classes  Scope Rules  Recursion Outline KIC/Computer Programming & Problem Solving.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
1 Lecture 3 Part 2 Storage Classes, Scope, and Recursion.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
 2000 Prentice Hall, Inc. All rights reserved Program Components in C++ Function definitions –Only written once –These statements are hidden from.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Functions Course conducted by: Md.Raihan ul Masood
UMBC CMSC 104 – Section 01, Fall 2016
C Functions -Continue…-.
5 C Functions.
Lecture 7: Repeating a Known Number of Times
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
CSC113: Computer Programming (Theory = 03, Lab = 01)
Deitel- C:How to Program (5ed)
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 5 - Functions Outline 5.1 Introduction
Functions.
Chapter 5 - Functions Outline 5.1 Introduction
Scope, Parameter Passing, Storage Specifiers
C Arrays.
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
C Arrays.
7 Arrays.
Chapter 6 - Functions Outline 5.1 Introduction
Arrays Outline Introduction Arrays Declaring Arrays
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
6 C Arrays.
Function.
Arrays.
Programming Languages and Paradigms
Function.
Presentation transcript:

1-6 Midterm Review

Review chapter 1-6 Variables, arithmetic, decision making Structured program development in C C program controls C Functions C Arrays Midterm exam rules, scope, and tips

1: Variables, Arithmetic, Decision making Memory Concepts Understand variables: type, size, value Arithmetic in C Remember the precedence of arithmetic operators Decision Making: Equality and Relational Operators Remember the meaning and syntax of equality and relational operators

2: Structured Program Development in C Basic problem-solving techniques 2 important primary steps Thorough understanding of the problem Carefully plan an approach for solving it Algorithms, Pseudo code, control structures Formulating Algorithm with Top-down, stepwise refinement case 3 phases programming Initialization, processing, and termination Control statements If…else, while, nested control, counter and sentinel controlled repetition Operators: assignment, increment, decrement

3: Program control Essential of counter-controlled repetition Control statements: Pretest loop: for Posttest loop: do … while Multiple selection: switch Alter flow control: break continue Complex conditional expressions

3.1: Pretest Loop for Syntax: Init: assignments to counter variables for ( init ; condition ; update ) statement; Init: assignments to counter variables Update: changes to counter variables

3.1: For Example Printing vertical line of stars: for (counter = 0; { printf(“*\n”);}

3.2: Posttest Loop do-while Syntax: do { statement(s) } while (condition);

3.2: Using the do-while do { printf(“\n Enter id# and salary: “); scanf(“%d %f”,&id,&salary); printf(“\n You entered id#%1d”, id); printf(“ and salary $%.2f,”, salary); printf(“ Is this correct? (Y/N) ” ); scanf(“ %c”,&ans); } while ((ans != ‘Y’) && (ans != ‘y’)); Loop always executes at least once

3.3: Multiple selection - Switch Useful when a variable or expression is tested for all the values it can assume and different actions are taken Format Series of case labels and an optional default case switch ( value ){ case '1': actions case '2': default: } break; exits from statement

3.4: Break statement The break statement can be used to halt a loop. do { scanf(“%d”,&num); if (num < 0) break; /* Loop ends */ } while (num != 0);

3.5: Continue statement A continue statement says jump past any remaining statements Example: for (I = 0; I < 100; I++) { if ((I % 2) == 1) continue; printf(“%d is even”,I); // continue goes to here: end of // statements }

3.6: Logical operators

4: C Functions Program modules in C Function definitions and prototypes Function call stack and activation records Headers Calling function by value and reference Functions Math library functions rand() Recursion

Fig. 5.1 | Hierarchical boss function/worker function relationship. 4.1: Program modules in C Fig. 5.1 | Hierarchical boss function/worker function relationship.

4.2: Function definition & Prototypes Function definition format return-value-type function-name( parameter-list ) { declarations and statements } Function Prototypes Function name, Parameters, Return type (default int) Used to validate functions Prototype only needed if function definition comes after use in program int maximum( int x, int y, int z ); Takes in 3 ints Returns an int

4.3: Function call stack and activation records Program execution stack: Last-in, first-out data structure Keep track of which functions have been called Activation records: Multiple function can be activated at the same time Each function has an activation record (Stack frame) Stack overflow: # activation records > memory capacity

4.4: Function headers Header files Custom header files Contain function prototypes for library functions <stdlib.h> , <math.h> , etc Load with #include <filename> #include <math.h> Custom header files Create file with functions Save as filename.h Load in other files with #include "filename.h" Reuse functions

4.5: Calling Functions Call by value Call by reference Copy of argument passed to function Changes in function do not effect original Use when function does not need to modify argument Avoids accidental changes Call by reference Passes original argument Changes in function effect original Only used with trusted functions

4.6 Storage class Identifier attributes: Storage class specifiers: Storage duration – how long an object exists in memory Scope – where object can be referenced in program Linkage – specifies the files in which an identifier is known Storage class specifiers: Automatic storage duration: Auto, Register Static storage duration: Extern, Static

4.7: Scope rules Identifier scopes: Function scope: File scope: Can only be referenced inside a function body Used only for labels (start:, case: , etc.) File scope: Identifier defined outside function, known in all functions Used for global variables, function definitions, function prototypes Block scope: Identifier declared inside a block Local variables of function

4.8: Recursion (1) Recursive functions Recursion vs. Iteration Functions that call themselves Can only solve a base case Recursion vs. Iteration Repetition Iteration: explicit loop Recursion: repeated function calls Termination Iteration: loop condition fails Recursion: base case recognized Both can have infinite loops

4.8: Recursion (2) Example: factorials Notice that 5! = 5 * 4 * 3 * 2 * 1 Notice that 5! = 5 * 4! 4! = 4 * 3! ...

5: C Arrays Array data structure Passing arrays to functions Sorting, searching arrays Multiple-Subscripted arrays

5.1: Array data structure Structure: To refer to an element, specify Group of consecutive memory locations Same name and type To refer to an element, specify Array name Position number Format: arrayname[ position number ] Defining arrays arrayType arrayName[numberOfElements ];

5.2: Passing arrays to functions Arrays passed call-by-reference Name of array is address of first element Syntax: Function_name ( array_name, array_size ); Passing array elements Passed by call-by-value Pass subscripted name (i.e., myArray[ 3 ]) to function Function prototype void modifyArray( int b[], int arraySize );

5.3 Sorting & Searching Arrays Sorting arrays Bubble sort Computing: Mean, Median, Mode Searching arrays Linear Binary Recursive & Interative

5.4: Multiple-Subscripted arrays Tables with rows and columns (m by n array) Like matrices: specify row, then column Initialization int b[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } }; Referencing elements Specify row, then column

Midterm exam rules, scope, & tips You are not allowed to refer to any materials except one cheating paper. The examination starts at 9:00 AM and ends at 10:30AM sharp. You can leave any time if you want before 10:30PM. Scope: Chapter 1-6 Tips: Review all lecture slides Review all class assignments and home works Do all Self-Review exercises after each chapter in text book Practice as many as possible