SlideShare a Scribd company logo
BY
OMKAR MAJUKAR
XI-A
ARRAY
 An array is collection of variable of
same datatype that are referenced
by a common name.
 Types of arrays-
1) SINGLE DIMENSIONAL ARRAYS.
2) TWO DIMENSIONAL ARRAYS.
SINGLE
DIMENSIONAL
ARRAYS The simplest form of an array is a
single dimentional array.
 The array is given a name and its
elements are referred to by their
subscripts or indices.
 C++ array’s index numbering
starts with 0.
BASE DATATYPE
 The data type of array elements is
known as the base type of the
array.
type array-name[size];
 The above statement declared
array marks has 50 elements,
marks[0] to marks[49].
 EXAMPLE-
#include<iostream.h>
void main()
{
const int size = 50;
float marks[size];
for(int i=0; i<size; i++)
{
cout<<“Enter marks of students”<<i+1<<“n”;
cin>>marks[i];
}
cout<<n”;
for(i=0; i<size; i++)
cout<<“marks[“<<i<<“]=“<<marks[i]<<“n”;
return 0;
}
 OUTPUT-
Enter marks of student1
89
Enter marks of student2
98
Enter marks of student3
88
Marks[0] = 89
Marks[1] = 98
Marks[2] = 88
MEMORY
REPRESENTATION OF
SINGLE DIMENSIONAL
ARRAYS Single dimension arrays are essentially lists of
same information of the same type and their
elements are stored in contiguous memory
location in their index order.
 For example, an array grade of type char with 8
declared as
char grade[8];
will have element grade[0] at 1st allocated
memory location, grade[1] at the next, and so
forth.
Since grade is a char type array, each
element size of 1 byte(a character size is 1 byte)
and it will be represented in the memory as shown
below-
GRADE
ADDRESS 2000 2001 2002 2003 2004 2005 2006 2007
*An 8 element character array beginning at
location 2000 .
Total bytes = size of base datatype * no. of elements
Grade
[0]
Grade
[1]
Grade
[2]
Grade[
3]
Grade
[4]
Grade
[5]
Grade
[6]
Grade
[7]
ARRAY
TRAVERSAL Traversal- Accessing each element of array.
 Example-
#include<iostream.h>
Void main()
{
float PER[10];
int c;
for(c=0; c<10; c++)
{
cout<<“Enter percentage of student”<<c+1;
cin>>PER[c];
}
cout<<endl<<“Contents of array”<<endl;
for(c=0; c<10; ++c)
{
cout<<“Percentage of student”<<c+1<<“=“<<PER[c]<<endl;
}
}
SEARCHING FOR AN
ELEMENT IN A 1-D
ARRAY Sometimes we need to search an
element in an array.
 This can be only done by comparing the
search-item with each and every
element of the array.
 This process for searching for an
element in an array is called linear
search.
 EXAMPLE-
#include<iostream.h>
void main()
{
const int maxsize = 10;
int ARR[maxsize],srch,ndx,found=0;
cout<<endl<<“Enter array values”<<endl;
for(int c=0; c<maxsize; ++c)
cin>>ARR[c];
cout<<“Enter the value to be searched”;
cin>>srch;
for(c=0; c<maxsize; ++c)
{
if(ARR[c]==srch)
{
found=1;
ndx=c;
break;
}
}
if(found==1)
cout<<“First occurance is at index”<<ndx;
else
Cout<<“Value not found in the array”;
}
CHARACTER
ARRAY-STRINGS
 C++ stores sequence of characters I,e
string into character arrays.
 In character arrays arrays C++ puts a
special character after the last character
within the string to mark the end of string.
 The special character is known as null
character or 0.
For reading spaces within a string
gets() or getline() methods should be used
and for reading one word only cin can be
used.
 EXAMPLE-
#include<iostream.h>
#include<stdio.h>
#include<ctype.h>
void main()
{
char st[50];
int c;
cout<<“Enter a string of characters”;
gets(st);
for(c=0; st[c]!=‘0’; c++)
{
if(c%2==0)
st[c]=toupper(st[c]);
else
st[c]=tolower(st[c]);
}
cout<<“Converted string = “<<st;
}
2 DIMENSIONAL
ARRAYS
 A 2-D array is an array in which each element is
itself an array.
 For instance, an array A[m][n] is an M by N table
with M rows and N columns containing M*N
elements.
No. of elements in 2-D array = No. of rows * No. of
columns
 The simplest form of a multi dimensioned array is 2-
D arrays, is an array having single dimensioned
array as its elements.
 The general form of the 2-D array declaration is
type array-name[rows][columns]
PROCESSING 2-D
ARRAYS
 To read or process a 2-D array, you
need to use nested loops.
 One loop processes the rows and other
the columns.
 If outer loop is for rows and inner loop
is for columns, then for each row index,
all columns are processed and then the
same process is repeated for next row
index.
 EXAMPLE-
#include<iostream.h>
void main()
{
float marks[4][3],sum,avg;
char grade[4];
int i,j;
for(i=0; i<4; i++)
{
sum = avg = 0;
cout<<“Enter 3 scores of student”<<i+1<<“:”;
for(j=0; j<3; j++)
{
cin>>marks[i][j];
sum+=marks[i][j];
}
avg = sum3;
if(avg<45.0)
grade[i] = ‘D’;
else if(avg<60.0)
grade[i] = ‘C’;
else if(avg<75.0)
grade[i] = ‘B’;
else
grade[i] = ‘A’;
}
for(i=0; i<4; i++)
{ cout<<“student”<<i+1<<“tTotal Marks = “;
cout<<marks[i][0] + marks[i][2]
cout<<“tGrade=“<<grade[i]<<“n”;
}
return 0;
}
 OUTPUT-
Enter 3 scores of student 1 : 78 65 46
Enter 3 scores of student 2 : 56 65 66
Enter 3 scores of student 3: 90 89 92
Enter 3 scores of student 4: 45 56 43
Student 1 Total Marks = 189 Grade = B
Student 2 Total Marks = 187 Grade = B
Student 3 Total Marks = 271 Grade = A
Student 4 Total Marks = 144 Grade = C
MEMORY
REPRESENTATION OF
2 DIMENSIONAL
ARRAYS Two dimensional arrays are stored in a row-
column matrix, where the first index
indicates the row and second indicates the
column.
 This means the second index changes
faster than the first index when accessing
the elements in the array in the order in
which they are actually stored in memory.
0 1 2 3 4 5
0
1
2
3
4
*A two dimensional array pay[5][7] in
memory.
 Total bytes=no. of rows*no. of
columns*size of base data type.
Pay[2][3]
Pay[3][1]
MATRICES AS 2-D
ARRAYS
 Matrix is a useful concept of
mathematics.
 A matrix is a set of mn numbers
arranged in the form of a rectangular
array of m rows and n columns.
 Such a matrix is called m*n(m by n)
matrix.
 Matrices can be represented through 2-
D arrays.
 EXAMPLE-
#include<iostream.h>
void main()
{
int A[3][3],B[3][3],r,c; //Read values in matrices
cout<<“Enter first matrix row wisen”;
for(r=0;r<3;r++)
{ for(c=0;c<3;c++)
{ cin>>B[r][c];
}
}
int flag=0; //loop to check equality
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{ if(A[r][c]!=B[r][c])
{ flag=1; break;
}
if(flag==1) break;
}
if(flag!=0)
cout<<“Matrices are unequaln”;
else
cout<<“Matrices are equaln”;
return 0;
}
 OUTPUT-
Enter first matrix row wise
1 2 3
4 5 6
7 8 9
Enter second matrix row wise
1 2 3
4 5 6
7 8 9
Matrices are equal
ARRAY
INITIALIZATION
 C++ provides the facility of array initialization at
the time of declaration.
 The arrays are initialized in the same way as other
variables are.
 The general form of array initialization is
Type array-name[size1]……[size N]={value-list};
 Following code initializes an integer array with 12
elements:
int days of month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
CALLING
FUNCTIONS WITH
ARRAYS When an arrays argument is passed to a
function, C++, in most contexts treats the
name of an array as if it were a pointer i,e.,
memory address of some element.
 That, if age is an int array to hold 10
integers then age stores the address of
age[0], the first element of an array i,e., the
array name age is a pointer to an integer
which is the first element of an array
age[10].
 EXAMPLE-
#include<iostream.h>
void main()
{
float large(float arr[],intn); //Function prototype
char ch;
int i;
float amount[50],big;
for(i=0;i<50;i++)
{
cout<<“nEnter element no”<<i+1<<“n”;
cin>>amount[i];
cout<<“nWant to enter more?(y/n)n”;
cin>>ch;
if(ch!=‘y’)
break;
}
if(i<50)
i++; //In case of incomplete loop
big=large(amount,i); //Call function large() by passing the array and its number of elements
cout<<“nThe largest element of the array is :”<<big<<“n”;
return 0;
}
float large(float arr[],int n)
{
if(arr[j]>max)
max=arr[j];
}
return(max);
}
 EXAMPLE-
Enter element no. 2
5
Want to enter more?(y/n)
y
Enter element no. 3
33
Want to enter more?(y/n)
y
Enter element no. 4
13
Want to enter more?(y/n)
n
The largest element of the array is :33
THANK
YOU
Ad

More Related Content

What's hot (16)

Arrays
ArraysArrays
Arrays
fahadshakeel
 
Arrays in C
Arrays in CArrays in C
Arrays in C
Kamruddin Nur
 
Multi dimensional array
Multi dimensional arrayMulti dimensional array
Multi dimensional array
Rajendran
 
C arrays
C arraysC arrays
C arrays
CGC Technical campus,Mohali
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Array
ArrayArray
Array
Radha Rani
 
Model-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error CheckingModel-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error Checking
Eelco Visser
 
Java arrays
Java    arraysJava    arrays
Java arrays
Mohammed Sikander
 
Array
ArrayArray
Array
Kathmandu University
 
Java cheatsheet
Java cheatsheetJava cheatsheet
Java cheatsheet
Anass SABANI
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
Qno 3 (a)
Qno 3 (a)Qno 3 (a)
Qno 3 (a)
Praveen M Jigajinni
 
Qno 2 (c)
Qno 2 (c)Qno 2 (c)
Qno 2 (c)
Praveen M Jigajinni
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
poonam.rwalia
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
Deyvessh kumar
 

Similar to Structured data type (20)

Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
AnkurRajSingh2
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
Education Front
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
rohassanie
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
kirthika jeyenth
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
3 (3)Arrays and Strings for 11,12,college.pptx
3 (3)Arrays and Strings for 11,12,college.pptx3 (3)Arrays and Strings for 11,12,college.pptx
3 (3)Arrays and Strings for 11,12,college.pptx
navaneethan2714
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
Nooryaseen9
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Kashif Nawab
 
Data Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasdData Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
Array BPK 2
Array BPK 2Array BPK 2
Array BPK 2
Riki Afriansyah
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
AqeelAbbas94
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
Hemantha Kulathilake
 
Array ppt you can learn in very few slides.
Array ppt you can learn in very few slides.Array ppt you can learn in very few slides.
Array ppt you can learn in very few slides.
dwivedyp
 
Array and its operation in C programming
Array and its operation in C programmingArray and its operation in C programming
Array and its operation in C programming
Rhishav Poudyal
 
Topic20Arrays_Part2.ppt
Topic20Arrays_Part2.pptTopic20Arrays_Part2.ppt
Topic20Arrays_Part2.ppt
adityavarte
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
NehaJain919374
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
3 (3)Arrays and Strings for 11,12,college.pptx
3 (3)Arrays and Strings for 11,12,college.pptx3 (3)Arrays and Strings for 11,12,college.pptx
3 (3)Arrays and Strings for 11,12,college.pptx
navaneethan2714
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Data Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasdData Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
AqeelAbbas94
 
Array ppt you can learn in very few slides.
Array ppt you can learn in very few slides.Array ppt you can learn in very few slides.
Array ppt you can learn in very few slides.
dwivedyp
 
Array and its operation in C programming
Array and its operation in C programmingArray and its operation in C programming
Array and its operation in C programming
Rhishav Poudyal
 
Topic20Arrays_Part2.ppt
Topic20Arrays_Part2.pptTopic20Arrays_Part2.ppt
Topic20Arrays_Part2.ppt
adityavarte
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
Ad

Recently uploaded (20)

How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Ad

Structured data type

  • 2. ARRAY  An array is collection of variable of same datatype that are referenced by a common name.  Types of arrays- 1) SINGLE DIMENSIONAL ARRAYS. 2) TWO DIMENSIONAL ARRAYS.
  • 3. SINGLE DIMENSIONAL ARRAYS The simplest form of an array is a single dimentional array.  The array is given a name and its elements are referred to by their subscripts or indices.  C++ array’s index numbering starts with 0.
  • 4. BASE DATATYPE  The data type of array elements is known as the base type of the array. type array-name[size];  The above statement declared array marks has 50 elements, marks[0] to marks[49].
  • 5.  EXAMPLE- #include<iostream.h> void main() { const int size = 50; float marks[size]; for(int i=0; i<size; i++) { cout<<“Enter marks of students”<<i+1<<“n”; cin>>marks[i]; } cout<<n”; for(i=0; i<size; i++) cout<<“marks[“<<i<<“]=“<<marks[i]<<“n”; return 0; }
  • 6.  OUTPUT- Enter marks of student1 89 Enter marks of student2 98 Enter marks of student3 88 Marks[0] = 89 Marks[1] = 98 Marks[2] = 88
  • 7. MEMORY REPRESENTATION OF SINGLE DIMENSIONAL ARRAYS Single dimension arrays are essentially lists of same information of the same type and their elements are stored in contiguous memory location in their index order.  For example, an array grade of type char with 8 declared as char grade[8]; will have element grade[0] at 1st allocated memory location, grade[1] at the next, and so forth.
  • 8. Since grade is a char type array, each element size of 1 byte(a character size is 1 byte) and it will be represented in the memory as shown below- GRADE ADDRESS 2000 2001 2002 2003 2004 2005 2006 2007 *An 8 element character array beginning at location 2000 . Total bytes = size of base datatype * no. of elements Grade [0] Grade [1] Grade [2] Grade[ 3] Grade [4] Grade [5] Grade [6] Grade [7]
  • 9. ARRAY TRAVERSAL Traversal- Accessing each element of array.  Example- #include<iostream.h> Void main() { float PER[10]; int c; for(c=0; c<10; c++) { cout<<“Enter percentage of student”<<c+1; cin>>PER[c]; } cout<<endl<<“Contents of array”<<endl; for(c=0; c<10; ++c) { cout<<“Percentage of student”<<c+1<<“=“<<PER[c]<<endl; } }
  • 10. SEARCHING FOR AN ELEMENT IN A 1-D ARRAY Sometimes we need to search an element in an array.  This can be only done by comparing the search-item with each and every element of the array.  This process for searching for an element in an array is called linear search.
  • 11.  EXAMPLE- #include<iostream.h> void main() { const int maxsize = 10; int ARR[maxsize],srch,ndx,found=0; cout<<endl<<“Enter array values”<<endl; for(int c=0; c<maxsize; ++c) cin>>ARR[c]; cout<<“Enter the value to be searched”; cin>>srch; for(c=0; c<maxsize; ++c) { if(ARR[c]==srch) { found=1; ndx=c; break; } } if(found==1) cout<<“First occurance is at index”<<ndx; else Cout<<“Value not found in the array”; }
  • 12. CHARACTER ARRAY-STRINGS  C++ stores sequence of characters I,e string into character arrays.  In character arrays arrays C++ puts a special character after the last character within the string to mark the end of string.  The special character is known as null character or 0. For reading spaces within a string gets() or getline() methods should be used and for reading one word only cin can be used.
  • 13.  EXAMPLE- #include<iostream.h> #include<stdio.h> #include<ctype.h> void main() { char st[50]; int c; cout<<“Enter a string of characters”; gets(st); for(c=0; st[c]!=‘0’; c++) { if(c%2==0) st[c]=toupper(st[c]); else st[c]=tolower(st[c]); } cout<<“Converted string = “<<st; }
  • 14. 2 DIMENSIONAL ARRAYS  A 2-D array is an array in which each element is itself an array.  For instance, an array A[m][n] is an M by N table with M rows and N columns containing M*N elements. No. of elements in 2-D array = No. of rows * No. of columns  The simplest form of a multi dimensioned array is 2- D arrays, is an array having single dimensioned array as its elements.  The general form of the 2-D array declaration is type array-name[rows][columns]
  • 15. PROCESSING 2-D ARRAYS  To read or process a 2-D array, you need to use nested loops.  One loop processes the rows and other the columns.  If outer loop is for rows and inner loop is for columns, then for each row index, all columns are processed and then the same process is repeated for next row index.
  • 16.  EXAMPLE- #include<iostream.h> void main() { float marks[4][3],sum,avg; char grade[4]; int i,j; for(i=0; i<4; i++) { sum = avg = 0; cout<<“Enter 3 scores of student”<<i+1<<“:”; for(j=0; j<3; j++) { cin>>marks[i][j]; sum+=marks[i][j]; } avg = sum3; if(avg<45.0) grade[i] = ‘D’; else if(avg<60.0) grade[i] = ‘C’; else if(avg<75.0) grade[i] = ‘B’; else grade[i] = ‘A’; } for(i=0; i<4; i++) { cout<<“student”<<i+1<<“tTotal Marks = “; cout<<marks[i][0] + marks[i][2] cout<<“tGrade=“<<grade[i]<<“n”; } return 0; }
  • 17.  OUTPUT- Enter 3 scores of student 1 : 78 65 46 Enter 3 scores of student 2 : 56 65 66 Enter 3 scores of student 3: 90 89 92 Enter 3 scores of student 4: 45 56 43 Student 1 Total Marks = 189 Grade = B Student 2 Total Marks = 187 Grade = B Student 3 Total Marks = 271 Grade = A Student 4 Total Marks = 144 Grade = C
  • 18. MEMORY REPRESENTATION OF 2 DIMENSIONAL ARRAYS Two dimensional arrays are stored in a row- column matrix, where the first index indicates the row and second indicates the column.  This means the second index changes faster than the first index when accessing the elements in the array in the order in which they are actually stored in memory.
  • 19. 0 1 2 3 4 5 0 1 2 3 4 *A two dimensional array pay[5][7] in memory.  Total bytes=no. of rows*no. of columns*size of base data type. Pay[2][3] Pay[3][1]
  • 20. MATRICES AS 2-D ARRAYS  Matrix is a useful concept of mathematics.  A matrix is a set of mn numbers arranged in the form of a rectangular array of m rows and n columns.  Such a matrix is called m*n(m by n) matrix.  Matrices can be represented through 2- D arrays.
  • 21.  EXAMPLE- #include<iostream.h> void main() { int A[3][3],B[3][3],r,c; //Read values in matrices cout<<“Enter first matrix row wisen”; for(r=0;r<3;r++) { for(c=0;c<3;c++) { cin>>B[r][c]; } } int flag=0; //loop to check equality for(r=0;r<3;r++) { for(c=0;c<3;c++) { if(A[r][c]!=B[r][c]) { flag=1; break; } if(flag==1) break; } if(flag!=0) cout<<“Matrices are unequaln”; else cout<<“Matrices are equaln”; return 0; }
  • 22.  OUTPUT- Enter first matrix row wise 1 2 3 4 5 6 7 8 9 Enter second matrix row wise 1 2 3 4 5 6 7 8 9 Matrices are equal
  • 23. ARRAY INITIALIZATION  C++ provides the facility of array initialization at the time of declaration.  The arrays are initialized in the same way as other variables are.  The general form of array initialization is Type array-name[size1]……[size N]={value-list};  Following code initializes an integer array with 12 elements: int days of month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
  • 24. CALLING FUNCTIONS WITH ARRAYS When an arrays argument is passed to a function, C++, in most contexts treats the name of an array as if it were a pointer i,e., memory address of some element.  That, if age is an int array to hold 10 integers then age stores the address of age[0], the first element of an array i,e., the array name age is a pointer to an integer which is the first element of an array age[10].
  • 25.  EXAMPLE- #include<iostream.h> void main() { float large(float arr[],intn); //Function prototype char ch; int i; float amount[50],big; for(i=0;i<50;i++) { cout<<“nEnter element no”<<i+1<<“n”; cin>>amount[i]; cout<<“nWant to enter more?(y/n)n”; cin>>ch; if(ch!=‘y’) break; } if(i<50) i++; //In case of incomplete loop big=large(amount,i); //Call function large() by passing the array and its number of elements cout<<“nThe largest element of the array is :”<<big<<“n”; return 0; } float large(float arr[],int n) { if(arr[j]>max) max=arr[j]; } return(max); }
  • 26.  EXAMPLE- Enter element no. 2 5 Want to enter more?(y/n) y Enter element no. 3 33 Want to enter more?(y/n) y Enter element no. 4 13 Want to enter more?(y/n) n The largest element of the array is :33