1 COMP 102: PROGRAMMING I SPRING 2012Material is based on*Programming Logic and Design, Fifth Edition, Comprehensive Chapter 1* Introduction to Programming in C++: Algorithms,Flowcharts and Pseudocode by BrentDaviduck
Course OutlineInstructor Information:Name Ms. Saira AnwarEmailSairaAnwar@fccollege.edu.pkSairaAnwar@hotmail.comOffice S – 211Office HoursMonday, Wednesday 10:00 – 11:00Tuesday, Thursday 11:00 – 12:00Class Meet Tuesday, Thursday 9:00 – 10:50 AMCategory•Core course for all Computing Majors•Recommended General Education Course for students withsome enthusiasm to learn programming and who want to feel realflavor of writing a programPre- Requisite NilWebsite https://sites.google.com/site/comp102seca/
Course Outline Text Book Java in Two Semesters by Quentin Charatan and Aaron Kans Java 6 Illuminated Second Edition By Julie Anderson, Herve Franceschi Reference Books Art and Science of Java by Eric Roberts Thinking in Java, by Bruce Eckel Java, The Complete Reference, by Patrick Naughton, Herbert Schildt Java and Object Orientation: An introduction, John Hunt The Java Handbook , by Patrick Naughton, Michael Morrison Java in a Nutshell: A Desktop Quick Reference for Java Programmers , by David Flanagan The Java Language Specification , by James Gosling , Bill Joy, Guy Steele Whos Afraid of Java?, by Steve Heller
Course OutlineGrading: Lab Quiz (Consider them 45% exams) Assignments and Quiz 7% Project 7% Group Quiz 1% Mid (Out of class) 20% Final 20% Total 100.00%•REGRADING CAN BE REQUESTED WITHINFOLLOWING TIME LIMITS:QUIZZES AND HOMEWORKS: 2DAYS, EXAMS: 3DAYS
Course OutlineAttendance and Quiz Policy:•Attendance in class is mandatory.•Inadequate attendance (less than 85%)may lead to disqualification from theMidterm and/or Final Exams.•Take attendance on random days.•There could be both announced and un-announced quizzes•Deadlines are hard deadlines.
Course OutlineAcademic Honest:•What is plagiarism?“Plagiarism is defined as presenting someone else’s work as your own. Work means any intellectual output, and typically includes text, data, images, sound or performance.” (Office of Academic Appeals & Regulation 2005) Office of Academic Appeals & Regulation, 2005, Section 2.1 of the published procedures on “ Cheating, plagiarism and fraudulent or fabricated coursework ” (available online at http://www.leeds.ac.uk/AAandR/cpff.htm - accessed 6th Aug 2005)
Course OutlinePlagiarism is serious:•All cases are reported and go on yourstudent record.•Penalties vary from written warnings, re-sitting modules to expulsion from theUniversity.•Why? – plagiarism undermines theUniversity’s reputation and the quality of itsdegrees and research, plus plagiarists missout on learning!
Course OutlinePlagiarism Detection:•Subject experts knowledge of the disciplineand its literature.•Changes in writing style, inappropriatewriting style.•Electronically.
Course OutlineReferences:•“Write the text taken from others in doublequotes and italicize the text. Put referencecat the end.”.•If your ideas match to someone putreferences .•If you want to put multiple references. Putthem like it .•You have to double quote the major termslike “Software Engineering”.
Course Outline “The only stupid question is the one which is never asked”[Unknown]
Good programmers can rule the kingdom !11
Understanding Computer Components and Operations12 Hardware and software: the two major components of any computer system Hardware: equipment, or devices Software: programs that contain instructions for the computer Four major operations in a computer: Input Processing Output Storage
Program Input (Data) PROGRAM Output (Results) (Algorithm)13 Takes some values as INPUT PROCESS Them Produce some result as OUTPUT
Programming Task14 A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps is called an algorithm Implementation phase implement the program in some programming language
Understanding Computer Components and Operations15 Input devices: allow data to enter the computer Mouse, keyboard, scanner Processing: working on the data Organizing data Checking data for accuracy Mathematical or other manipulations on data Central Processing Unit (CPU): hardware that performs the tasks
Understanding Computer16 Components and Operations Output devices: provide data to the user Printer, monitor, speakers Programming language: special language containing instructions for the computer Visual Basic, Java, C#, C++, COBOL Syntax: rules governing word usage and punctuation in the language
Understanding Computer17 Components and Operations Machine language: controls the computer’s on/off circuitry Compiler or interpreter: software that translates programming languages to machine language Program must be free of syntax errors to be run, or executed, on a computer To function properly, the logic must be correct Algorithm = Syntax + Semantics
Understanding18 the Programming Process Six programming phases: Understand the problem Plan the logic Code the program Use software to translate the program to machine language Test the program Put the program into production
Understanding the Problem19 May be the most difficult phase Users may not be able to articulate their needs well User needs may be changing frequently Programmers may have to learn the user’s functional job tasks Failure to understand the problem is the major cause of most project failures
Planning the Logic20 Plan the steps that the program will take Use tools such as flowcharts and pseudocode Flowchart: a pictorial representation of the logic steps Pseudocode: Natural language representation of the logic Walk through the logic before coding by desk- checking the logic
Pseudo Code and Flow Charts21 Pseudo Code Algorithms written in structural English Good way to begin a solution design Program flow is not always clear Flow Charts Graphical representation Express flow of control
Using Software to Translate theProgram into Machine Language22 Creating an executable program
Points to Note:231. The process consists of repeated application of simple steps2. All steps are unambiguous (clearly defined)3. We are capable of doing all those steps4. Only a limited no. of steps needs to be taken5. Once all those steps are taken according to the prescribed sequence, the required result will be found6. Moreover, the process will stop at that point
24 Constructs Basic Programming Tools
Sequence/ Sequential Execution Unconditional Transfer Input or output Processing 25
Branching Conditional Transfer ?? 26
Loops Conditional Loop Counted Loop 27
Flowcharts for three constructs29
Using Flowchart Symbols and30 Pseudocode Statements
Elements of Flowcharts32 Symbol Name Flowline Terminal Input/Output Processing Decision
Continued…33 Symbol Name Connector Off page Connector Predefined process Annotation
DEVELOPINGFLOWCHARTSPutting algorithms to work
What is a flowchart? Flowcharts are one method for creating an Algorithm. They allow a process to be described in a step-by-step manner. Other Algorithm types are Pseudocode and Prose.
TerminatorsStart Oval Shape One line in or out Used to indicate the beginning and end of a process Stop
Data Boxes Parallelogram shaped Input One line in, One line out Used to indicate the input or output of data from the system.Output
Process Boxes Rectangle shaped One line in, One line out Used to indicate a process step Process
Decision Boxes Diamond shaped One line in, two lines out Must contain a binaryYes/No question (Yes/No,Question True/False, 0/1, etc) Used to branch a program dependent upon a condition being met
Subprocess Box Rectangle shaped, with bars on the sides One line in, One line outSubprocess Used to include a predefined process
Bad design… What is wrong with this chart? The box has two lines in, one line out… Lines must join other lines, never boxes!
Bad design… What is wrong with this flowchart? Never use curved lines. Always straight Always vertical or horizontal.
Remember… Drawing flowcharts is actually easy. Breaking tasks into small steps is often much harder than it might seem. If you can flowchart it, you can program it.
Flowchart Conversion from Fahrenheit-to- Celsius47
Flowchart for Computing sum, product and average48 Start Start Prompt the user and get Prompt the user and get number1 and number2 number1 and number2 sum = number1 + number2 sum = number1 + number2 product = number1 **number2 product = number1 number2 average =sum/2 average =sum/2 Print sum, product and average Print sum, product and average End End
Flowchart for Computing circumference andarea of a circle49 Start Start Prompt the user and Prompt the user and get radius of the circle get radius of the circle circumference = 2*3.14*radius circumference = 2*3.14*radius Area = 3.14*radius*radius; Area = 3.14*radius*radius; Print circumference and Print circumference and area of the circle area of the circle End End
Flowchart for Computing min and max of 2numbers50 Start Start Prompt the user and get number1 and number2 Prompt the user and get number1 and number2 yes number1 < number2 ? number1 < number2 ? no min = number1 min = number1 min = number2 min = number2 max = number2 max = number2 max = number1 max = number1 Print min and max Print min and max End End
Flowchart : Computing min of 3 numbers51 Start Start Prompt the user and Prompt the user and get number1, number2 and number3 get number1, number2 and number3 yes number1 < number2 ? number1 < number2 ? no yes yes number2 < number3 ? number2 < number3 ? number1 < number3 ?? number1 < number3 no no min = number3 min = number3 min = number2 min = number2 min = number3 min = number3 min = number1 min = number1 Print min Print min End End
Flowchart Computing min of 3 numbers52 Start Start Prompt the user and Prompt the user and get number1, number2 and number3 get number1, number2 and number3 min = number1 min = number1 yes number2 < min? number2 < min? no min = number2 min = number2 yes number3 < min? number3 < min? no min = number3 min = number3 Print min Print min End End