70 likes | 131 Views
Lecture 2. Programming life cycle. computer piano analogy. Piano + player - computer hardware Musical score/notes - software or program Composer - programmer A music box is set with one melody – similar to a microwave's preset computer chip. Algorithm.
E N D
Lecture 2 Programming life cycle
computer piano analogy • Piano + player - computer hardware • Musical score/notes - software or program • Composer - programmer • A music box is set with one melody – similar to a microwave's preset computer chip
Algorithm • An algorithm is a set of steps to accomplish a task • High level language and source code are synonyms. Examples include C, C++, Pascal, Java, COBOL, Fortran, Python … • All these languages have very specific syntax. This allows a compiler program to read them and translate them into machine code. • Machine code-the final executable file that can be run as an application.
HLL, pseudocode, syntax • All High level Languages (HLL) have similar constructs such as a "while" loop, "if then" statements and others. Therefore a programmer often first writes code in Pseudocode. • Pseudocode- code that almost source code but cannot be run through a compiler since it does not have the correct syntax. • Syntax- the exact proper way a HLL must be written in for a compiler program to work.
Compiler • source code machine code • Source code is stored in a simple text file • machine code is stored in an executable file or an application file. Compiler
Sample pseudocode 2Registration system in BC. • First we will keep all information in two tables (on the hard disk but copied to RAM when the program runs: • The first is a students table that has students� addresses, courses taken or registered for and grades. � • The second is a course database that has the course number, hours, number enrolled and enrollment limit. • Enter all courses that will be offered this semester • If a new student comes to register enter name into student database • For each course a student wants to take • i.If the course is not full, in the course table increment the number enrolled and in the student table enter the course number for that student. • ii.If the course is full inform the student that they would need an overtally.
Sample pseudocode 1average entered grades • prepare the following three variables (a spot in memory to store things): • nstudents- number of grades entered so far, sum-sum of grades so far, avg-average of grades • while entered grade from user is still not negative • nstudents = nstudents+1 • read another grade from user • add grade to sum • avg=sum/nstudents • print avg to the screen