Programming Fundamentals. Today’s Lecture Multidimensional Arrays Arrays as Class Member Data Arrays of Objects C-Strings.

Slides:



Advertisements
Similar presentations
EC-111 Algorithms & Computing Lecture #11 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Advertisements

This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Lecture 20 Arrays and Strings
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Chapter 10.
CS31: Introduction to Computer Science I Discussion 1A 5/7/2010 Sungwon Yang
C-Strings A C-string (also called a character string) is a sequence of contiguous characters in memory terminated by the NUL character '\0'. C-strings.
1 Lecture 20:Arrays and Strings Introduction to Computer Science Spring 2006.
Chapter 9: Arrays and Strings
CS 201 String Debzani Deb.
Chapter 9: Arrays and Strings
Chapter 8 Arrays and Strings
String What it is Why it’s useful library routines for handling strings how to input a string from the keyboard.
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
UNFORMATTED INPUT OUTPUT. Topics to be discussed……………….. overloaded operators >> and and
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
In Addition... To the string class from the standard library accessed by #include C++ also has another library of string functions for C strings that can.
CSIS 123A Lecture 6 Strings & Dynamic Memory. Introduction To The string Class Must include –Part of the std library You can declare an instance like.
DCS 5085 C++ Fundamentals Chapter 4. Overview Basics of a typical C++ Environment C++ Stream Input/Output Classic Stream vs. Standard Stream Iostream.
1 Data Structures A Data Structure is an arrangement of data in memory. A Data Structure is an arrangement of data in memory.  The purpose is to map real.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT8: Characters and Strings CS2311 Computer Programming.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
EGR 2261 Unit 9 Strings and C-Strings  Read Malik, pages in Chapter 7, and pages in Chapter 8.  Homework #9 and Lab #9 due next week.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
1 Mr. Muhammad Hanif Lecturer Information Technology MBBS Campus Dadu University of SIndh.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
1 CS161 Introduction to Computer Science Topic #13.
Array, Pointer and Reference ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
I/O and Data Formatting Introduction to Class Concepts INFSY 307 Spring 2003 Lecture 3.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
Introduction to C++ Part II Version 1.3. Topics C++ Functions -- passing by value in C++ -- passing by reference in C++ -- passing by address in C++ C++
1 Character Strings (Cstrings) Reference: CS215 textbook pages
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
1 Arrays and Strings Lecture: Design Problem l Consider a program to calculate class average Why?? ?
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Chapter 15 Strings as Character Arrays
Chapter 7 Continued Arrays & Strings. Strings as Class Members Strings frequently appear as members of classes. The next example, a variation of the objpart.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
5.6 String Processing Part 2. Sprintf(destnvar,…..regularprintf) Write formatted data to string Same as printf except the output is put in variable. A.
Review Pointer Pointer Variables Dynamic Memory Allocation Functions.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
More about strings in C++. String member functions The next three slides present information about functions that are members of the C++ string class.
1 Lecture 8 Pointers and Strings: Part 2 Section 5.4, ,
1 CSC103: Introduction to Computer and Programming Lecture No 28.
Arrays Chapter 12. Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays.
Characters and Strings
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Today’s Lecture  I/O Streams  Console I/O  File I/O  Tools for File I/O  Sequential.
Programming Fundamentals. Today’s Lecture Array Fundamentals Arrays as Class Member Data Arrays of Objects C-Strings The Standard C++ string Class.
Chapter 7 Continued Arrays & Strings. Arrays of Structures Arrays can contain structures as well as simple data types. Let’s look at an example of this,
C Strings Doing strings the old fashioned way. strings vs c-strings C++ strings are an object data type – State : list of characters – Can ask it to perform.
Chapter Expressions and Interactivity 3. The cin Object 3.1.
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني I/O and File management Concept of streams. cin and cout objects. C++stream classes. Unformatted I/O.
EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Fundamentals of Characters and Strings
Arrays Arrays exist in almost every computer language.
C++ Programming Lecture 20 Strings
Introduction to Programming
Presentation transcript:

Programming Fundamentals

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

Multidimensional Arrays

Passing Arrays to Functions

OUTPUT???

Arrays of Structures

Arrays as Class Member Data

Arrays of Objects

C-Strings

C-String Variables 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 ‘\0’, 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

String Constants

Reading Embedded Blanks 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 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

Copying a String the Hard Way

Copying a String the Easy Way

Arrays of Strings

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

Defining and Assigning string Objects

Input/Output with string Objects

Finding string Objects

Questions???