1 / 20

Chapters 22 and Following

Chapters 22 and Following. John Keyser. Remainder of the Course. There are six chapters left, and only two lectures. So, we won’t come close to covering everything I will pull out some of the highlights from remaining chapters Read the listed chapters!!!. Read this section!!!!!!!!!!!!!!!!!

damara
Télécharger la présentation

Chapters 22 and Following

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. Chapters 22 and Following John Keyser

  2. Remainder of the Course • There are six chapters left, and only two lectures. • So, we won’t come close to covering everything • I will pull out some of the highlights from remaining chapters • Read the listed chapters!!!

  3. Read this section!!!!!!!!!!!!!!!!! I promise there will be test questions pulled from this section… Section 22.1

  4. Programming Ideals • This discusses some of the overarching ideas of programming. • Thing we want: • Correctness • Maintainability • Performance • On-time Delivery • Many other features we like in languages, but cant have them all

  5. Good Programming Practices • Represent ideas directly in code • Represent independent ideas independently in code • Represent relationships among ideas directly in code • Combine ideas in code freely where and only where combinations make sense • Express simple ideas simply

  6. Different Programming Styles • Bottom-up vs. Top-Down • Procedural vs. Object-oriented vs. Generic • The best software tends to combine styles as appropriate, rather than sticking rigidly to one style!

  7. This is an introduction to Regular Expressions (regex) Also uses some material from 23.8 The use in C++ is in sections 23.7-23.9 Sections 23.5 – 23.6

  8. Regular Expressions • We often want to be able to read in data that will come in one of several formats. • E.g. phone numbers: • (979)458-0167 • 979-458-0167 • 979.458.0167 • 1.979.458.0167 • 9794580167 • etc.

  9. Regular Expressions • Regular Expressions are a way of defining the pattern that a character string should take. • Support for regex in C++ has been provided by external libraries • It is supposed to be part of the standard library in the latest iteration of C++, but it is not really implemented yet. • The textbook has more about how they can be used in practice (Sections 23.7-23.9)

  10. Regular Expressions • Basically a small language for defining valid character strings • Can be used to process text input that could vary in form • The syntax will vary depending on the language/library used! • The following is just one example.

  11. Representing Characters • Can use a mechanism to specify that you expect an alphabetic character, a digit, whitespace, etc. • \d: decimal digit • \s: whitespace (space, tab) • \w: letter or digit or underscore (_) • \l: lower case letter • \u: upper case letter

  12. Examples • A phone number of the sort (979)458-1067: • (\d\d\d)\d\d\d-\d\d\d\d • An ID with a person’s initials and the last four of the SSN, such as JRS1234: • \u\u\u\d\d\d\d

  13. Repeating • Sometimes an input can repeat, or be optionally included • Express following some other item • {n}: repeat exactly n times • {n,}: repeat n or more times • {n,m}: repeat at least n, no more than m times • *: repeat zero or more times (i.e. {0,} ) • +: repeat one or more times (i.e. {1,} ) • ?: include or not (i.e. {0,1} )

  14. Examples • Phone number: (979)458-0167: • (\d{3})\d{3}-\d{4} • Phone number with/without dashes: 979-458-0167 or 9794580167: • \d{3}-?\d{3}-?\d{3} • A person’s first and last name: John Keyser: • \u\l*\w\u\l* • Maybe include middle name? • \u\l*\w(\u\l*\w)?\u\l*

  15. Using Regular Expressions • Regular Expressions (like grammars) define what is valid and invalid input • Using libraries (or languages, like Perl), you can process text data relatively easily. • You will need to assign data from input to variables, but a regex will help you identify format and where to pull data from.

  16. This deals with some basic numerics and calculations. The rest of the chapter discusses a matrix class, random numbers, standard math functions, and a complex number class. Read those if they are interesting to you. Sections 24.2-24.4

  17. Precision and Overflow • Floating-point numbers: • Store a sign, mantissa, and exponent • Mantissa: X.XXXXXX • Value is mantissa raised to exponent • There is usually some roundoff error • The last digit of the mantissa is rounded • As this number is used, that tiny error can grow • Overflow: • All standard number types have only so many bits to store data in • When you try to store more than that, you get “overflow” • Not always easy to detect

  18. Multidimensional Arrays(i.e. Matrix) • Read sections 24.3-24.4! • C-style multidimensional arrays are still very commonly used. • An array of an array of an array • Can be on stack or on heap • They are also more efficient, generally • But, there are lots of problems, also • No copying, no range checking, passing by pointer

  19. C-style arrays • inttestarray[4][3]; • This is a 2D array of ints, 4x3 • Can access like: testarray[0][0], testarray[3][1] • What about testarray[4][0]? • Can allocate on heap: • int** testarray; • testarray = new (int*)[4]; • for(inti=0; i<4; i++) testarray[i] = new int[3];

  20. Using Multidimensional Arrays • Generally better to use something like the matrix class that the book discusses • But, there are cases where you will want to use “C-style” multidimensional arrays • In particular, numerical code often needs to be very efficient • This means using the efficient over the “clean”

More Related