COP 3530 Data Structures & Algorithms Discussion Session 3.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 A string is an array of characters.  Strings must have a 0 or null character after the last character to show where the string ends.  The null character.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
 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.
Ch 8. Characters and Strings Timothy Budd 2 Characters and Literals Strings Char in C++ is normally an 8-bit quantity, whereas in Java it is a 16-bit.
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
Copyright  Hannu Laine C++-programming Part 5 Strings.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters 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.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12: More on C-Strings and the string Class Starting Out with.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
Chapter 10.
The Standard String Class Is actually a template: –typedef basic_string string This means you can have strings of things other than chars.
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.
Chapter 9: Arrays and Strings
CS Nov 2006 C-strings.
CS 117 Spring 2002 Review for Exam 3 arrays strings files classes.
C-strings Array with base type char One character per indexed variable
Week 7 – String. Outline Passing Array to Function Print the Array How Arrays are passed in a function call Introduction to Strings String Type Character.
Strings. Sentences in English are implemented as strings in the C language. Computations involving strings are very common. E.g. – Is string_1 the same.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
1 Chapter 10 Characters, Strings, and the string class.
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.
One Dimensional Arrays (Part2) Sorting Algorithms Searching Algorithms Character Strings The string Class. 1.
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
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.
C What you Know* Objective: To introduce some of the features of C. This assumes that you are familiar with C++ or java and concentrates on the features.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
Define our own data types We can define a new data type by defining a new class: class Student {...}; Class is a structured data type. Can we define our.
9-1 Learning Objectives  An Array Type for Strings  C-Strings.
TEXT FILES. CIN / COUT REVIEW  We are able to read data from the same line or multiple lines during successive calls.  Remember that the extraction.
Fundamental File Processing Operations C++
 2008 Pearson Education, Inc. All rights reserved Pointers and Pointer-Based Strings.
 2003 Prentice Hall, Inc. All rights reserved.m ECE 2552 Dr. Këpuska based on Dr. S. Kozaitis Summer Chapter 15 - Class string and String Stream.
Characters, Strings, And The string Class Chapter 10.
Representing Strings and String I/O. Introduction A string is a sequence of characters and is treated as a single data item. A string constant, also termed.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
1 Character Strings (Cstrings) Reference: CS215 textbook pages
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 10 Characters, Strings, and the string class.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 1 due Friday, 7pm. RAD due next Friday. Presentations week 6. Today: –More details on functions,
Chapter 15 Strings as Character Arrays
 2003 Prentice Hall, Inc. All rights reserved. 11 Fundamentals of Characters and Strings Character constant –Integer value of a character –Single quotes.
An Array Type For Strings. Two ways to represent strings – i.e. “Hello” cstring An array with base type char Older way of processing strings Null character.
Slides from Shane Griffith (TA and guest instructor in Fall 2008) CprE 185: Intro to Problem Solving.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 9. Streams & Files.
DCT1063 Programming 2 CHAPTER 3 STRINGS Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
Streams and File Processing in C++ Instructor - Andrew S. O’Fallon CptS 122 Washington State University.
In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students.
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
File I/O. Files allow permanent storage of programs and data. ifstream and ofstream objects –For file I/O the inclusion of is required. –Objects for file.
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
COP 3530 Data Structures & Algorithms
Review of Strings which include file needs to be used for string manipulation? what using statement needs to be included fro string manipulation? how is.
Standard Input/Output Streams
Standard Input/Output Streams
Programming with ANSI C ++
when need to keep permanently
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Standard Input/Output Stream
CS150 Introduction to Computer Science 1
STL and Example.
Chapter 12: More on C-Strings and the string Class
Presentation transcript:

COP 3530 Data Structures & Algorithms Discussion Session 3

Outline  Input-output streams in C++  Floating point precision  File manipulation  Pointers in C  Vector class in C++  Strings in C and C++

About me  Eyup Serdar Ayaz   TA Office: E309  This week no office hours

Input and output streams in C++  Stream classes  Stream objects  Insertion ( >) operators

Floating point precision  default precision  scientific precision  fixed precision

File manipulation in C++  Include necessary header: fstream  Declare an file stream: ifstream or ofstream  Open the stream file  Check if the file is opened  Read from or write to the stream  Close the stream

File manipulation example

Pointers in C  Reference operator (&)  Dereference operator (*)  Types of pointers  Arrays as pointers  Pointer arithmetic  Pointers to pointers  Null pointer

Vector class in C++  An STL (Standard Template Library) container  An strict sequence container i.e. An array of variable size. Similar to ArrayList of Java  Defined as a template, type should be specified  Most useful functions:  operator[]  size  insert  erase  begin  end

A vector example

Strings in C  Strings are char arrays  Declared as char arrays or pointers  Ends with ‘\0’ or simply 0  String manipulation functions are defined in  Cannot be assigned directly other than declaration  Frequently used functions:  strcpy  strcmp  strcat  strlen

cstring example

String class in C++  Strings are objects  String manipulation functions are defined in  Can be directly assigned  Can be concatenated using + operator  Frequently used functions:  operator[] or at  size  copy  compare  substr  operator+= or append

C++ String example(Comparison)

References   cpp/io/readtextfile.html cpp/io/readtextfile.html   s/setprecision/ s/setprecision/ 