Http://ioerc.mk Functions in C ++ Subject: Programming Languages ​​for III year Topic: functions, member class.

Slides:



Advertisements
Similar presentations
Functions. COMP104 Functions / Slide 2 Introduction to Functions * A complex problem is often easier to solve by dividing it into several smaller parts,
Advertisements

Return values.
BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
1 Programming in C++ Lecture Notes 9 Functions (Returning Values) Andreas Savva.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 5 Functions.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 5. Functions.
Function (L16) * Mathematical Library Functions * Program Components in C++ * Motivations for Functionalizing a Program * Function Prototype * Function.
Functions. COMP104 Lecture 13 / Slide 2 Review of Array: Bubble Sort for (j=0; j List[j+1]) swap(List[j], List[j+1]); }
1 Lecture 14:User-Definded function I Introduction to Computer Science Spring 2006.
Topic 2A – Library Functions and Casting. CISC 105 – Topic 2A Functions A function is a piece of code which performs a specific task. When a function.
Programming is instructing a computer to perform a task for you with the help of a programming language.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
Expressions and Interactivity Chapter 3. 2 The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Often.
Programming in C++ Lecture Notes 6 Void Functions (Procedures) Andreas Savva.
Lecture 9m: Top-Down Design with Functions COS120 Software Development Using C++ AUBG, COS dept.
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) MATH Functions in C Language.
CSE202: Lecture 4The Ohio State University1 Mathematical Functions.
Chapter 3 Expressions and Interactivity Department of Computer Science Missouri State Univeristy.
Functions Why we use functions C library functions Creating our own functions.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan Snd Term Nouf Aljaffan (C) CSC 1201 Course at KSU1.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
USER-DEFINED FUNCTIONS. STANDARD (PREDEFINED) FUNCTIONS  In college algebra a function is defined as a rule or correspondence between values called the.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 3 Formatting Output.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
CHAPTER 5 FUNCTIONS I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Input a number #include using namespace std; int main() { int num; cout num; return 0; }
1 MODULAR DESIGN AND ABSTRACTION. 2 SPECIFYING THE DETAILS OF A PROBLEM INTO A RELATED SET OF SMALLER PROBLEMS.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
CS1201: PROGRAMMING LANGUAGE 2 FUNCTIONS. OVERVIEW What is a Function? Function Prototype Vs Decleration Highlight Some Errors in Function Code Parameters.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
CS1201: Programming Language 2 Function I By: Nouf Aljaffan Edited by : Nouf Almunyif.
Mathematical Manipulation Data types Operator precedence Standard mathematical functions Worked examples.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
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.
Some Useful MATLAB Functions
Dr. Shady Yehia Elmashad
Function Topic 4.
Functions and an Introduction to Recursion
Chapter 3: Expressions and Interactivity.
Arithmetic & other operations
FUNCTIONS EXAMPLES.
Writing Reuseable Formulas
Dr. Shady Yehia Elmashad
Chapter 4: Subprograms Functions for Problem Solving
User-defined Functions
Dr. Shady Yehia Elmashad
CSC1201: Programming Language 2
Using Free Functions Chapter 3 Computing Fundamentals with C++
User-defined Functions
Anatomy of a Function Part 1
Chapter 6: User-Defined Functions I
CS1201: Programming Language 2
Arrays Lecture 11.
Functions and an Introduction to Recursion
Functions Divide and Conquer
CSC1201: Programming Language 2
CSC1201: Programming Language 2
Introduction to Algorithms and Programming
Functions Imran Rashid CTO at ManiWeber Technologies.
CS1201: Programming Language 2
Introduction to Algorithms and Programming COMP151
Introduction to Functions
Functions in C Math Library Functions Functions Function Definitions
Presentation transcript:

http://ioerc.mk Functions in C ++ Subject: Programming Languages ​​for III year Topic: functions, member class

Author: Blagorodna Lazova Subject: Programming Languages for III year Topic: Functions in C ++: Level:High school Language: Macedonian Language Type of material: Exercises-oriented functions in C++ Material Format :Presentation http://ioerc.mk

Abstract: The realization of the function podalgoritmi in programming languages is carried out by sub-function. Function subprograms are called short features. This material covered is a brief explanation of the functions, types of functions and their definition and declaration in C ++. All this can analyze it through appropriate resolved examples of tasks where they used customized and integrated functions.

- Example 2 user function; Contents: Types of functions, declaration of multi-functional prototype; Definition of functions; - Example 1 for customized function - Example 2 user function; Embedded mathematical functions library; -Programme that illustrate the functions sin i cos? Other solved problems, examples of functions

1. Function The tipe of function Function subprograms are called functions and can be: - embedded (functions found in programming libraries) - custom functions Declaration of the functions performed by the order, which takes the following form: Type Name (list of formal arguments) This command is called the function prototype. type-value type that restores function name- function name list of formal arguments Declaration ends with;

2. Definition of functions The general form of function definition in C ++ is:       type name (a list of formal arguments)       {                body function                return feedback value;       } Funkciite declare the beginning of the program to be able to call in the main program. Variables used in the function are called local variables, and those used in the program are called global variables.

Example of user functions: - int Mnozi (int m, int n); -name Mnozi - formal arguments m и n - type rezultat- int float koren(float x) - type rezultat- float int Pomal(int ,int) - list without names arguments int g() - list without names arguments int h(void) - function list without arguments int f(int a,b) - wrong, the right is int f(int a,int b)

Ex 1. Collection of two numbers with function #include<iostream> using namespace int suma (int n, int m) { return n+m; } int main() int a,b; cout<<“Enter a :”; cin>>a; cout<<“Enter b :”; cin>>b; cout<<“The sum of the numbers is“<<suma(a,b); return 0;

Ex.2 Write a function to calculate the largest of three preset numbers : #include<iostreаm> using namespace int maximum (int x, int y, int z); // function prototype int main() { int number1; int number2; int number3; int most; cout<<“Enter three integers:”; cin>> number1 >> number2>> number3; /*number1, number2 and number3 are arguments of a function call to function maximum most =maximum(number1, number2, number3) cout<<“ The Maksimum is :<<most<<endl; return 0; } /*Definition of function maximum, x, y and z are arguments*/ int maximum (int x, int y, int z) int max=x; // We assume that x is max if (y > max ) // If y is greater than max max=y; //then y e max if (z > max ) //If z is greater than od max, max=z; // then z is max return max; // max is most

Functions of the mathematical library in C ++ sqrt (x) - the square root of x exp (a) - exponential function eª log (x) - natural logarithm of x log10 (x) - decade logarithm of x fabs (x) - absolute value of x ceil (x) - x completion of the smallest integer not less than x floor (x) - rounding of x largest integer not greater than x pow (x, y) - x y grade fmod (x, y) - residue of x y as real number sin (x) - sine of x cos (x) - cosine of x tan (x) - tangent of x

Example 1 program to illustrate the functions sin i cos #include<iostream> #include<cmath> // for this purpose include the mathematical library cmath using namespace std; const double Pi=3.14159265; main() { float angle_in_degrees, angle_in_radians;  cout<<“Enter angle in degrees"<<endl;  cin>> angle_in_degrees; angle_in_radians =(angle_in_degrees *Pi)/180; cout<<" Sine of of the input angle is :"<<endl; cout<<"sin("<<agol_vo_stepeni<<")="<<sin(angle_in_radians)<<endl; cout<<" Cosine of the input angle is :"<<endl;  cout<<"cos("<<angle_in_degrees<<")="<<cos(angle_in_radians)<<endl;   return 0; }

Examples tasks for functions: Conversion of Farenhajt to Celsius degree #include <iostream> using namespace std; float Converse(float); float TempFar; //global variable int main() { float TempCel; //local variable cout<<“Enter the temperature in Farenhajt:”; cin>>TampFar; TempCel=Converse (TempFar) cout<<“The temperature in Celsius degree is“; cout<<TempCel<<endl; return 0; } float Converse (float TempFar) float TempC; TempC=( (TempFar-32)*5)/9 return TempC;

Examples tasks for functions : 2. To find the sum of the first to feature even numbers #include<iostream> using namespace std; int collection(int n) { int i, sum=0, number; for(i=0,i<n,i++) { cout<<“Enter number:”; cin>>number; if (number%2==0) sum+=number;} return sum; } int main() { int n; cout<<“Enter n:”; cin>>n; cout<<“The sum is “<< collection(n);

3. Printing a triangle of stars Examples tasks for functions : 3. Printing a triangle of stars #include <iostream> using namespace std; int stars(int n) int i; if(n==0) return 0; else {for (i=1;i<=n;i++) cout<<“*”<<endl; return stars(n-1) }} int main() { int n; cout<<“How many stars must be printed“; cin>>n; stars(n) } return 0; }

Examples tasks for functions : 4. Calculate the factorial of the number added feature rekruzivna #include <iostream> using namespace std; int faktoriel(int n) if(n==1) return n; else return n*faktoriel(n-1) } int main() int n; cout<<“Enter n:”; cin>>n; cout<<“Faktoriel of n is”; fakoriel(n) return 0;