In C++, functions are used to organize code into modular blocks that can perform specific tasks. Functions allow you to avoid code repetition, improve code readability, and make your program more manageable.
This document discusses different types of functions in C++, including user-defined functions, library functions, function parameters, return values, function prototypes, and function overloading. It provides examples to illustrate key concepts like defining functions with different parameters and return types, passing arguments to functions, and returning values from functions. Storage classes like local, global, static local and register variables are also briefly covered. The document is an introduction to functions in C++ programming.
The document discusses different types of storage classes in C++ that determine the lifetime and scope of variables:
1. Local variables are defined inside functions and have scope limited to that function. They are destroyed when the function exits.
2. Global variables are defined outside all functions and have scope in the entire program. They are destroyed when the program ends.
3. Static local variables are local variables that retain their value between function calls. Register variables are local variables stored in processor registers for faster access.
4. Thread local storage allows defining variables that are local to each thread and retain their values similar to static variables. The document provides examples to illustrate local, global, and static variables.
Functions, classes, and objects are fundamental concepts in object-oriented programming. Here's a brief explanation of each:
Functions:
Functions are blocks of code that perform specific tasks or computations.
They encapsulate a set of instructions and can take parameters (input) and return values (output).
Functions are reusable, promoting code modularity and maintainability.
Classes:
Classes are blueprints or templates for creating objects.
They define the structure and behavior of objects by specifying attributes (data members) and methods (functions) that the objects will have.
Classes serve as a model for creating multiple instances (objects) with similar characteristics.
Objects:
Objects are instances of classes.
They are concrete representations of the class's blueprint, with their own unique data values and the ability to perform actions using the methods defined in the class.
Objects are used to model and manipulate real-world entities in code.
In summary, functions are used to define specific tasks or operations, classes serve as templates for creating objects with shared attributes and behaviors, and objects are instances of classes that represent real-world entities and can interact with their environment. These concepts are central to object-oriented programming and software development.
Functions allow programmers to organize and reuse code. There are two types of functions: library functions provided by C++ and user-defined functions created by the programmer. Functions communicate by passing arguments and returning values. Key concepts for functions include declaration, definition, call, pass by value, pass by reference, and pointers. Virtual functions allow for runtime polymorphism by calling the correct overridden function based on the object's type.
Check out these exercises: http://de.slideshare.net/nicolayludwig/3-cpp-procedural-programmingexercises
- Procedural Programming
- Predefined and User defined Functions
- Declaration and Definition of Functions
- Procedural and recursive Function Calling
- Namespaces and separated Function Definitions
- A Glimpse of Separated Compilation and Translation Units
The document discusses functions in C++. It defines a function as a self-contained program that performs a specific task. Functions help break large programs into smaller, modular pieces. The key parts of a function include the prototype, definition, arguments, return statement, and calling a function. Functions make programs easier to understand, maintain and debug.
The document provides information on functions in C++. It defines a function as a self-contained block of code that performs a specific task. The key points made include:
1. Functions have a name, return type, arguments, and body of code. They may be library functions or user-defined.
2. Functions are declared with a prototype and defined with a body. They are called by passing arguments.
3. Functions return a value using the return statement. Default return type is int.
4. Functions can have default arguments, be inline to reduce overhead, or be overloaded based on parameters. Recursion and passing objects are also discussed.
Functions allow programmers to organize code into reusable blocks. A function is defined with a return type, name, parameters, and body. Functions can be called to execute their code from other parts of a program. Parameters allow data to be passed into functions, and functions can return data through return values or by reference. Inline functions avoid function call overhead by copying the function code into the calling location. Default parameters simplify function calls by automatically passing default values if arguments are omitted.
The document discusses functions in C++. It begins by outlining key topics about functions that will be covered, such as function definitions, standard library functions, and function calls. It then provides details on defining and calling functions, including specifying return types, parameters, function prototypes, scope rules, and passing arguments by value or reference. The document also discusses local and global variables, function errors, and the differences between calling functions by value or reference.
The document discusses functions in C++, including defining functions, parameter passing, inline functions, and default arguments. It covers:
- Defining functions with return types, function names, parameters, and bodies
- Passing parameters by value and by reference
- Using the inline keyword to avoid function call overhead for small functions
- Specifying default values for parameters so functions can be called without passing all arguments
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
C++ functions allow programmers to organize code into reusable blocks to perform specific tasks. There are two types of functions: standard library functions that are predefined in C++, and user-defined functions that are created by programmers. User-defined functions in C++ are declared with a return type, function name, and parameters. Functions can return values using the return statement. Function prototypes allow functions to be defined after they are called. Functions improve code readability and reusability.
Functions in C++, this presentation will cover the following topics
• Functions
• Functions Basics
• Overloaded functions
o Different numbers of arguments
o Different kinds of arguments
Revision Fucntion overloading
• Inline functions
• Default arguments
The document provides an overview of functions in C++. It discusses declaring functions with prototypes specifying the return type and parameters. It also covers defining functions by providing the body enclosed in curly braces. Functions are called by specifying the name and passing arguments for any parameters. Parameters can be passed by value, where a copy is made, or by reference, where changes to the parameter also affect the argument. The document uses examples to demonstrate declaring, defining, calling, and passing arguments to functions. It also discusses default parameter values and recursion.
power point presentation on object oriented programming functions conceptsbhargavi804095
The document discusses C++ functions. It covers the following key points in 3 sentences:
Standard functions that are included with C++ like math functions are discussed as well as how to define user-defined functions. User-defined functions are defined with a function header, parameters, and body. Functions can share data through parameters, either by value or by reference, and variables can have local or global scope.
This document discusses functions and modular programming in C++. It defines what a function is and explains that functions allow dividing code into separate and reusable tasks. It covers function declarations, definitions, parameters, return types, and calling functions. It also discusses different ways of passing arguments to functions: call by value, call by pointer, and call by reference. Finally, it provides an example program that calculates addition and subtraction using different functions called within the main function. Modular programming is also summarized as dividing a program into independent and reusable modules to reduce complexity, decrease duplication, improve collaboration and testing.
Functions allow programmers to organize code into reusable blocks. A function is defined with a return type, name, parameters, and body. Functions can return values and accept arguments. Arguments are passed by value by default, meaning changes inside the function don't affect the original arguments. Functions are called by name and passing any required arguments. Functions improve code organization and reuse.
This document discusses functions in C++. It covers:
- The definition of a function as a subprogram that can act on data and return a value.
- Functions come in two varieties: user-defined and built-in.
- Functions must be declared before use with a prototype specifying the return type and parameters.
- A function is defined by providing the body of code that performs the task.
- Functions can interact through calls where parameters are passed by value or by reference.
Chapter 6 - Modular Programming- in C++.pptxChereLemma2
Here is a function that meets the requirements:
int getProduct(int num1, double num2) {
return num1 * num2;
}
This function:
- Is named getProduct
- Has two parameters: num1 which is an int, and num2 which is a double
- Returns the product of num1 and num2 by multiplying them together and returning the result
- Complies with the data types and operation specified in the requirements
Pointers in C++ object oriented programmingAhmad177077
Pointers in C++ are variables that store the memory address of another variable. They are powerful tools that allow you to directly access and manipulate memory, making them essential in systems programming, dynamic memory allocation, and data structures.
Array In C++ programming object oriented programmingAhmad177077
In C++, an array is a collection of elements of the same data type stored in contiguous memory locations. Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value
More Related Content
Similar to 6. Functions in C ++ programming object oriented programming (20)
The document discusses functions in C++. It defines a function as a self-contained program that performs a specific task. Functions help break large programs into smaller, modular pieces. The key parts of a function include the prototype, definition, arguments, return statement, and calling a function. Functions make programs easier to understand, maintain and debug.
The document provides information on functions in C++. It defines a function as a self-contained block of code that performs a specific task. The key points made include:
1. Functions have a name, return type, arguments, and body of code. They may be library functions or user-defined.
2. Functions are declared with a prototype and defined with a body. They are called by passing arguments.
3. Functions return a value using the return statement. Default return type is int.
4. Functions can have default arguments, be inline to reduce overhead, or be overloaded based on parameters. Recursion and passing objects are also discussed.
Functions allow programmers to organize code into reusable blocks. A function is defined with a return type, name, parameters, and body. Functions can be called to execute their code from other parts of a program. Parameters allow data to be passed into functions, and functions can return data through return values or by reference. Inline functions avoid function call overhead by copying the function code into the calling location. Default parameters simplify function calls by automatically passing default values if arguments are omitted.
The document discusses functions in C++. It begins by outlining key topics about functions that will be covered, such as function definitions, standard library functions, and function calls. It then provides details on defining and calling functions, including specifying return types, parameters, function prototypes, scope rules, and passing arguments by value or reference. The document also discusses local and global variables, function errors, and the differences between calling functions by value or reference.
The document discusses functions in C++, including defining functions, parameter passing, inline functions, and default arguments. It covers:
- Defining functions with return types, function names, parameters, and bodies
- Passing parameters by value and by reference
- Using the inline keyword to avoid function call overhead for small functions
- Specifying default values for parameters so functions can be called without passing all arguments
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
C++ functions allow programmers to organize code into reusable blocks to perform specific tasks. There are two types of functions: standard library functions that are predefined in C++, and user-defined functions that are created by programmers. User-defined functions in C++ are declared with a return type, function name, and parameters. Functions can return values using the return statement. Function prototypes allow functions to be defined after they are called. Functions improve code readability and reusability.
Functions in C++, this presentation will cover the following topics
• Functions
• Functions Basics
• Overloaded functions
o Different numbers of arguments
o Different kinds of arguments
Revision Fucntion overloading
• Inline functions
• Default arguments
The document provides an overview of functions in C++. It discusses declaring functions with prototypes specifying the return type and parameters. It also covers defining functions by providing the body enclosed in curly braces. Functions are called by specifying the name and passing arguments for any parameters. Parameters can be passed by value, where a copy is made, or by reference, where changes to the parameter also affect the argument. The document uses examples to demonstrate declaring, defining, calling, and passing arguments to functions. It also discusses default parameter values and recursion.
power point presentation on object oriented programming functions conceptsbhargavi804095
The document discusses C++ functions. It covers the following key points in 3 sentences:
Standard functions that are included with C++ like math functions are discussed as well as how to define user-defined functions. User-defined functions are defined with a function header, parameters, and body. Functions can share data through parameters, either by value or by reference, and variables can have local or global scope.
This document discusses functions and modular programming in C++. It defines what a function is and explains that functions allow dividing code into separate and reusable tasks. It covers function declarations, definitions, parameters, return types, and calling functions. It also discusses different ways of passing arguments to functions: call by value, call by pointer, and call by reference. Finally, it provides an example program that calculates addition and subtraction using different functions called within the main function. Modular programming is also summarized as dividing a program into independent and reusable modules to reduce complexity, decrease duplication, improve collaboration and testing.
Functions allow programmers to organize code into reusable blocks. A function is defined with a return type, name, parameters, and body. Functions can return values and accept arguments. Arguments are passed by value by default, meaning changes inside the function don't affect the original arguments. Functions are called by name and passing any required arguments. Functions improve code organization and reuse.
This document discusses functions in C++. It covers:
- The definition of a function as a subprogram that can act on data and return a value.
- Functions come in two varieties: user-defined and built-in.
- Functions must be declared before use with a prototype specifying the return type and parameters.
- A function is defined by providing the body of code that performs the task.
- Functions can interact through calls where parameters are passed by value or by reference.
Chapter 6 - Modular Programming- in C++.pptxChereLemma2
Here is a function that meets the requirements:
int getProduct(int num1, double num2) {
return num1 * num2;
}
This function:
- Is named getProduct
- Has two parameters: num1 which is an int, and num2 which is a double
- Returns the product of num1 and num2 by multiplying them together and returning the result
- Complies with the data types and operation specified in the requirements
Pointers in C++ object oriented programmingAhmad177077
Pointers in C++ are variables that store the memory address of another variable. They are powerful tools that allow you to directly access and manipulate memory, making them essential in systems programming, dynamic memory allocation, and data structures.
Array In C++ programming object oriented programmingAhmad177077
In C++, an array is a collection of elements of the same data type stored in contiguous memory locations. Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value
Operators in c++ programming types of variablesAhmad177077
In C++, a variable is a named storage location in memory that can hold a value. Variables allow programmers to store, modify, and retrieve data during program execution. Each variable has a data type that defines the kind of data it can hold, such as integers, floating-point numbers, characters, etc.
2. Variables and Data Types in C++ proramming.pptxAhmad177077
In C++, a variable is a named storage location in memory that can hold a value. Variables allow programmers to store, modify, and retrieve data during program execution. Each variable has a data type that defines the kind of data it can hold, such as integers, floating-point numbers, characters, etc.
Introduction to c++ programming languageAhmad177077
C++ is a powerful, high-performance, general-purpose programming language that supports procedural, object-oriented, and generic programming paradigms. It is widely used for developing applications where efficiency and performance are critical, such as operating systems, game development, and real-time systems.
Selection Sort is a simple comparison-based sorting algorithm. It works by repeatedly finding the smallest (or largest, depending on the sorting order) element from the unsorted portion of the list and swapping it with the first element of the unsorted portion.
Strassen's Matrix Multiplication divide and conquere algorithmAhmad177077
The Strassen Matrix Multiplication Algorithm is a divide-and-conquer algorithm for matrix multiplication that is faster than the standard algorithm for large matrices. It was developed by Volker Strassen in 1969 and reduces the number of multiplications required to multiply two matrices.
Recursive Algorithms with their types and implementationAhmad177077
A recursive algorithm is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem. The algorithm repeatedly breaks the problem into smaller sub-problems until it reaches a base case, which is the simplest instance that can be solved directly without further recursion.
Graph Theory in Theoretical computer scienceAhmad177077
1. Introduction to Graph Theory
What is Graph Theory? History and importance.
Definition of a graph:
Vertices (nodes) and edges (links)
Graphs as a mathematical representation of relationships
Applications of graph theory:
Social networks
Computer networks
Pathfinding (e.g., Google Maps)
Data structures (e.g., trees)
2. Types of Graphs
Undirected vs. directed graphs
Weighted vs. unweighted graphs
Simple graphs, multigraphs, and pseudographs
Special types of graphs:
Complete graph (
𝐾
𝑛
K
n
)
Bipartite graph
Cyclic and acyclic graphs
Trees and forests
Planar graphs
3. Graph Representations
Adjacency matrix
Adjacency list
Incidence matrix
Edge list
Comparison of representations (memory and efficiency)
4. Basic Graph Properties
Degree of a vertex (in-degree, out-degree)
Path and cycle
Simple path, closed path, Hamiltonian path, and Eulerian path
Connectedness:
Connected and disconnected graphs
Strongly and weakly connected components in directed graphs
Subgraphs and spanning subgraphs
Propositional Logics in Theoretical computer scienceAhmad177077
1. Introduction to Propositional Logic
Definition of propositional logic
Propositions: what they are and examples
Importance of propositional logic in computer science (e.g., algorithms, programming, and AI)
Applications in real-world problems (e.g., decision-making, automated reasoning)
2. Syntax and Semantics
Syntax of propositional logic:
Propositional variables
Logical connectives: AND (∧), OR (∨), NOT (¬), IMPLICATION (→), BICONDITIONAL (↔)
Truth values and truth tables
Well-formed formulas (WFFs)
Examples of valid and invalid formulas
3. Logical Equivalences
Concept of logical equivalence
Common equivalences:
Identity laws
Domination laws
Double negation law
De Morgan’s laws
Distributive laws
Absorption laws
Contrapositive and its importance
Simplifying logical expressions using equivalences
4. Truth Tables and Tautologies
Constructing truth tables
Identifying tautologies, contradictions, and contingencies
Examples of tautologies (e.g.,
𝑃
∨
¬
𝑃
P∨¬P) and their significance
5. Logical Implication and Inference
Understanding logical implication
Rules of inference:
Modus Ponens and Modus Tollens
Hypothetical Syllogism
Disjunctive Syllogism
Addition, Simplification, and Conjunction
Resolution method
Using inference rules in proofs
1. Introduction to C++ and brief historyAhmad177077
C++ is a powerful, high-level programming language that was developed by Bjarne Stroustrup in 1983. It's an extension of the C programming language with added features such as object-oriented programming (OOP) and generic programming capabilities.
Here are some key concepts and features of C++:
Object-Oriented Programming (OOP): C++ supports OOP principles such as classes, objects, inheritance, polymorphism, and encapsulation. This allows for the creation of modular and reusable code.
Syntax: C++ syntax is similar to C, but with additional features. It uses semicolons to end statements and curly braces to define blocks of code. It also supports a wide range of operators for arithmetic, logical, and bitwise operations.
Standard Template Library (STL): C++ provides a rich set of libraries known as the Standard Template Library (STL), which includes containers (like vectors, lists, maps), algorithms (such as sorting and searching), and iterators.
Memory Management: Unlike some higher-level languages, C++ gives programmers control over memory management. It allows manual memory allocation and deallocation using new and delete operators. However, this also introduces the risk of memory leaks and segmentation faults if not used carefully.
Portability: C++ code can be compiled to run on various platforms, making it a portable language. However, platform-specific code may need adjustments for different environments.
Performance: C++ is known for its high performance and efficiency. It allows low-level manipulation of resources, making it suitable for system-level programming, game development, and other performance-critical applications.
Community and Resources: C++ has a vast community of developers and extensive documentation available online. There are many tutorials, forums, and books to help programmers learn and master the language.
When learning C++, it's essential to understand the fundamentals thoroughly, including data types, control structures (like loops and conditionals), functions, and pointers. As you become more proficient, you can explore advanced topics like templates, exception handling, multithreading, and more.
Overall, C++ is a versatile language with a wide range of applications, from system programming to game development to web applications. Mastering it can open up many opportunities for software development.Community and Resources: C++ has a vast community of developers and extensive documentation available online. There are many tutorials, forums, and books to help programmers learn and master the language.
When learning C++, it's essential to understand the fundamentals thoroughly, including data types, control structures (like loops and conditionals), functions, and pointers. As you become more proficient, you can explore advanced topics like templates, exception handling, multithreading, and more.
Overall, C++ is a versatile language with a wide range of applications, from system programming to game development to web
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationChristine Shepherd
AI agents are reshaping logistics and supply chain operations by enabling automation, predictive insights, and real-time decision-making across key functions such as demand forecasting, inventory management, procurement, transportation, and warehouse operations. Powered by technologies like machine learning, NLP, computer vision, and robotic process automation, these agents deliver significant benefits including cost reduction, improved efficiency, greater visibility, and enhanced adaptability to market changes. While practical use cases show measurable gains in areas like dynamic routing and real-time inventory tracking, successful implementation requires careful integration with existing systems, quality data, and strategic scaling. Despite challenges such as data integration and change management, AI agents offer a strong competitive edge, with widespread industry adoption expected by 2025.
PyData - Graph Theory for Multi-Agent Integrationbarqawicloud
Graph theory is a well-known concept for algorithms and can be used to orchestrate the building of multi-model pipelines. By translating tasks and dependencies into a Directed Acyclic Graph, we can orchestrate diverse AI models, including NLP, vision, and recommendation capabilities. This tutorial provides a step-by-step approach to designing graph-based AI model pipelines, focusing on clinical use cases from the field.
➡ 🌍📱👉COPY & PASTE LINK👉👉👉 ➤ ➤➤ https://drfiles.net/
Wondershare Filmora Crack is a user-friendly video editing software designed for both beginners and experienced users.
Your startup on AWS - How to architect and maintain a Lean and Mean accountangelo60207
Prevent infrastructure costs from becoming a significant line item on your startup’s budget! Serial entrepreneur and software architect Angelo Mandato will share his experience with AWS Activate (startup credits from AWS) and knowledge on how to architect a lean and mean AWS account ideal for budget minded and bootstrapped startups. In this session you will learn how to manage a production ready AWS account capable of scaling as your startup grows for less than $100/month before credits. We will discuss AWS Budgets, Cost Explorer, architect priorities, and the importance of having flexible, optimized Infrastructure as Code. We will wrap everything up discussing opportunities where to save with AWS services such as S3, EC2, Load Balancers, Lambda Functions, RDS, and many others.
Kubernetes Security Act Now Before It’s Too LateMichael Furman
In today's cloud-native landscape, Kubernetes has become the de facto standard for orchestrating containerized applications, but its inherent complexity introduces unique security challenges. Are you one YAML away from disaster?
This presentation, "Kubernetes Security: Act Now Before It’s Too Late," is your essential guide to understanding and mitigating the critical security risks within your Kubernetes environments. This presentation dives deep into the OWASP Kubernetes Top Ten, providing actionable insights to harden your clusters.
We will cover:
The fundamental architecture of Kubernetes and why its security is paramount.
In-depth strategies for protecting your Kubernetes Control Plane, including kube-apiserver and etcd.
Crucial best practices for securing your workloads and nodes, covering topics like privileged containers, root filesystem security, and the essential role of Pod Security Admission.
Don't wait for a breach. Learn how to identify, prevent, and respond to Kubernetes security threats effectively.
It's time to act now before it's too late!
Mastering AI Workflows with FME - Peak of Data & AI 2025Safe Software
Harness the full potential of AI with FME: From creating high-quality training data to optimizing models and utilizing results, FME supports every step of your AI workflow. Seamlessly integrate a wide range of models, including those for data enhancement, forecasting, image and object recognition, and large language models. Customize AI models to meet your exact needs with FME’s powerful tools for training, optimization, and seamless integration
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Impelsys Inc.
Web accessibility is a fundamental principle that strives to make the internet inclusive for all. According to the World Health Organization, over a billion people worldwide live with some form of disability. These individuals face significant challenges when navigating the digital landscape, making the quest for accessible web content more critical than ever.
Enter Artificial Intelligence (AI), a technological marvel with the potential to reshape the way we approach web accessibility. AI offers innovative solutions that can automate processes, enhance user experiences, and ultimately revolutionize web accessibility. In this blog post, we’ll explore how AI is making waves in the world of web accessibility.
Artificial Intelligence in the Nonprofit Boardroom.pdfOnBoard
OnBoard recently partnered with Microsoft Tech for Social Impact on the AI in the Nonprofit Boardroom Survey, an initiative designed to uncover the current and future role of artificial intelligence in nonprofit governance.
Developing Schemas with FME and Excel - Peak of Data & AI 2025Safe Software
When working with other team members who may not know the Esri GIS platform or may not be database professionals; discussing schema development or changes can be difficult. I have been using Excel to help illustrate and discuss schema design/changes during meetings and it has proven a useful tool to help illustrate how a schema will be built. With just a few extra columns, that Excel file can be sent to FME to create new feature classes/tables. This presentation will go thru the steps needed to accomplish this task and provide some lessons learned and tips/tricks that I use to speed the process.
Domino IQ – What to Expect, First Steps and Use Casespanagenda
Webinar Recording: https://www.panagenda.com/webinars/domino-iq-what-to-expect-first-steps-and-use-cases/
HCL Domino iQ Server – From Ideas Portal to implemented Feature. Discover what it is, what it isn’t, and explore the opportunities and challenges it presents.
Key Takeaways
- What are Large Language Models (LLMs) and how do they relate to Domino iQ
- Essential prerequisites for deploying Domino iQ Server
- Step-by-step instructions on setting up your Domino iQ Server
- Share and discuss thoughts and ideas to maximize the potential of Domino iQ
Bridging the divide: A conversation on tariffs today in the book industry - T...BookNet Canada
A collaboration-focused conversation on the recently imposed US and Canadian tariffs where speakers shared insights into the current legislative landscape, ongoing advocacy efforts, and recommended next steps. This event was presented in partnership with the Book Industry Study Group.
Link to accompanying resource: https://bnctechforum.ca/sessions/bridging-the-divide-a-conversation-on-tariffs-today-in-the-book-industry/
Presented by BookNet Canada and the Book Industry Study Group on May 29, 2025 with support from the Department of Canadian Heritage.
Floods in Valencia: Two FME-Powered Stories of Data ResilienceSafe Software
In October 2024, the Spanish region of Valencia faced severe flooding that underscored the critical need for accessible and actionable data. This presentation will explore two innovative use cases where FME facilitated data integration and availability during the crisis. The first case demonstrates how FME was used to process and convert satellite imagery and other geospatial data into formats tailored for rapid analysis by emergency teams. The second case delves into making human mobility data—collected from mobile phone signals—accessible as source-destination matrices, offering key insights into population movements during and after the flooding. These stories highlight how FME's powerful capabilities can bridge the gap between raw data and decision-making, fostering resilience and preparedness in the face of natural disasters. Attendees will gain practical insights into how FME can support crisis management and urban planning in a changing climate.
6. Functions in C ++ programming object oriented programming
1. 1
Functions in C++
Ahmad Baryal
Saba Institute of Higher Education
Computer Science Faculty
Oct 21, 2024
2. 2 Table of contents
What is function?
Why do we need functions?
Function structure
Function declaration
Types of functions
Function calling
Function call methods
Recursion
Inline Functions
Function overloading
3. 3 Function C++
A function is a set of statements that takes input, does some specific
computation, and produces output. The idea is to put some commonly or
repeatedly done tasks together to make a function so that instead of writing the
same code again and again for different inputs, we can call this function.
They also enable code reusability by allowing you to call a function multiple times
within your program.
4. 4 Why Do we Need Functions?
• Functions help us in reducing code redundancy. If functionality is performed
at multiple places in software, then rather than writing the same code,
again and again, we create a function and call it everywhere. This also
helps in maintenance as we have to make changes in only one place if
we make changes to the functionality in future.
• Functions make code modular. Consider a big file having many lines of
code. It becomes really simple to read and use the code, if the code is
divided into functions.
• Functions provide abstraction. For example, we can use library functions
without worrying about their internal work.
5. 5 Function structure in c++
Let's break down the components of a C++ function:
return_type: This is the data type of the value that the function will return after it has
executed its task. If the function doesn't return a value, you can use void as the return
type.
function_name: This is the name you choose for your function, following the naming rules
of C++.
parameters: These are optional input values that the function can accept. Parameters
are enclosed in parentheses and separated by commas. They allow you to pass
information into the function for processing.
Function body: This is the actual code that performs the specific task of the function.
return (optional): If the return_type is not void, you can use the return statement to send a
6. 6 Function Return Type in C++
The return type is the type of value returned by the function. A function in C++ may or may
not return a value. If the function does not return a value then its return type is void. Value
is returned from a function using the return statement. Control is transferred back to the
caller when the return statement is executed. If the function returns a value then we need
to specify its data type, like int, char, or float.
Note: Only one value can be returned from a function in C++. It is mandatory to return a
value for functions with a non-void return type.
For example, consider a function calculateFactorial which calculates the factorial of a
number and returns an integer value. We can see its return type is int.
int calculateFactorial( int num)
{
int fact=1;
for(int i=1;i<=num;i++)
fact*=i;
return fact; }
7. 7 Types of Functions
1. User Defined Function are user/customer-defined blocks of code specially
customized to reduce the complexity of big programs. They are also commonly
known as “tailor-made functions” which are built only to satisfy the condition in
which the user is facing issues meanwhile reducing the complexity of the whole
program.
2. Library functions are also called “built-in Functions“. These functions are part of a
compiler package that is already defined and consists of a special function with
special and different meanings. Built-in Function gives us an edge as we can directly
use them without defining them whereas in the user-defined function we have to
declare and define a function before using them.
For Example: sqrt(), sort(),pow(),reverse(),abs(), etc.
8. 8 Calling a Function
In C++, you can call a function by specifying the function's name, followed by
parentheses containing any necessary arguments (if the function takes parameters).
Here's the basic syntax for calling a function in C++:
// Function declaration
int add(int a, int b);
int main() {
int result = add(5, 3); // Calling the add function
cout << "Result: " << result << endl;
return 0;
}
// Function definition
int add(int a, int b) {
return a + b;
}
9. 9 There are two most popular ways to pass parameters:
1. Pass by Value: In this parameter passing method, values of actual parameters are
copied to the function’s formal parameters. The actual and formal parameters are
stored in different memory locations so any changes made in the functions are not
reflected in the actual parameters of the caller.
void incrementByValue(int x) {
x++; // Increment the value of x
cout << "Inside incrementByValue: x = " << x << endl;
}
int main() {
int num = 5;
cout << "Original value of num: " << num << endl;
incrementByValue(num);
cout << "After incrementByValue: num = " << num << endl;
return 0;
}
10. 10 There are two most popular ways to pass parameters:
1. Pass by Reference: Both actual and formal parameters refer to the same locations, so
any changes made inside the function are reflected in the actual parameters of the
caller.
void incrementByReference(int &x) {
x++; // Increment the value referred to by x
cout << "Inside incrementByReference: x = " << x << endl;
}
int main() {
int num = 5;
cout << "Original value of num: " << num << endl;
incrementByReference(num);
cout << "After incrementByReference: num = " << num << endl;
return 0;
}
11. 11
Difference between call by value and call by reference in C++
Call by value
A copy of the value is passed to
the function
Changes made inside the
function are not reflected on
other functions
Actual and formal arguments will
be created at different memory
location
Call by reference
An address of value is passed to
the function
Changes made inside the
function are reflected outside the
function as well
Actual and formal arguments will
be created at same memory
location.
12. 12 Recursion in function
Recursion is a programming concept where a function calls itself directly or indirectly to
solve a problem.
#include <iostream>
using namespace std;
// Recursive factorial function
int factorial(int n) {
// Base case: factorial of 0 is 1
if (n == 0 || n == 1) {
return 1;
} else {
// Recursive case: n! = n * (n-1)!
return n * factorial(n - 1);
}
}
int main() {
// Example usage of the factorial function
int num = 5;
cout << "Factorial of " << num << " is: " << factorial(num) << endl;
return 0;
}
13. 13 Inline functions
Inline functions in C++ are expanded by the compiler directly at the point of the
function call, eliminating the overhead of a regular function call.
Marked with the inline keyword.
Pros:
• Performance improvement by reducing function call overhead.
• Compiler optimization opportunities.
• Reduced time and space overhead on the call stack.
Cons:
• Potential code bloat due to duplicated code at call sites.
• Compiler might choose not to inline based on its optimization criteria.
• Can reduce code maintainability for complex functions.
14. 14 Inline functions Example
#include <iostream>
using namespace std;
// Definition of an inline function
inline int square(int x) {
return x * x;
}
int main() {
int num = 5;
// Inline function call
int result = square(num);
cout << "Square of " << num << " is: " << result << endl;
return 0; }
15. 15 Function overloading
• Function overloading is a feature in C++ that allows multiple functions in the same scope with
the same name but different parameter lists.
• It provides a way to create functions that perform similar tasks but with variations in the type or
number of parameters.
Overloading Based on the Number and Type of Parameters:
• Overloaded functions must differ in either the number or type of their parameters.
• The compiler determines which function to call based on the number and types of arguments
passed during the function call.
16. 16 Example 1: Overloading Based on Number of Parameters:
#include <iostream>
using namespace std;
// Function to add two integers
int add(int a, int b) {
return a + b;
}
// Overloaded function to add three integers
int add(int a, int b, int c) {
return a + b + c;
}
int main() {
cout << "Sum of 2 and 3: " << add(2, 3) << endl;
cout << "Sum of 2, 3, and 4: " << add(2, 3, 4) << endl;
return 0;
}
17. 17 Example 2: Overloading Based on Type of Parameters:
#include <iostream>
using namespace std;
// Function to add two integers
int add(int a, int b) {
return a + b;
}
// Overloaded function to concatenate two strings
string add(const string& str1, const string& str2) {
return str1 + str2;
}
int main() {
cout << "Sum of 2 and 3: " << add(2, 3) << endl;
cout << "Concatenation of 'Hello' and ' World': " << add("Hello", " World") <<
endl;
return 0;
}
18. 18 Functions Using Pointers
The function fun() expects a pointer ptr to an integer (or an address of an
integer). It modifies the value at the address ptr. The dereference operator * is
used to access the value at an address. In the statement ‘*ptr = 30’, the value
at address ptr is changed to 30. The address operator & is used to get the
address of a variable of any data type. In the function call statement ‘fun(&x)’,
the address of x is passed so that x can be modified using its address.
// C++ Program to demonstrate working of
// function using pointers
#include <iostream>
using namespace std;
void fun(int* ptr) { *ptr = 30; }
int main()
{
int x = 20;
fun(&x);
cout << "x = " << x;
return 0;