Programming Fundamental

Slides:



Advertisements
Similar presentations
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Advertisements

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.
1 Lecture 3 Part 1 Functions with math and randomness.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Lecture-13 Instructor Name: Muhammad Safyan Programming Fundamental.
Programming Fundamentals Lecture 4. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.
Functions in C Programming Dr. Ahmed Telba. If else // if #include using namespace std; int main() { unsigned short dnum ; cout
CPS120: Introduction to Computer Science Decision Making in Programs.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
CPS120: Introduction to Computer Science Lecture 14 Functions.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 6 - Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
GE 211 Dr. Ahmed Telba. // compound assignment operators #include using namespace std; int main () { a =5 int a, b=3; a = b; a+=2; // equivalent to a=a+2.
Lecture 12: Functions Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
 2000 Prentice Hall, Inc. All rights reserved. 5.2Program Modules in C Functions –Modules in C –Programs combine user-defined functions with library functions.
 2000 Prentice Hall, Inc. All rights reserved Introduction Divide and conquer –Construct a program from smaller pieces or components –Each piece.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
CHAPTER 4 FUNCTIONS Dr. Shady Yehia Elmashad. Outline 1.Introduction 2.Program Components in C++ 3.Math Library Functions 4.Functions 5.Function Definitions.
Dale Roberts CSCI N305 Functions Declarations Department of Computer and Information Science, School of Science, IUPUI.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Introduction to Programming
C++ LANGUAGE MULTIPLE CHOICE QUESTION
Introduction to Programming
Dr. Shady Yehia Elmashad
REPETITION CONTROL STRUCTURE
The setw Manipulator The setw manipulator causes the number (or string) that follows it in the stream to be printed within a field n characters wide, where.
Programming Fundamental
Chapter 2.1 Control Structures (Selection)
Control Flow based Testing
Programming Fundamentals
Dr. Shady Yehia Elmashad
Chapter 5 - Functions Outline 5.1 Introduction
11/10/2018.
Chapter 5 - Functions Outline 5.1 Introduction
Dr. Shady Yehia Elmashad
Functions Declarations CSCI 230
Repetition Statements
Introduction to Programming
Introduction to Programming
Chapter 6 - Functions Outline 5.1 Introduction
Conditional Construct
CPS120: Introduction to Computer Science
Functions Divide and Conquer
CS149D Elements of Computer Science
Fundamental Programming
Introduction to Programming
Functions Imran Rashid CTO at ManiWeber Technologies.
Introduction to Programming
Programming Fundamental
Programming Fundamental
Programming Fundamental
Programming Fundamental
Programming Fundamental
Programming Fundamental
Programming Fundamental-1
Programming Fundamental-1
Programming Fundamental
Presentation transcript:

Programming Fundamental Instructor Name: Muhammad Safyan Lecture-11

Lecture outline Unconditional Statement (goto) Function

Unconditional Branch of Execution goto Unconditional Branch of Execution

int i=0; while (i<=10) { goto a; cout<<"GCU"<<endl; i=i+1; } a: cout<<"CSD";

Minimize the use of break Advice Minimize the use of break Minimize the use of continue Never use goto

What have we done till now … Sequential Statements Decisions if , if else , switch Loops while , do while , for

Functions

Guide lines for structured programming Modular Single entry - single exit

Laboratory Stool

Constructing a laboratory Stool

Constructing a laboratory Stool Task: Making a stool Subtask: Make a seat Make legs for the stool Assemble them

What we will study today … What are functions? How are they declared ? How are they defined ? What values are passed to functions ? What values do functions return ?

Function(Objective) Function: A piece of code that perform a specific task Divide the Task into sub-Tasks Divide and conquer approach Better Understanding Information Hiding Reusability

Function Steps involve in functions: Declare a function Define a function Call a function

Declaration of fuction void function-name( ) ; main ( ) { : }

Define a Function void function-name( ) { declarations and statements }

call a Function function-name( );

// Function Declaration void pak(); void india(); main() { cout<<" im in main"<<endl; // Call Function pak(); india(); getch(); } // Function Definition void pak() cout<<" i am in pakistan"<<endl;; void india() cout<<" i am in india";

Function(in Detail) Two types of functions: Functions that do not return a value Functions that return a value

Function return-value-type function-name( argument-list ) { declarations and statements }

Declaration of Function return-value-type function-name( argument--type-list) ; main ( ) { : }

Example int function-name ( int , int , double ) ; void main ( ) { …. }

Definition of Function int function-name ( int i ,int k, double j ) { … }

Return Type of Function Declaration int square ( int ) ; Definition int square ( int i ) { return ( i * i ) ; }

Function Call int x ; x = square ( i ) ;

Example: Function to calculate integer power ( Xn ) double raiseToPow ( double x , int power ) { double result ; int i ; result = 1.0 ; for ( i = 1 ; i <= power ; i ++ ) // braces first result * = x ; // result = result *x } return ( result ) ;

Code to Call the raisetopow Function include < iostream.h > void main ( ) { double x ; int i ; cout << “ Please enter the number “ ; cin >> x ; cout << “ Please enter the integer power that you want this number raised to “ ; cin >> i ; cout << x << “ raise to power “ << i << “is equal to “ << raiseToPow ( x , i ) ; }

Calling function Called function

Area of the Ring Area of Outer Circle = Area of the Ring

Calculating ringArea without using Function main ( ) { : ringArea = ( 3.1415926 * rad1 * rad1 ) – ( 3.1415926 * rad2 * rad2 ) ; }

Example: Function to calculate the area of a circle (with Return Value)

Example: Function to calculate the area of a circle (Without Return a value)