SlideShare a Scribd company logo
Data Structures and Abstract Data Types Chapter 2
Chapter Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Chapter Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data Structures, Abstract Data Types, and Implementations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data Structures, Abstract Data Types, and Implementations ,[object Object],[object Object],[object Object],[object Object],[object Object]
C++  Data Types structured array   struct   union  class simple integral  enum char   short  int  long  bool address pointer  reference floating float  double  long double
Structured Data Type  ,[object Object],[object Object],[object Object]
Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Single Dimension Arrays ,[object Object],[object Object],[object Object],[object Object]
Character Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object]
Subscript Operation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Declare variables to  store and total 3 blood pressures   ,[object Object],[object Object],4002 4000 4004 bp2 bp1 bp3 cin >> bp1 >>  bp2 >>  bp3; total =  bp1 +  bp2 +  bp3;
What if you wanted to store and total 1000 blood pressures? ,[object Object],[object Object],bp[0]  bp[1]  bp[2]  . . . .  bp[999] 5000  5002  5004  5006     .  .  .  .
One-Dimensional Array Definition ,[object Object],[object Object],[object Object]
Another Example ,[object Object],[object Object],temps[0]  temps[1]  temps[2]  temps[3]  temps[4] 7000  7004  7008  7012  7016   number of elements in the array indexes or subscripts Base Address
Declaration of an Array ,[object Object],[object Object],[object Object],[object Object],[object Object]
Yet Another Example ,[object Object],[object Object],number of elements in the array name[0]  name[1]  name[2]  name[3]  name[4]  .  .  .  .  .  name[9] 6000  6001  6002  6003  6004  6005  6006  6007  6008  6009 Base Address
Assigning Values to  Individual Array Elements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],temps[0]  temps[1]  temps[2]  temps[3]  temps[4] 7000  7004  7008  7012  7016   99.4  ?  98.6  101.2  50.6
What values are assigned? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],temps[0]  temps[1]  temps[2]  temps[3]  temps[4] 7000  7004  7008  7012  7016   ?  ?  ?  ?  ?
Now what values are printed? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],temps[0]  temps[1]  temps[2]  temps[3]  temps[4] 7000  7004  7008  7012  7016   100.0  100.2  100.4  100.6  100.8
Variable Subscripts ,[object Object],[object Object],[object Object],[object Object],[object Object],temps[0]  temps[1]  temps[2]  temps[3]  temps[4] 7000  7004  7008  7012  7016   100.0  100.2  100.4  100.6  100.8
A Closer Look at the Compiler ,[object Object],[object Object],[object Object],temps[0]  temps[1]  temps[2]  temps[3]  temps[4] 7000   7004  7008  7012  7016  100.0  100.2  100.4  100.6  100.8
Initializing in a Declaration ,[object Object],[object Object],[object Object],[object Object],[object Object],ages[0]  ages[1]  ages[2]  ages[3]  ages[4] 6000  6002  6004  6006  6008 40  13  20  19  36
Passing Arrays as Arguments ,[object Object],[object Object]
In C++,  No Aggregate Array Operations ,[object Object],[object Object]
Using Arrays as  Arguments to Functions  ,[object Object],[object Object],[object Object]
Example with Array Parameters #include <iomanip> #include <iostream> void  Obtain (int[], int);  // Prototypes here   void  FindWarmest ( const  int[],  int , int&); void  FindAverage  ( const  int[],  int , int&); void  Print ( const  int[], int); using  namespace  std; int main ( ) { // Array to hold up to 31 temperatures int  temp[31] int  numDays; int  average; int  hottest; int  m;
Example continued cout  <<  “How many daily temperatures? ”; cin  >>  numDays; Obtain(temp, numDays);  // Call passes value of numDays and address temp cout  <<  numDays  <<  “ temperatures“  << endl; Print (temp, numDays); FindAverage (temp, numDays, average); FindWarmest (temp, numDays, hottest); cout  <<  endl  <<  “Average was:  “ << average  << endl; cout  <<  “Highest was:  “  << hottest  << endl; return 0; }
Memory Allocated for Array int temp[31]; // Array to hold up to 31 temperatures temp[0]  temp[1]  temp[2]  temp[3]  temp[4]  .  .  .  .  .  temp[30] 6000  Base Address 50  65  70  62  68  . . . . . .
void Obtain (  /* out */   int  temp[] ,   /* in */   int  number ) // User enters number temperatures at keyboard // Precondition: //  number is assigned  &&  number > 0 // Postcondition: //  temp[0 . . number -1]  are assigned { int  m; for (m = 0; m < number;  m++) { cout << “Enter a temperature : “; cin >>  temp[m]; } }
void Print ( /* in */  const   int  temp[],   /* in */  int  number ) // Prints number  temperature values to screen // Precondition: //  number is assigned  &&  number > 0 //  temp[0 . . number -1] are assigned // Postcondition: //  temp[0 . . number -1] printed 5 per line  { int  m; cout  <<  “You entered: “; for (m = 0; m < number;  m++) {  if  (m % 5 == 0) cout  <<  endl;   cout  <<  setw(7) << temp[m]; } }
Using Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Figure1:Array Output Function  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
  Figure 2: Array Input Function  #include <cassert>  void read(IntArray theArray, int capacity, int numValues) /*-------------------------------------------------------------------------  Input values into an array of integers from the keyboard. Preconditions: 0 <= numValues < capacity, which is the capacity of theArray. Postcondition: numValues integers entered from the keyboard have been stored in the first NumValues positions of theArray  -------------------------------------------------------------------------/*  { assert (numValues >= 0 && numValues <= capacity);  for (int i = 0; i < numValues; i++)  cin » theArray[i] ;  }
#include <iostream> using namespace std; void main() { int Nums[4]; int Sum=0; cout<<&quot;Enter 4 Numbers :&quot;; for(int i=0;i<4;i++) cin>>Nums[i]; for(int j=0;j<4;j++) Sum+=Nums[j]; cout<<&quot;Sum = &quot;<<Sum<<endl; }
Multidimensional Arrays ,[object Object],. . .
Example on Multidimensional Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Array of Array Declarations ,[object Object],[object Object]
Array of Array Declarations ,[object Object],scoresTable[2] is the whole row numbered 2 scoresTable [1][3]
Memory Allocation in  2-Dimensional Arrays ,[object Object],[object Object],location [0][4] is followed in memory by location [1][0]

More Related Content

What's hot

Chapter 2
Chapter 2Chapter 2
Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2
Ali Aminian
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
ARVIND PANDE
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
Dr. Md. Shohel Sayeed
 
Unit 2
Unit 2Unit 2
Unit 2
TPLatchoumi
 
Computer Programming- Lecture 4
Computer Programming- Lecture 4Computer Programming- Lecture 4
Computer Programming- Lecture 4
Dr. Md. Shohel Sayeed
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
Dr. Md. Shohel Sayeed
 
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
Dr. Md. Shohel Sayeed
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
Dr. Md. Shohel Sayeed
 
Arrays
ArraysArrays
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
Bhuvana Gowtham
 
Python programing
Python programingPython programing
Python programing
hamzagame
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Marian Marinov
 
Computer Programming- Lecture 8
Computer Programming- Lecture 8Computer Programming- Lecture 8
Computer Programming- Lecture 8
Dr. Md. Shohel Sayeed
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
Frankie Jones
 
Computer Programming- Lecture 7
Computer Programming- Lecture 7Computer Programming- Lecture 7
Computer Programming- Lecture 7
Dr. Md. Shohel Sayeed
 
Python
PythonPython
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
 
See through C
See through CSee through C
See through C
Tushar B Kute
 

What's hot (19)

Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
Unit 2
Unit 2Unit 2
Unit 2
 
Computer Programming- Lecture 4
Computer Programming- Lecture 4Computer Programming- Lecture 4
Computer Programming- Lecture 4
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
 
Arrays
ArraysArrays
Arrays
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
 
Python programing
Python programingPython programing
Python programing
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Computer Programming- Lecture 8
Computer Programming- Lecture 8Computer Programming- Lecture 8
Computer Programming- Lecture 8
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
Computer Programming- Lecture 7
Computer Programming- Lecture 7Computer Programming- Lecture 7
Computer Programming- Lecture 7
 
Python
PythonPython
Python
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
See through C
See through CSee through C
See through C
 

Viewers also liked

Dss6 7
Dss6 7Dss6 7
Simulator
SimulatorSimulator
Simulation and modeling
Simulation and modelingSimulation and modeling
Simulation and modeling
Habibur Rahman
 
Ch1
Ch1Ch1
Chapter2
Chapter2Chapter2
Chapter1
Chapter1Chapter1
Input modeling
Input modelingInput modeling
Discrete Structure
Discrete StructureDiscrete Structure
Discrete Structure
Syed Umair
 

Viewers also liked (8)

Dss6 7
Dss6 7Dss6 7
Dss6 7
 
Simulator
SimulatorSimulator
Simulator
 
Simulation and modeling
Simulation and modelingSimulation and modeling
Simulation and modeling
 
Ch1
Ch1Ch1
Ch1
 
Chapter2
Chapter2Chapter2
Chapter2
 
Chapter1
Chapter1Chapter1
Chapter1
 
Input modeling
Input modelingInput modeling
Input modeling
 
Discrete Structure
Discrete StructureDiscrete Structure
Discrete Structure
 

Similar to Lec2

Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
Ibrahim El-Torbany
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
rohassanie
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
Hattori Sidek
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Rakesh Roshan
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
FareedIhsas
 
Data structure array
Data structure  arrayData structure  array
Data structure array
MajidHamidAli
 
Unit 3
Unit 3 Unit 3
Unit 3
GOWSIKRAJAP
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
rajatryadav22
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Kashif Nawab
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
NelyJay
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
worldchannel
 
Pointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptxPointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptx
krishna50blogging
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
GC University Faisalabad
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
Svetlin Nakov
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
martha leon
 
Java part 2
Java part  2Java part  2
Arrays basics
Arrays basicsArrays basics
Arrays basics
sudhirvegad
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
ANUSUYA S
 
Array and Pointers
Array and PointersArray and Pointers
Array and Pointers
Prof Ansari
 

Similar to Lec2 (20)

Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
Unit 3
Unit 3 Unit 3
Unit 3
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
Pointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptxPointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptx
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
Java part 2
Java part  2Java part  2
Java part 2
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 
Array and Pointers
Array and PointersArray and Pointers
Array and Pointers
 

More from Saad Gabr

Ch5
Ch5Ch5
Ch3
Ch3Ch3
Ch2
Ch2Ch2
Ch4
Ch4Ch4
02 20110314-simulation
02 20110314-simulation02 20110314-simulation
02 20110314-simulation
Saad Gabr
 
Lec6 mod linked list
Lec6 mod linked listLec6 mod linked list
Lec6 mod linked list
Saad Gabr
 
Lec5
Lec5Lec5
Lec5
Saad Gabr
 
Lec4
Lec4Lec4
Lec4
Saad Gabr
 
Lec3
Lec3Lec3
Lec3
Saad Gabr
 
Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
Saad Gabr
 
Lec1
Lec1Lec1
Lec1
Saad Gabr
 
Lec8
Lec8Lec8
Lec8
Saad Gabr
 

More from Saad Gabr (12)

Ch5
Ch5Ch5
Ch5
 
Ch3
Ch3Ch3
Ch3
 
Ch2
Ch2Ch2
Ch2
 
Ch4
Ch4Ch4
Ch4
 
02 20110314-simulation
02 20110314-simulation02 20110314-simulation
02 20110314-simulation
 
Lec6 mod linked list
Lec6 mod linked listLec6 mod linked list
Lec6 mod linked list
 
Lec5
Lec5Lec5
Lec5
 
Lec4
Lec4Lec4
Lec4
 
Lec3
Lec3Lec3
Lec3
 
Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
 
Lec1
Lec1Lec1
Lec1
 
Lec8
Lec8Lec8
Lec8
 

Recently uploaded

বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 

Recently uploaded (20)

বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 

Lec2

  • 1. Data Structures and Abstract Data Types Chapter 2
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. C++ Data Types structured array struct union class simple integral enum char short int long bool address pointer reference floating float double long double
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. Example with Array Parameters #include <iomanip> #include <iostream> void Obtain (int[], int); // Prototypes here void FindWarmest ( const int[], int , int&); void FindAverage ( const int[], int , int&); void Print ( const int[], int); using namespace std; int main ( ) { // Array to hold up to 31 temperatures int temp[31] int numDays; int average; int hottest; int m;
  • 28. Example continued cout << “How many daily temperatures? ”; cin >> numDays; Obtain(temp, numDays); // Call passes value of numDays and address temp cout << numDays << “ temperatures“ << endl; Print (temp, numDays); FindAverage (temp, numDays, average); FindWarmest (temp, numDays, hottest); cout << endl << “Average was: “ << average << endl; cout << “Highest was: “ << hottest << endl; return 0; }
  • 29. Memory Allocated for Array int temp[31]; // Array to hold up to 31 temperatures temp[0] temp[1] temp[2] temp[3] temp[4] . . . . . temp[30] 6000 Base Address 50 65 70 62 68 . . . . . .
  • 30. void Obtain ( /* out */ int temp[] , /* in */ int number ) // User enters number temperatures at keyboard // Precondition: // number is assigned && number > 0 // Postcondition: // temp[0 . . number -1] are assigned { int m; for (m = 0; m < number; m++) { cout << “Enter a temperature : “; cin >> temp[m]; } }
  • 31. void Print ( /* in */ const int temp[], /* in */ int number ) // Prints number temperature values to screen // Precondition: // number is assigned && number > 0 // temp[0 . . number -1] are assigned // Postcondition: // temp[0 . . number -1] printed 5 per line { int m; cout << “You entered: “; for (m = 0; m < number; m++) { if (m % 5 == 0) cout << endl; cout << setw(7) << temp[m]; } }
  • 32.
  • 33.
  • 34. Figure 2: Array Input Function #include <cassert> void read(IntArray theArray, int capacity, int numValues) /*------------------------------------------------------------------------- Input values into an array of integers from the keyboard. Preconditions: 0 <= numValues < capacity, which is the capacity of theArray. Postcondition: numValues integers entered from the keyboard have been stored in the first NumValues positions of theArray -------------------------------------------------------------------------/* { assert (numValues >= 0 && numValues <= capacity); for (int i = 0; i < numValues; i++) cin » theArray[i] ; }
  • 35. #include <iostream> using namespace std; void main() { int Nums[4]; int Sum=0; cout<<&quot;Enter 4 Numbers :&quot;; for(int i=0;i<4;i++) cin>>Nums[i]; for(int j=0;j<4;j++) Sum+=Nums[j]; cout<<&quot;Sum = &quot;<<Sum<<endl; }
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.