Programming Fundamentals Todays Lecture l l Multidimensional Arrays

  • Slides: 32
Download presentation
Programming Fundamentals

Programming Fundamentals

Today’s Lecture l l Multidimensional Arrays as Class Member Data Arrays of Objects C-Strings

Today’s Lecture l l Multidimensional Arrays as Class Member Data Arrays of Objects C-Strings

Multidimensional Arrays

Multidimensional Arrays

Passing Arrays to Functions

Passing Arrays to Functions

OUTPUT? ? ?

OUTPUT? ? ?

Arrays of Structures

Arrays of Structures

Arrays as Class Member Data

Arrays as Class Member Data

Arrays of Objects

Arrays of Objects

C-Strings

C-Strings

C-String Variables l l Each character occupies 1 byte of memory. An important aspect

C-String Variables l l Each character occupies 1 byte of memory. An important aspect of C-strings is that they must terminate with a byte containing 0. This is often represented by the character constant ‘’, which is a character with an ASCII value of 0. This terminating zero is called the null character. When the << operator displays the string, it displays characters until it encounters the null character.

Avoiding Buffer Overflow

Avoiding Buffer Overflow

String Constants

String Constants

Reading Embedded Blanks l l It turns out that the extraction operator >> considers

Reading Embedded Blanks l l It turns out that the extraction operator >> considers a space to be a terminating character. Thus it will read strings consisting of a single word, but anything typed after a space is thrown away.

Reading Embedded Blanks l l To read text containing blanks we use another function,

Reading Embedded Blanks l l To read text containing blanks we use another function, cin. get(). This syntax means a member function get() of the stream class of which cin is an object.

Reading Multiple Lines

Reading Multiple Lines

Copying a String the Hard Way

Copying a String the Hard Way

Copying a String the Easy Way

Copying a String the Easy Way

Arrays of Strings

Arrays of Strings

The Standard C++ string Class l l Standard C++ includes a new class called

The Standard C++ string Class l l Standard C++ includes a new class called string. You can concatenate string objects with the + operator:

Defining and Assigning string Objects

Defining and Assigning string Objects

Input/Output with string Objects

Input/Output with string Objects

Finding string Objects

Finding string Objects

Questions? ? ?

Questions? ? ?