DOC PREVIEW
MIT 16 01 - Introduction to Computers and Programming

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 2 In reply to Mud applications? unified? Reading: B: 156-171; FK: 34-61 Sept 8 2003 • Palindrome example • The von Neumann model • Why is Ada good for mission critical • What kind of tests? • How will Ada integrate into rest of • How to make CP more challenging?CP homework vs XXX? problems in CP knowledge and would like to skip introductory Ada homework exercises and get something more challenging to do! Today program 1. I want to do the regular homework 2. I feel confident in my programming • Components of the “hello world” • Step-by-step compilation exercise • Creating the listing file using AdaGIDE • Programming style • The Feldman Spider Adventureeditor hello.adb gnatcc hello.o hello.ali gnatbl hello.exe hello system libs Creating program in editor Compile program (F2) Bind / link (F3) Run program (F4) errors hello.lsb (Alt + F2) hello.adb [p. 33] WITH Ada.Text_IO; PROCEDURE Hello IS --| Last Modified: June 1998 BEGIN Ada.Text_IO.Put(Item => "Hello there. "); Ada.Text_IO.Put(Item => "We hope you enjoy studying Ada!"); Ada.Text_IO.New_Line; END Hello; --------------------------------------------------------------| A very simple program; it just displays a greeting. --| Author: Michael Feldman, The George Washington University -------------------------------------------------------------- HelloGNAT 3.14p (20010503) Copyright 1992-2001 Free Software Foundation, .. Compiling: c:\docume~1\kristina\mydocu~1\underv~1\unifie~1\adakod\hello.adb (source file time stamp: 1998-09-13 21:04:32) 1. WITH Ada.Text_IO; 2. PROCEDURE Hello IS 3. 4. 5. 6. --| Last Modified: June 1998 7. 8. BEGIN 9. 10. "Hello there. "); 11. "We hope you enjoy studying Ada!"); 12. Ada.Text_IO.New_Line; 13. 14. END Hello; 15. 15 lines: No errors Common Programming Errors - bugs -hello.lsb – Listing files --------------------------------------------------------------| A very simple program; it just displays a greeting. ------------------------------------------------------------– Hello Ada.Text_IO.Put(Item => Ada.Text_IO.Put(Item => --| Author: Michael Feldman, The George Washington University • Compilation errors • Run-time errors • Logic or algorithmic errorsCompilation Errors • – be fixed before code can be compiled • – use of values, variables, packages, … • Correct the first one or two errors in program, then recompile Run-time Errors exception in Ada occurrence of exceptions and prevent the computer from halting Syntax errors Fatal error that has to Semantic errors Inconsistency in the Propagation errors • Called • Detected during execution of a program • In Ada we have a way of predicting the – Exception handlingLogic / Algorithm Errors solving a problem algorithm The computer does only what you tell it to do, not what you meant to tell it to do … (GIGO) Comments, headers, and programming style Communication efficient, easy to develop and debug • Developing an incorrect algorithm for • Incorrect translation of a correct • Good programming style: • Good style leads to programs that are: – Understandable, readable, reusable,Comments, headers, and programming style • compiler • -- phase 1 complete 9/8/03 ------------------------------------Adventures of the Spider “introduction to algorithms” Spider (control structures and parameters) Comments start with “--” and are ignored by the ------------------------------------- program name: my_first_program -- programmer: Jane B -- usage: -- compile: -- system: -- date: started 9/5/03 -- bugs: -- description: • Simple picture-drawing creature – The – Algorithmic constructs – Ada packagesStraight-Line Algorithms parameters – TYPE Directions IS (North, East, South, West); – TYPE Colors IS (Red, Green, Blue, Black, None); • – PROCEDURE Face (WhichWay: IN Directions); – PROCEDURE Algorithm with single loop • – – loop FOR Side IN 1..4 LOOP … ; Enumeration types: provides lists of values WhichWay has been assigned a value ChangeColor (NewColor: Colors); NewColor has been assigned a value Algorithm for drawing a box: Repeat steps 1 and 2 four times A repetition usually called a END LOOP • Program 2.3 – The Spider walks a line • Program 2.5 – Spider commands with -- Pre: -- Post: Spider turns to face the given direction. • Spider.Face(WhichWay => Spider.West); -- Pre: -- Post: Spider leaves its tracks in the new color • Spider.ChangeColor(NewColor => Spider.Red); 1. Take three steps forward 2. Turn rightAlgorithm with nested loop • – 1.Choose a color 2.Repeat step 2.1 three times 3.Turn right – FOR Side IN 1..4 LOOP Spider.ChangeColor(Spider.RandomColor); FOR Count IN 1..5 LOOP Spider.Step; ; Spider.TurnRight; ; Run-time error WITH Spider; PROCEDURE Spider_Crash IS BEGIN Spider.Start; FOR Count IN 1..12 LOOP Spider.Step; ; Spider.Quit; END Spider_Crash; Algorithm for drawing a box: Repeat steps 1 through 3 four times END LOOP END LOOP Spider.ChangeColor(NewColor => Spider.Red); END LOOP 2.1 Take one step forward -- Spider_CrashConditional execution FUNCTION AtWall RETURN Boolean; None -- next to a wall IF Spider.AtWall THEN EXIT; ; Concept Question END IF -- Pre: -- Post: Return True if the spider is standing 1. The Code will have no errors. 2. The Code will have compilation errors. 3. The Code will have logical


View Full Document

MIT 16 01 - Introduction to Computers and Programming

Documents in this Course
Fluids

Fluids

3 pages

Fluids

Fluids

4 pages

Fluids

Fluids

4 pages

Fluids

Fluids

5 pages

Load more
Download Introduction to Computers and Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Computers and Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Computers and Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?