- Количество слайдов: 30
Day 2 Algorithms, problem solving and Introduction to C++
Day 2 Objectives Algorithms and problem solving A little history About software development Intro to C++ Some hands on with Code. Blocks and ideone.
Algorithms Algorithm A sequence of precise instructions which leads to a solution (historically, the term had a more specialized meaning) l Program An algorithm expressed in a language the l computer can understand
Consider A long list of names… Bill Sally Robert Catherine Lora Bill Jennifer Lora Catherine …. . l How can we determine ho many instances there are of the name “Lora”?
An Algorithm is precise To qualify as an algorithm, a set of instructions must completely and unambiguously specify the steps to be taken and the order in which they are taken. The person or machine carrying out the algorithm does exactly what the algorithm says, neither more nor less.
Computing history The Antikythera mechanism, invented some time around 100 BC in ancient Greece, is the first known mechanical calculator utilizing gears of various sizes and configuration to perform calculations. l
History The Kurdish medieval scientist Al-Jazari built programmable automata in 1206 AD. One system employed in these devices was the use of pegs and cams placed into a wooden drum at specific locations, which would sequentially trigger levers that in turn operated percussion instruments. The output of this device was a small drummer playing various rhythms and drum patterns.
History The Jacquard loom, which Joseph Marie Jacquard developed in 1801, uses a series of pasteboard cards with holes punched in them. The hole pattern represented the pattern that the loom had to follow in weaving cloth. Repeatable automated procedures
History Charles Babbage adopted the use of punched cards around 1830 to control his Analytical Engine. This was an engine for calculating mathematical and astronomical tables
History Some believe that the first computer program was written for the Analytical Engine by mathematician Ada Lovelace to calculate a sequence of Bernoulli numbers.
History – The difference engine l l Charles Babbage also designed the first computer that actually stored a program in memory (rather then a fixed program on cards). He was unable to complete the complex machine, but was built later, and it worked perfectly!
History – Difference Engine The difference engine was built recently with Legos!
Program Design Programming is a creative process No complete set of rules for creating a program – Problem Solving Phase Algorithm Implementation Phase Program Slide 1 - 14
Problem Solving Phase Be certain the task is completely specified What is the input? What information is in the output? How is the output organized? Develop the algorithm before implementation Experience shows this saves time in getting your program to run. Test the algorithm for correctness Slide 1 - 15
Implementation Phase Translate the algorithm into a programming language Easier as you gain experience with the language Compile the source code Locates errors in using the programming language Run the program on sample data Verify correctness of results Results may require modification of the algorithm and program Display 1. 7 Slide 1 - 16
Display 1. 7 Back Next Slide 1 - 17
Object Oriented Programming Abbreviated OOP On Object Memory or State The program for the object Slide 1 - 18
Object Oriented Programming Objects represent “entities” we are modeling. An entity is a actor in a process
Software Life Cycle Goals For System Evaluate Review Planning C ive at re Algorithms Programs Slide 1 - 20
Introduction to C++
Hands on 1 – Code. Blocks IDE Goto: tinyurl. com/Cpp. Kenyon in Chrome. Open the notes for today's class Use the instructions to start Code. Block and create a project Helloworld. Open the Sample code for today's class, copy “Hello world” code, paste in Code. Block main. cpp. Build (compile and link) and run the program.
Hands on – ideone (web based) Go to ideone. com This is a web page that allows quick testing of simple programs At the bottom left corner set to C++ 5. 1 Paste in the hello world code from sample code into main code area. Hit run button What happens?
Hands on Goto: tinyurl. com/Cpp. Kenyon in Chrome. Open the notes for today's class Use the instructions to start Code. Block and create a project Helloworld. Open the Sample code for today's class, copy “Hello world” code, paste in Code. Block main. cpp. Build (compile and link) and run the program.
Hands on – ideone Go to ideone. com This is a web page that allows quick testing of simple programs At the bottom left corner set to C++ 5. 1 Paste in the hello world code from sample code into main code area. Hit run button What happens?
Introduction to C++ Where did C++ come from? Derived from the C language C was derived from the B language B was derived from the BCPL language Why the ‘++’? ++ is an operator in C++ and results in a cute pun Slide 1 - 26
C++ History C developed by Dennis Ritchie at AT&T Bell Labs in the 1970 s. Used to maintain UNIX systems Many commercial applications written in C C++ developed by Bjarne Stroustrup at AT&T Bell Labs in the 1980 s. Overcame several shortcomings of C Incorporated object oriented programming C remains a subset of C++ Slide 1 - 27
A Sample C++ Program Any C++ program contains these lines #include
Display 1. 9 Slide 1 - 29
In class Make program give personnal greeting e. g. “Hello Jim” Make program print your address on multiple lines. Make the system print out your first name as a text banner: # # #### # # # ###### # # ##### # # ## # # ###### # # # ## # # ## #### # #