Lecture 24: 12/3/2002CS149D Fall 20021 CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.

Slides:



Advertisements
Similar presentations
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
Advertisements

LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
Classes and Data Abstraction Lecture 9. Objects Models of things in the real world Defined in classes  Class name is the object name Example: Library.
C Strings. The char Data Type for Storing Characters The char data type can is used to declare a variable that can hold a single character. Examples:
C++ Data Type String A string is a sequence of characters enclosed in double quotes. Examples of strings: “Hello” “CIS 260” “Students” The empty string.
CIS 101: Computer Programming and Problem Solving Lecture10 Usman Roshan Department of Computer Science NJIT.
1 Lecture 19:String Data Type Introduction to Computer Science Spring 2006.
1 Lecture 6: Input/Output (II) Introduction to Computer Science Spring 2006.
Characters. COMP104 Lecture 21 / Slide 2 Data Type: char * Constant declaration const char star = '*'; * Variable declaration char resp; * Variable assignment.
Lecture 18:Topic: I/O Formatting and Files Dale/Weems/Headington
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
String What it is Why it’s useful library routines for handling strings how to input a string from the keyboard.
Chapter 3: Input/Output
Lecture 17: 10/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
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.
1 Chapter 4 Program Input and the Software Design Process.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
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.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
1 Program Input Software Design Chapter 4. 2 You Will Want to Know... Prompting for and reading values into a program. Accessing data from a file. What.
String Class. C-style and C++ string Classes C-style strings, called C-strings, consist of characters stored in an array ( we’ll look at them later) C++
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
More Strings CS303E: Elements of Computers and Programming.
1 Character Strings (Cstrings) Reference: CS215 textbook pages
String Class Mohamed Shehata 1020: Introduction to Programming.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
Chapter 15 Strings as Character Arrays
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
More about strings in C++. String member functions The next three slides present information about functions that are members of the C++ string class.
Program Input and the Software Design Process ROBERT REAVES.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Lecture 17: 4/4/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
1 Input (Read) Statement. Variable Declaration (Definition) Initialization Assignment Displaying variables: using cout statement Reading variables from.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
Strings.
Strings CSCI 112: Programming in C.
What Actions Do We Have Part 1
Section 3.2c Strings and Method Signatures
CS149D Elements of Computer Science
getline() function with companion ignore()
CS149D Elements of Computer Science
Engineering 1020: Introduction to Programming Fall 2018
Input/Output Handouts: Quiz 2, Unit 3 practice sheets.
CS149D Elements of Computer Science
Introduction to C++ Programming
String Manipulation Chapter 7 Attaway MATLAB 4E.
Chapter 3: Input/Output
String What it is Why it’s useful
Introduction to C++ Programming
CS149D Elements of Computer Science
CS148 Introduction to Programming II
CS149D Elements of Computer Science
Additional string operators
CS149D Elements of Computer Science
Using string type variables
character manipulation
Announcements HW1 is due TODAY.
getline() function with companion ignore()
Introduction to Computer Science
Presentation transcript:

Lecture 24: 12/3/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture 24: 12/3/2002

CS149D Fall Outline Character Data

Lecture 24: 12/3/2002CS149D Fall Character Data Character data consists of alphabetic characters, digits, and special characters. Each character corresponds to a a binary code value Recall ASCII (see Appendix A) ‘a’ is 97 in ASCII, “A” is 65 in ASCII Declaration char c = ‘A’; Single Character I/O cout.put(c);//output cin.get(c);//input, read any character even space See ascii_test.cpp

Lecture 24: 12/3/2002CS149D Fall String 1/3 Dealing with variable length character data (instead of a single character) Include  #include  Note we omitted the “.h”. The header files without the “.h” are the new header files in the new C++ standard Declaration string name = “Ayman”; string TITLE = “Mr. “; string astring = TITLE+name;//string concatenation Output cout << TITLE<<name;

Lecture 24: 12/3/2002CS149D Fall Strings 2/3 Input cin >> name; >> operator skips any leading white-space characters such as blanks and newlines, then reads successive characters into the variable stopping at the first trailing white-space character See string_test.cpp String operations name.length()//returns number of characters in string name = “The cat and the dog”;name.find(“the”); The function returns 12 //the first occurrence of a particular substring, if found. If not found, the //function returns the special value string::npos (A very large value)

Lecture 24: 12/3/2002CS149D Fall Strings 3/3 substr function myString.substr(a,b); //returns a new string extracted from myString starting at character a and for a length of b characters myString = “Programming and Problem Solving”; myString.substr(0,7)“Program” myString.substr(7,8)“ming and” myString(10,0)“” myString(24,40)“Solving” myString(40,24)Program terminates with an execution error message See section 6.3 for a listing of character functions