[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] / [CSE201] / 08
[Text Version] [Syllabus] [Schedule] [Glossary] [Labs] [Projects] [Resources] [Grading] [Contact] [Search ]
Notes: [01] [02] [03] [04] [05] [06] [07] <08> [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10]
Tue Apr 16 15:01:00 PDT 2013



      Previous 07 loops

      [ 07.html ]

      Hand in a question you want answered on chapter 3

      Project 3 Due

      Study pages 132-144 Advanced Loops

        Many programs need nested loops, process inputs, or are simulations.

        3.9 Nested Loops

        Two or more dimensions.

        Informal example

         		while(not full)
         			while(some ice cream left)
         				eat a spoonful;
         			get some more ice cream;
         		}//end while not full

        [Activity diagram/flow chart]

        Examples of Nested loops ch03/ [ triangle.cpp ] (pages 132-133).

        Wall Paper: [ wp.cpp ] [ wp.png ]

        3.10 Processing inputs

        Good advice for reading data from the user.

        Advanced topic 3.4 The loop-and-a-half Problem

        Study this now.

        Here is a quick example of loop-and-a-half: [ 08loop.cpp ] Here we want to read until the user inputs a something that is not a number or is a smaller number.

        Productivity Hint 3.2 Redirecting input and output

        Neat trick that works in Linux, MacOs, and MSWindows. Learn it!

        Advanced topic 3.5 End-of-file Detection

        The first loop is a very simple and powerful way to process all the input data. Be ready to use it.

        Advanced topic 3.6 Clearing the Failure State of a stream

        Later. But note -- after you discover cin.fail() is true with an if you must (1) handle the failure (think), and (2) clear the state of cin with cin.clear() before doing anything else with cin.

        Random Fact 3.2 The Denver Airport Luggage Handling System

        Just for fun... try [ watch?v=xx8f4x6C_KY ] (YouTube, 2:28 mins) and then you can go to [ ?page_id=2086 ] which analyses why this system failed.

        3.11 Simulations

        We will simulate somethings in the lab this quarter.

        Here is an improved version of [ buffon.cpp ] from pages 141-143.

        Here [ piman.cpp ] is a simpler attempt at finding π by thowing darts at a square board and counting how many are inside part of a circle.

      Chapter Summary

      Use to Review the last 3 topics.

      Review Questions -- Ask and you will be answered

      Hand in one question that you would like answered about the content of Chapter 3. Or hand in one error/problem/weakness you have spotted on the web site. Include your name and the relevant pages in the chapter.


      Nested loops [ nested.cpp ] [ nested3.cpp ] [ mtable0.cpp ] which outputs a multiplication table.

      Quiz 3 tracing a program with strings

      Lab 5 next week on Loops

      Next 09 -- Functions

      [ 09.html ]


  1. Algorithm::=A precise description of a series of steps to attain a goal, [ Algorithm ] (Wikipedia).
  2. Class::=A description of a type of object that includes the data it knows and the functions it can execute.
  3. Function::programming=A selfcontained and named piece of program that knows how to do something.
  4. Gnu::="Gnu's Not Unix", a long running open source project that supplies a very popular and free C++ compiler.
  5. OOP::="Object-Oriented Programming", Current paradigm for programming.
  6. Semantics::=Rules determining the meaning of correct statements in a language.
  7. SP::="Structured Programming", a previous paradigm for programming.
  8. Syntax::=The rules determining the correctness and structure of statements in a language, grammar.
  9. Q::software="A program I wrote to make software easier to develop",
  10. TBA::="To Be Announced", something I should do.
  11. TBD::="To Be Done", something you have to do.
  12. UML::="Unified Modeling Language", industry standard design and documentation diagrams.
  13. void::C++Keyword="Indicates a function that has no return value".

( End of document ) <<Contents | Top