160 likes | 273 Views
The Construction of Programs. CSC 145. Programming in the Small vs. Programming in the Large. Working alone vs. group of programmers Need for good design & planning Software Engineering. Program Development Process. Requirements analysis & specs Design Phase
E N D
The Construction of Programs CSC 145
Programming in the Small vs. Programming in the Large • Working alone vs. group of programmers • Need for good design & planning • Software Engineering
Program Development Process • Requirements analysis & specs • Design Phase • Implementation Phase (produce code) • Test & Installation • Operation & Maintenance
Algorithm Development • Use of a natural language – pseudocode • Use of pictures & symbols (flowcharts)
Example: Algorithm to add the integers 1 through 100 in natural language (pseudocode) Set Sum to 0 & counter Ct to 1 Repeat following two steps until Ct is greater than 100 Add Ct to the Sum saving result in Sum Increase Ct by 1 Output Sum of the 100 numbers
Example: same algorithm in Ada Sum := 0; Ct := 1; While Ct <= 100 loop Sum := Sum + Ct; Ct := Ct + 1; End loop; Put (Sum);
Algorithms will usually be expressed using 3 Controls: • Sequence – series of steps executed in sequential order • Selection – one of two or more alternatives are chosen • Iteration – repeating a certain number of times or until a certain condition is met
Sequence • Get number of hours worked • Get hourly rate of pay • Compute Salary by Number of hours X Hourly Rate
Selection If Count is zero then output “Sorry”, otherwise Compute Average by dividing Sum by Count
Iteration Keep adding 1 tbsp.sugar and tasting until sweet enough
Problem Solving using a computer • Specify the problem (make sure you understand it) • Design algorithm to solve problem • Express algorithm as code in programming language • Compile & Run program on the computer
Stages of a Working Program • Source Code is created using text editor. • Compiler translates into object module. • Linker puts object modules together (builds) to create load module. • Operating System puts load module in memory and executes.
When Problems get complicated Divide & Conquer!! Top-Down Design
Top-Down Design (stepwise refinement) See Example Handout…note that as you move from Top to Bottom the steps are being refined into simpler tasks.
Program Structure in Ada With …; Use …; Procedure programname is any declarations (including variables) Begin executable statements End programname;
Example: Simple Ada program With TEXT_IO; Use TEXT_IO; Procedure First is; Begin Put (“This is my first program…whoopee!”); End First;