Lecture1:Introduction to Programming andProblem SolvingDaniel ChenTopics• 1. Computer Operations• 2. What is programming?•...
6. Run the program on the computer7. Document and maintain the programDefine the Problem• Divide the problem into three co...
Specific Programming Language• Only after all design considerations have been metshould you actually start to code the pro...
Example 2: Payroll Problem• I: time cards, pay rate, deductions• P: calculate gross pay, calculate net payhours worked = e...
• e.g. calculating sales tax or printing report headings• Three control structures– Sequence (one after another)– Selectio...
sngGradePoint = 0.0End IfRepetition• A set of instructions to be performed repeatedly,as long as a condition is true• Pseu...
– a data item with a name and a value that remain thesame during the execution of the program (e.g. 8, 10)– a constant who...
Upcoming SlideShare
Loading in …5
×

Lecture1

221 views

Published on

sdasdasd

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
221
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lecture1

  1. 1. Lecture1:Introduction to Programming andProblem SolvingDaniel ChenTopics• 1. Computer Operations• 2. What is programming?• 3. What are the steps of programdevelopment?• 4. What is structured programming• 5. Data and data structuresSix Basic Computer Operations1. A computer can receive (input) data2. A computer can store data in memory3. A computer can perform arithmetic and manipulatetext strings4. A computer can compare the contents of twomemory locations and select one of twoalternatives5. A computer can repeat a group of operations6. A computer can output information (processeddata)Computer OperationsWhat is Programming• Program – a very specific set of instructions (orcommand lines) that making a computer do whatyou want it to do• Programming – the process of creating a program– the development of a solution to an identified program,and setting up of a related series of instructions which,when directed through computer hardware, willproduce the desired resultsSteps in program developmentDefine the problemOutline the solutionDevelop the outline into an algorithmTest the algorithm for correctnessCode the algorithm into a specificprogramming language
  2. 2. 6. Run the program on the computer7. Document and maintain the programDefine the Problem• Divide the problem into three components(called IPO):– Inputs – what do you have?– Outputs – what do you want to have?– Processing• how do you go from inputs to outputs?• A defining diagram is recommendedOutline the Solution• The major processing steps involved• The major subtasks (if any)• The major control structures (e.g. repetition loops)• The major variables and record structuresDevelop the Outline into anAlgorithm• Algorithm is a set of precise steps thatdescribe exactly the tasks to be performed,and the order in which they are to be carriedout• Pseudocode (a form of structured English)is used to represent the solution algorithmTest the Algorithm forCorrectness• The main purpose of desk checking the algorithmis to identify major logic errors early, so that theymay be easily corrected• Test data needs to be walked through each step inthe algorithm, to check that the instructionsdescribed in the algorithm will actually do whatthey are supposed toCode the Algorithm into a
  3. 3. Specific Programming Language• Only after all design considerations have been metshould you actually start to code the program intoyour chosen programming language (e.g. VisualRun the Program on theComputer• This step uses a program compiler andprogrammer-designed test data to machine test thecode for syntax errors• Program complier translate high-level languages(e.g. VB) to low-level machine language beforeexecutionDocument and Maintain theProgram• Not the last step in the program developmentprocess• An ongoing task from the initial definition of theproblem to the final test result• Involves both external documentation (such ashierarchy charts) and internal documentation thatmay have been coded in the programExample 1: Circle• Calculate the circumference and area• IPO– I: radius– P: calculate circumference and area ascircumference = 2 * P I* radiusarea=PI * radius ^ 2– O: radius, circumference, areaCircle (Pseudocode)Begin programget radius, PIcircumference = 2 * P I* radiusarea=PI * radius * radiusdisplay circumference, areaEnd program
  4. 4. Example 2: Payroll Problem• I: time cards, pay rate, deductions• P: calculate gross pay, calculate net payhours worked = end time – start timegross pay = hours worked * pay ratenet pay = gross pay - deductions• O: payroll records (gross pay, deductionsnet pay)Payroll problem (cont.)– Deductions include required (taxes) and optional (staff benefits)– Gross pay may include vacation time, sick time, personal time.– Repeat payroll processing for all employees– Employee {pretty much} static data• Name, address, department, …– Employee non-static historical data• Year to date earnings, …– Employee current data• Hours worked, vacation hours, sick hours, …– Global data• Tax tables [federal & state] , tax cutoffsPayroll Problem Pseudocode(…assuming deductions are given)Begin programRead Start_time, End_time, Pay_rate, DeductionsHours_worked = End_time – Start_timeGross_pay = Hours_worked * Pay_rateNet_Pay = Gross_pay – DeductionsDisplay Gross_pay, Deductions, Net_payEnd programStructured Programming– outline a general solution to the problem first– start coding at the beginning of the problem and worksystematically through each step until reaching the end– keep things together that belong together
  5. 5. • e.g. calculating sales tax or printing report headings• Three control structures– Sequence (one after another)– Selection (making decisions/choices)– Repetition (doing things over and over)Sequence• The straightforward execution of one processingstep after another• pseudocode statementsExample of Sequence in VBPrivate Sub CmdTotlasales_Click()Numbercontracts = CInt(TxtTotalContracts.Text)Pricecontracts = CCur(TxtContractPrice.Text)Totalrevenue = Numbercontracts * PricecontractsTxtTotalSales.Text =FormatCurrency(Totalrevenue, 2)Selection• Pseudocode statements:IF condition p is true THENstatement(s) in true caseELSEstatement(s) in false caseENDIF• If condition p is true then the statement orstatements in the true case will be executed, andthe statements in the false case will be skippedExample of Selection in VBIf strGrade = A thensngGradePoint = 4.0Elseif strGrade = B thensngGradePoint = 3.0Elseif strGrade = C thensngGradePoint = 2.0Elseif strGrade = D thensngGradePoint = 1.0Else
  6. 6. sngGradePoint = 0.0End IfRepetition• A set of instructions to be performed repeatedly,as long as a condition is true• Pseudocode statements:DOWHILE condition p is truestatement blockExample of Repetition• Add up all odds between 1 to 20– 1 + 3 + 5 + 7 + 9 + … + 19 = ?– 1 + 3 =4–4+5=9–9 + 7 = 16–… … …–81 + 19 = 100Example of Repetition (Cont)• Computer’s wayPrivate Sub CmdCalcSum_Click()intSum = 0intCounter = 1Do while intCounter <= 20intSum = intSum + intCounterintCounter = intCounter + 2LoopEnd subData– the name given to a collection of memory cells,designed to store a particular data item– the value stored in that variable may change or vary asthe program executes
  7. 7. – a data item with a name and a value that remain thesame during the execution of the program (e.g. 8, 10)– a constant whose name is the written representation ofits value (e.g. “8”, “10”)Data type– Numbers with a decimal point– Two choices in VB: single and doubleData Structures(also called data aggregates)• Record– One set of related data• A time card; an invoice– A set of related records– A collection of data that have same data type– An array of charactersDaniel Chen

×