Lecture 23 - Computer programming. After studying this chapter you will be able to understand: Programming in real life, what is problem solving? Algorithm, algorithms to programs, components of algorithms, software development process, top down algorithm design.
Computer Programming Lecture 23 Summary of Previous Lecture In the previous lecture, we have learnt Intellectual Property Copyrights Patents Trade Secrets Types of Intellectual Property Rights Laws Employees and Trade Secrets Key intellectual Property Right Issues Plagiarism Reverse engineering Summary of Previous Lecture Open source code Competitive intelligence Cyber squatting Today’s Lecture Programming in real life Introduction What is Problem Solving? Problem Solving process Algorithm History Working Definition Examples Today’s Lecture Algorithms to Programs Components of Algorithms Variables and values Instructions Sequences Procedures Selections Repetitions Documentation Today’s Lecture Software Development Process Top Down Algorithm Design Summary Where is programming in real life? Short answer: all over the place! Where is programming in real life? Short answer: all over the place! Introduction People think in words: Like “The sky is so beautiful!” The computer understand in ‘binary’ Which just means ones and zeros: 00111000100111 “Programming languages” are different ways of taking your words and turning them into instructions that the computer can understand Introduction Programs are a set of instructions for the computer There are three levels of programming languages Machine level, i.e.; direct hardware commands Middle level i.e.; Assembly language Higher level i.e.; C, Java, C++, LISP etc Selection – At Least One of Several Conditions What if at least one of several conditions needs to be satisfied? if ( I feel hungry or the time is 1.00pm or my friend has his eye on my lunch ) then { Eat my lunch now } Components of an Algorithm Values and Variables Instruction (a.k.a primitives) Sequence (of instructions) Procedure (involving instructions) Selection (between instructions) Repetition (of instructions) Documentation (beside instructions) Repetition Repeat an instruction while (or maybe until) some true or false condition occurs Test the condition each time before repeating the instruction Also known as iteration or loop Example: Algorithm for getting a leave from the class Repetition Example procedure getleave ( teacher, course, time) { reach_to(teacher) Say(“Hello", teacher, “I am feeling fever!") Say(“I want leave in ", course, "at", time, "?") ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say("please!") add to begging count ListenToReply ( ) } } Repetition – Example (cont) procedure getleave ( teacher, course, time) { reach_to(teacher) Say(“Hello", teacher, “I am feeling fever!") Say(“I want leave in ", course, "at", time, "?") ListenToReply ( ) start begging count at zero while ( reply is "No" and begging count < 100 ) { Say("please!") add to begging count ListenToReply ( ) } } Condition is tested before sequence Repetition – Example (cont) procedure getleave ( teacher, course, time) { reach_to(teacher) Say(“Hello", teacher, “I am feeling fever!") Say(“I want leave in ", course, "at", time, "?") ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say(“Please!") add to begging count ListenToReply ( ) } Sequence may not get executed at all } Repetition – Example (cont) Ensure initial procedure getleave ( teacher, course, time) values of variables { reach_to(teacher) used in the Say(“Hello", teacher, “I am feeling fever!") conditions are set Say(“I want leave in ", course, "at", time, "?") correctly ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say(“Please!") add to begging count ListenToReply ( ) } } Repetition – Example (cont) procedure getleave ( teacher, course, time) { reach_to(teacher) Say(“Hello", teacher, “I am feeling fever!") Say(“I want leave in ", course, "at", time, "?") ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say(“Please!") Ensure the variables add to begging count ListenToReply ( ) used in the conditions } } are updated in each iteration Repetition – Example (cont) • What if we don’t increment the begging count? procedure getleave ( teacher, course, time) { reach_to(teacher) Say(“Hello", teacher, “I am feeling fever!") Say(“I want leave in ", course, "at", time, "?") ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say("please!") } } Infinite loop Documentation Records what the algorithm does Describes how it does it Explains the purpose of each component of the algorithm Notes restrictions or expectations Example: Getting a leave (again) Components of an Algorithm Values and Variables Instruction (a.k.a primitives) Sequence (of instructions) Procedure (involving instructions) Selection (between instructions) Repetition (of instructions) Documentation (beside instructions) The Software Development Process We have covered this topic in Lecture “Database systems” Same process is followed to develop a computer program Top-down Algorithm Design Write down what you have to Break that into 3-7 smaller steps Break each step into 3-7 smaller steps Keeping subdividing until each individual step is easy enough to – i.e., until it is a single instruction Example: Learning Top-down Design Example Prepare Learn Study Reinforce Read Make notes Prepare questions Attend lecture Listen and think Complete prac Attend tute Record answers to questions Revise notes Read lecture notes Read textbook Read exercise Design algorithm Code solution Test and document Record insights Summary Programming is the way to instruct the computer what to do? Users set of computer instructions to be executed by the computer Different levels of programming exists Algorithms are developed before making a program to set a procedure Remember “Computers are stupid” means you need to teach them step by step each and every instruction, they can not it by themselves ... How we solve problems? We "just do" Guesswork-and-luck Trial-and-error Experience (possibly someone else's) "Scientifically" The Problem-solving Process "Doctor, my head hurts" Patient has elevated ... decimal numbers, use of zero, method for finding square root Latin translation (c.1120 CE): “Algoritmi de numero Indorum” Book on algebra Hisab al-jabr w’al-muqabala بببببب ببببببب بب بببب... Today’s Lecture Algorithms to Programs Components of Algorithms Variables and values Instructions Sequences Procedures Selections Repetitions Documentation Today’s Lecture Software