1 / 15

COP 3530 Data Structures & Algorithms

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 ayaz@cise.ufl.edu TA Office: E309 This week no office hours.

gen
Download Presentation

COP 3530 Data Structures & Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP 3530Data Structures & Algorithms Discussion Session 3

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

  3. About me • EyupSerdarAyaz • ayaz@cise.ufl.edu • TA Office: E309 • This week no office hours

  4. Input and output streams in C++ • Stream classes • Stream objects • Insertion (<<) and extraction (>>) operators

  5. Floating point precision • default precision • scientific precision • fixed precision

  6. 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

  7. File manipulation example

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

  9. 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

  10. A vector example

  11. 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 <cstring> • Cannot be assigned directly other than declaration • Frequently used functions: • strcpy • strcmp • strcat • strlen

  12. cstring example

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

  14. C++ String example(Comparison)

  15. References • http://www.cprogramming.com/tutorial/lesson9.html • http://www.fredosaurus.com/notes-cpp/io/readtextfile.html • http://www.cplusplus.com/reference/iostream/ • http://www.cplusplus.com/reference/iostream/manipulators/setprecision/ • http://www.cplusplus.com/reference/stl/list/sort/

More Related