This document provides information about linear search of arrays in C++. It discusses:
- Linear search involves comparing each element of an array to a key value to find a match. It is useful for small, unsorted arrays but is inefficient as it must examine every element if the key is not present.
- The linearSearch function takes an array, search key, and array size as parameters. It uses a for loop to compare each element to the key and returns the index of the match, or -1 if no match is found.
- Multiple examples are provided to demonstrate calling the linearSearch function and displaying the results of searches that do and do not find the key.
Call by value or call by reference in C++Sachin Yadav
Call by value means passing the value directly to a function. The called function uses the value in a local variable; any changes to it DO NOT affect the source variable. In call by value method, the called function creates its own copies of original values sent to it. Any changes, that are made, occur on the function’s copy of values and are not reflected back to the calling function.
Call by value or call by reference in C++Sachin Yadav
Call by value means passing the value directly to a function. The called function uses the value in a local variable; any changes to it DO NOT affect the source variable. In call by value method, the called function creates its own copies of original values sent to it. Any changes, that are made, occur on the function’s copy of values and are not reflected back to the calling function.
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
This is the last slide of advancedC - Advanced C part 3. In the previous slides we learnt all the fundamentals that is required to learnt Advanced C. In this last slide of Advanced C you will be learning about Multilevel pointers, Command line argument, different kinds of functions, and also you will gain deep knowledge on pre processor and user defined data types. This will help you to improve your knowledge in Advanced C
This presentation covers very frequently used standard library functions also called as inbuilt functions. a brief description about function and its declaration (syntax) is defined for help.
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
This is the last slide of advancedC - Advanced C part 3. In the previous slides we learnt all the fundamentals that is required to learnt Advanced C. In this last slide of Advanced C you will be learning about Multilevel pointers, Command line argument, different kinds of functions, and also you will gain deep knowledge on pre processor and user defined data types. This will help you to improve your knowledge in Advanced C
This presentation covers very frequently used standard library functions also called as inbuilt functions. a brief description about function and its declaration (syntax) is defined for help.
Visual programming (VP) refers to a method of programming that uses a graphical interface to create and modify code, rather than typing out code manually. Unlike traditional text-based programming, visual programming uses visual elements to represent code. Some graphical elements you can use when creating programs with VP include:
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
1. EC-102 Computer System &
Programming
Lecture #9
Instructor: Jahan Zeb
Department of Computer Engineering (DCE)
College of E&ME
2. Searching Arrays: Linear Search
Search array for a key value
Linear search
– Compare each element of array with key value
• Start at one end, go to other
– Useful for small and unsorted arrays
• Inefficient
• If search key not present, examines every element
3. 1 // Fig. 4.19: fig04_19.cpp
2 // Linear search of an array.
3 #include <iostream>
4
5 using std::cout;
6 using std::cin;
7 using std::endl;
8
9 int linearSearch( const int [], int, int ); // prototype
10
11 int main()
12 {
13 const int arraySize = 100; // size of array a
14 int a[ arraySize ]; // create array a
15 int searchKey; // value to locate in a
16
17 for ( int i = 0; i < arraySize; i++ ) // create some data
18 a[ i ] = 2 * i;
19
20 cout << "Enter integer search key: ";
21 cin >> searchKey;
22
23 // attempt to locate searchKey in array a
24 int element = linearSearch( a, searchKey, arraySize );
25
Takes array, search key, and
array size.
4. 26 // display results
27 if ( element != -1 )
28 cout << "Found value in location " << element << endl;
29 else
30 cout << "Value not found" << endl;
31
32 return 0; // indicates successful termination
33
34 } // end main
35
36 // compare key to every element of array until location is
37 // found or until end of array is reached; return subscript of
38 // element if key or -1 if key not found
39 int linearSearch( const int array[], int key, int sizeOfArray )
40 {
41 for ( int j = 0; j < sizeOfArray; j++ )
42
43 if ( array[ j ] == key ) // if found,
44 return j; // return location of key
45
46 return -1; // key not found
47
48 } // end function linearSearch
5. Enter integer search key: 36
Found value in location 18
Enter integer search key: 37
Value not found
6. Multiple-Subscripted Arrays
Multiple subscripts
– a[ i ][ j ]
– Tables with rows and columns
– Specify row, then column
– “Array of arrays”
• a[0] is an array of 4 elements
• a[0][0] is the first element of that array
Row 0
Row 1
Row 2
Column 0 Column 1 Column 2 Column 3
a[ 0 ][ 0 ]
a[ 1 ][ 0 ]
a[ 2 ][ 0 ]
a[ 0 ][ 1 ]
a[ 1 ][ 1 ]
a[ 2 ][ 1 ]
a[ 0 ][ 2 ]
a[ 1 ][ 2 ]
a[ 2 ][ 2 ]
a[ 0 ][ 3 ]
a[ 1 ][ 3 ]
a[ 2 ][ 3 ]
Row subscript
Array name
Column subscript
8. Multiple-Subscripted Arrays
Referenced like normal
cout << b[ 0 ][ 1 ];
– Outputs 0
– Cannot reference using commas
cout << b[ 0, 1 ];
• Syntax error
Function prototypes
– Must specify sizes of subscripts
• First subscript not necessary, as with single-scripted arrays
– void printArray( int [][ 3 ] );
1 0
3 4
9. 1 // Fig. 4.22: fig04_22.cpp
2 // Initializing multidimensional arrays.
3 #include <iostream>
4
5 using std::cout;
6 using std::endl;
7
8 void printArray( int [][ 3 ] );
9
10 int main()
11 {
12 int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } };
13 int array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 };
14 int array3[ 2 ][ 3 ] = { { 1, 2 }, { 4 } };
15
16 cout << "Values in array1 by row are:" << endl;
17 printArray( array1 );
18
19 cout << "Values in array2 by row are:" << endl;
20 printArray( array2 );
21
22 cout << "Values in array3 by row are:" << endl;
23 printArray( array3 );
24
25 return 0; // indicates successful termination
26
27 } // end main
Note the various initialization
styles. The elements in
array2 are assigned to the
first row and then the second.
Note the format of the
prototype.
10. 28
29 // function to output array with two rows and three columns
30 void printArray( int a[][ 3 ] )
31 {
32 for ( int i = 0; i < 2; i++ ) { // for each row
33
34 for ( int j = 0; j < 3; j++ ) // output column values
35 cout << a[ i ][ j ] << ' ';
36
37 cout << endl; // start new line of output
38
39 } // end outer for structure
40
41 } // end function printArray
Values in array1 by row are:
1 2 3
4 5 6
Values in array2 by row are:
1 2 3
4 5 0
Values in array3 by row are:
1 2 0
4 0 0
For loops are often used to
iterate through arrays. Nested
loops are helpful with
multiple-subscripted arrays.
11. Character Arrays
Strings
Arrays of characters
– All strings end with null ('0')
– Examples
• char string1[] = "hello";
– Null character implicitly added
– string1 has 6 elements
• char string1[] = { 'h', 'e', 'l', 'l',
'o', '0’ };
– Subscripting is the same
String1[ 0 ] is 'h'
string1[ 2 ] is 'l'
12. Examples Using Arrays
Input from keyboard
char string2[ 10 ];
cin >> string2;
– Puts user input in string
• Stops at first whitespace character
• Adds null character
Printing strings
– cout << string2 << endl;
• Does not work for other array types
– Characters printed until null found
13. 1 // Fig. 4_12: fig04_12.cpp
2 // Treating character arrays as strings.
3 #include <iostream>
4
5 using std::cout;
6 using std::cin;
7 using std::endl;
8
9 int main()
10 {
11 char string1[ 20 ], // reserves 20 characters
12 char string2[] = "string literal"; // reserves 15 characters
13
14 // read string from user into array string2
15 cout << "Enter the string "hello there": ";
16 cin >> string1; // reads "hello" [space terminates input]
17
18 // output strings
19 cout << "string1 is: " << string1
20 << "nstring2 is: " << string2;
21
22 cout << "nstring1 with spaces between characters is:n";
23
Two different ways to declare
strings. string2 is
initialized, and its size
determined automatically .
Examples of reading strings
from the keyboard and
printing them out.
14. 24 // output characters until null character is reached
25 for ( int i = 0; string1[ i ] != '0'; i++ )
26 cout << string1[ i ] << ' ';
27
28 cin >> string1; // reads "there"
29 cout << "nstring1 is: " << string1 << endl;
30
31 return 0; // indicates successful termination
32
33 } // end main
Enter the string "hello there": hello there
string1 is: hello
string2 is: string literal
string1 with spaces between characters is:
h e l l o
string1 is: there
Can access the characters in a
string using array notation.
The loop ends when the null
character is found.
15. Pointers
Pointers
– Powerful, but difficult to master
– Simulate pass-by-reference
– Close relationship with arrays and strings
16. Pointer Variable Declarations and
Initialization
Pointer variables
– Contain memory addresses as values
– Normally, variable contains specific value (direct reference)
– Pointers contain address of variable that has specific value
(indirect reference)
Indirection
– Referencing value through pointer
Pointer declarations
– * indicates variable is pointer
int *myPtr;
declares pointer to int, pointer of type int *
– Multiple pointers require multiple asterisks
int *myPtr1, *myPtr2;
count
7
countPtr
count
7
17. Pointer Variable Declarations and
Initialization
Can declare pointers to any data type
Pointer initialization
– Initialized to 0, NULL, or address
• 0 or NULL points to nothing
18. Pointer Operators
& (address operator)
– Returns memory address of its operand
– Example
int y = 5;
int *yPtr;
yPtr = &y; // yPtr gets address of y
– yPtr “points to” y
yPtr
y
5
yptr
500000 600000
y
600000 5
address of y
is value of
yptr
19. Pointer Operators
* (indirection/dereferencing operator)
– Returns synonym for object its pointer operand points to
– *yPtr returns y (because yPtr points to y).
*yptr = 9; // assigns 9 to y
* and & are inverses of each other
20. 1 // Fig. 5.4: fig05_04.cpp
2 // Using the & and * operators.
3 #include <iostream>
4
5 using std::cout;
6 using std::endl;
7
8 int main()
9 {
10 int a; // a is an integer
11 int *aPtr; // aPtr is a pointer to an integer
12
13 a = 7;
14 aPtr = &a; // aPtr assigned address of a
15
16 cout << "The address of a is " << &a
17 << "nThe value of aPtr is " << aPtr;
18
19 cout << "nnThe value of a is " << a
20 << "nThe value of *aPtr is " << *aPtr;
21
22 cout << "nnShowing that * and & are inverses of "
23 << "each other.n&*aPtr = " << &*aPtr
24 << "n*&aPtr = " << *&aPtr << endl;
25
* and & are inverses
of each other
21. 26 return 0; // indicates successful termination
27
28 } // end main
The address of a is 0012FED4
The value of aPtr is 0012FED4
The value of a is 7
The value of *aPtr is 7
Showing that * and & are inverses of each other.
&*aPtr = 0012FED4
*&aPtr = 0012FED4
* and & are inverses; same
result when both applied to
aPtr
22. Calling Functions by Reference
3 ways to pass arguments to function
– Pass-by-value
– Pass-by-reference with reference arguments
– Pass-by-reference with pointer arguments
return can return one value from function
Arguments passed to function using reference
arguments
– Modify original values of arguments
– More than one value “returned”
23. Calling Functions by Reference
Pass-by-reference with pointer arguments
– Simulate pass-by-reference
• Use pointers and indirection operator
– Pass address of argument using & operator
– Arrays not passed with & because array name already pointer
– * operator used as alias/nickname for variable inside of
function
24. 1 // Fig. 5.6: fig05_06.cpp
2 // Cube a variable using pass-by-value.
3 #include <iostream>
4
5 using std::cout;
6 using std::endl;
7
8 int cubeByValue( int ); // prototype
9
10 int main()
11 {
12 int number = 5;
13
14 cout << "The original value of number is " << number;
15
16 // pass number by value to cubeByValue
17 number = cubeByValue( number );
18
19 cout << "nThe new value of number is " << number << endl;
20
21 return 0; // indicates successful termination
22
23 } // end main
24
Pass number by value; result
returned by
cubeByValue
25. 25 // calculate and return cube of integer argument
26 int cubeByValue( int n )
27 {
28 return n * n * n; // cube local variable n and return result
29
30 } // end function cubeByValue
The original value of number is 5
The new value of number is 125
cubeByValue receives
parameter passed-by-value
Cubes and returns
local variable n
26. 1 // Fig. 5.7: fig05_07.cpp
2 // Cube a variable using pass-by-reference
3 // with a pointer argument.
4 #include <iostream>
5
6 using std::cout;
7 using std::endl;
8
9 void cubeByReference( int * ); // prototype
10
11 int main()
12 {
13 int number = 5;
14
15 cout << "The original value of number is " << number;
16
17 // pass address of number to cubeByReference
18 cubeByReference( &number );
19
20 cout << "nThe new value of number is " << number << endl;
21
22 return 0; // indicates successful termination
23
24 } // end main
25
Apply address operator & to
pass address of number to
cubeByReference
cubeByReference
modified variable
number
Prototype indicates parameter
is pointer to int
27. 26 // calculate cube of *nPtr; modifies variable number in main
27 void cubeByReference( int *nPtr )
28 {
29 *nPtr = *nPtr * *nPtr * *nPtr; // cube *nPtr
30
31 } // end function cubeByReference
The original value of number is 5
The new value of number is 125
cubeByReference
receives address of int
variable,
i.e., pointer to an int
Modify and access int
variable using indirection
operator *