Chapter 1 – Overview of Programming and Problem Solving Programming – aka coding – process of designing, writing, testing and debugging source code / computer programs Programming does require expertise in a programming language and algorithm development Computer – machine that receives input, processes input based on programmed instructions and produces output Semester goal:: teach/learn programming Process of developing a program: Development life cycle – process broken into 3 parts: Problem-solving phase Implementation phase Maintenance phase Problem-solving phase consists of Analysis – look closely at the problem to gain an understanding of it – if it is complex, it will require breaking down into smaller pieces Specification – documentation that is produced after the problem is analyzed – it describes how the problem will be solved Developing an Algorithm – this involves creating a detailed, step-by-step solution to the problem or subproblems in a finite amount of time (this is really the hard part!) – expressed in English ex1:: Algorithm for finding the perimeter and area of a rectangle ex2:: Algorithm for finding total tax and amount due of an item given: Homework: selling price of item, 4% sales tax, 10% luxury tax Page 40-41 Verify Correctness of the solution – desk checking the solution – tracing the WU #1, #2 algorithm CSFU #2,3,4,5 ex1:: Tracing algorithm for computing salesperson’s salary (handout) This phase is iterative and should not be skipped! Implementation Phase consists of Writing the program – translating the algorithm into a programming language such as C++ (this gets easier with practice!) ex1:: A sample program to find perimeter and area of a rectangle Programming Language – set of rules, symbols and special words used to construct a program Testing the program – compiling and executing the program to locate errors in using the language and errors in the output – finding errors in the output requires a set of test cases – sample input to the program checking all possible execution paths Maintenance Phase consists of Using the program in the environment is was intended to run in Updating the program as requirements change – modifications may need to be made to correct errors as well Waterfall model of software development – but there are other models Documentation – used to identify the program and explain its use – written in English and embedded in the code – explains complex/tricky code – can also be external to the code – must be easy to read and understand! Debugging – process of identifying and eliminating defects/errors/bugs in a program (Where did this term come from?) Data vs. Information – data are raw facts – eventually must be represented in a form that the computer can use – information is data that has been processed/structured/presented in a form that makes it useful ex1:: Data → 92710 Information → 9/27/10 – date of first exam $92,710 – average starting salary of a database administrator 92710 – zip code for Irvine, CA Programming Languages – definition above, but they have evolved over time: Machine language – instructions and data are represented in binary digits arranged in a form a particular computer understands – eventually all programs must be converted to this form in order to be executed Assemblers – converts assembly language program into machine language assembly language is a programming language in which the machine language instruction was replaced with a mneumonic (easy to remember name) Compilers – convert high-level languages into machine code – program instructions are getting even easier to understand – translation for entire program first, then executed Interpreters – also converts high-level languages into machine code, but translates and executes each line one at a time Preparing a program for execution To start – program entered using a text editor and stored as a file – source program the source program then translated using a compiler and if no syntax errors – object program created, which is the high-level program translated into machine code Then – since most programs use environments that contain precompiled components (ie math functions) that are stored in libraries, a linker (or linking) combines the object program with the precompiled components from the library Finally – at this point, the program can be executed – executing the program causes the final object file to be loaded into memory and appropriate hardware resources are made available to the program Source Program entered with Editor Source File We will practice this in the first inclass lab Source Program translated by Compiler Object File Object Program linked with Libraries Object File ready for Execution Control Structures within a program– tell us which order instructions will be executed or evaluated Sequence – one after the other Selection – depends on the “truth” of a condition Iteration – repeats a series of instructions – aka looping Subprogram – consists of a series of instructions that are always executed together when invoked Instructions are based on what computer can perform: transfer of data, input data from device, output data to device, store data to memory/secondary storage, retrieve data from memory/secondary storage, compare two values, perform arithmetic operations Taking a look inside the computer system – hardware and software together make up the system Hardware – physical components Memory – RAM temporary storage for program and data CPU – processing unit – responsible for program execution Control Unit – fetches instruction from memory then translates into control signals Arithmetic/Logic Unit – executes control signals utilizing appropriate resources Peripheral devices – any device attached to computer Homework: Page 38-39 EPE #1 - #12 Auxiliary storage devices/Secondary storage devices – a more permanent storage area for data and instructions Input devices – accepts data to be processed Output devices – presents data that has been processed How many peripheral devices can you name? Software – programs – usually where most $ spent! System Software – aka operating system – programs that manage the computer’s resources – name some? – usually comes with a basic editor Programming Languages – already discussed above – can you name some? Application Software – programs written to solve a particular problem – can you name some? Most software designed with a particular user interface in mind – users may have a windows environment or they may have to enter commands directly on the command line – most are interactive – a requested operation gets immediate response Network – many computers joined together in order to share resources (storage, printers, processing capabilities, files, communication). Ethics in Computing – computers have had profound effect on society and vice versa – every profession has a set of ethics that define responsibilities of practitioner Software Piracy – unauthorized copying of software for personal use or use by others without permission of creator Privacy of Data – should not take advantage of access to confidential data Use of resource – should not gain unauthorized access to any computer – should not develop/disseminate viruses Tips for problem solving: ask questions to clarify problem statement and try not to reinvent the wheel – if you have seen a similar problem, repeat the solution Solve by analogy – maybe the problem being solved might be easier if the solution to another problem was explored – the other problem need not be a computer problem! Divide and conquer – break problem into smaller pieces that can be solved more quickly Building-block – determine if a large problem can be solved by smaller problems that already have a solution Merging – combine existing solutions on a step-by-step basis If faced with a mental block – try writing the problem down in own words When developing an algorithmic solution, keep in mind the list of things the computer can do (from above) and repeated here – base solution on these operations: Instructions are based on what computer can perform: transfer of data, input data from device, output data to device, store data to memory/secondary storage, retrieve data from memory/secondary storage, compare two values, perform arithmetic operations