0% found this document useful (0 votes)
11 views47 pages

Sig Day 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views47 pages

Sig Day 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

SIG

Day - 3
Functions
Function is a block of code which runs when it is
called.
Instead of writing the same code multiple times ,one
can define a function and call it whenever needed.
Syntax
Types
With Arguments:With Return Statement
With Arguments:Without Return
Statement
Without Arguments:With Return
Statement
Without Arguments:Without Return
Statement
Library Functions/Built in Functions

Other:getch(),scanf(),printf()
Calling a function multiple times
Calling a function multiple times
Problem Statements
1)Check whether the given number is
even or odd.Number will be provided
by user.
2)Write a function that takes two
integers as parameters and returns
their multiplication.
Strings

A string in cpp is an ordered sequence of characters

>John
>1234444
>Jo26
Defining String:Method 1
Defining String:Method 2
string name=”John Doe”

string num=” 1234”


Indexing
Char name[]=”John Doe”;
name[0]=J
name[1]=o
name[2]=h
name[3]=n
name[4]=whitespace
name[5]=D
name[6]=o
name[7]=e
Calling Character using index
Slicing

Syntax: string.substr(starting_position, length);


Concatenation
Functions
1)length()/size():
string str = "Hello";
cout << str.length(); // Output: 5

2)find(substring):
string str = "Hello World";
cout << str.find("World"); // Output: 6
Functions
3)append():
string str = "Hello";
str.append(" World");
cout << str; // Output: Hello World
4)insert(position, string):
string str = "Hello";
str.insert(5, " World");
cout << str; // Output: Hello World
Functions
5)compare():
string str1 = "abc";
string str2 = "def";
cout << str1.compare(str2); // Output: -1
6)empty():
string str = "";
cout << str.empty(); // Output: 1 (true)
Problem Statements
1)Take a string as user input and calculate its length

2) Write a program that extracts a substring from a


given string based on a starting position and length
provided by the user.
MEMORY
MEMORY
MEMORY
MEMORY
To store a char
To store an integer
To store a long
Data Types
C++ Arrays
In C++, an array is a data structure that is used to store
multiple values of similar data types in a contiguous
memory location.
Properties of Arrays in C++
An Array is a collection of data of the same data
type, stored at a contiguous memory location.
Indexing of an array starts from 0. It means the first
element is stored at the 0th index, the second at
1st, and so on.
Elements of an array can be accessed using their
indices.
Properties of Arrays in C++
Once an array is declared its size remains constant
throughout the program.
An array can have multiple dimensions.
The size of the array in bytes can be determined by
the sizeof operator using which we can also find the
number of elements in the array.
We can find the size of the type of elements stored
in an array by subtracting adjacent addresses.
Array Declaration in C++
Initialize Array after
Declaration
MEMORY
Problem Statements
1. Take an array of scores from the user and find the
percentile corresponding to each of the score.
Thank
You !

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy