CS1010: Programming Methodology

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

WEEK 5 Class Activities Lecturer’s slides.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
CS1010 Programming Methodology
CS1010 Programming Methodology
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Topic R1 – Review for the Midterm Exam. CISC 105 – Review for the Midterm Exam Exam Date & Time and Exam Format The midterm exam will be Tuesday, 3 April.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Topic R3 – Review for the Final Exam. CISC 105 – Review for the Final Exam Exam Date & Time and Exam Format The final exam is 120-minutes, closed- book,
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
CS1101: Programming Methodology Aaron Tan.
13&14-2 Know the forms of loop statements in C (while,do/while,for). Understanding how data conversion occurs. Read/Write data in files using Unix redirection.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 7: One More Loop Problem, Generating “random” values, Midterm Review.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
CS1010: Programming Methodology
Repetitive Structures BBS514 Structured Programming (Yapısal Programlama)1.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
WEEK 4 Class Activities Lecturer’s slides.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
CS1101: Programming Methodology Aaron Tan.
CS1101: Programming Methodology
Previously Repetition Structures While, Do-While, For.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
Chapter 5: Control Structures II
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
WEEK 1 Class Activities.
CS1101: Programming Methodology
COMP Loop Statements Yi Hong May 21, 2015.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 4: Control Structures (Part 2) Xiang Lian The University of Texas – Pan American Edinburg, TX
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
WEEK 10 Class Activities Lecturer’s slides.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
WEEK 1 Class Activities.
Introduction to Computer Programming
CS1010 Programming Methodology
CS1010 Programming Methodology
CS1010 Programming Methodology
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
ECE Application Programming
Lecture 7: Repeating a Known Number of Times
C++ Programming: CS150 For.
CS1010 Discussion Group 11 Week 6 – One dimensional arrays.
Week 4 – Repetition Structures / Loops
CS1010 Programming Methodology
Chapter 5: Control Structures II
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CS1100 Computational Engineering
3 Control Statements:.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Let’s all Repeat Together
Arrays, Part 1 of 2 Topics Definition of a Data Structure
EPSII 59:006 Spring 2004.
do/while Selection Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Presentation transcript:

CS1010: Programming Methodology

Extra class: 25 September 2013  Objectives:  To go over the basic concepts covered in the first 6 weeks  To give out some programming exercises to test students’ understanding of these basic concepts CS1010 (AY2013/4 Semester 1)Recess Extra Class - 2

Summary (1/2)  Week 1:  Writing algorithms (pseudo-codes)  Week 2:  Input (scanf) and output (printf)  Types (int, float, double, char, etc.) and variables  Mathematical operations (*, /, %, +, -)  About integer division  Week 3:  Top-down design  Writing functions  Using math functions  Discussion session: Writing algorithms, programming environment, using CodeCrunch CS1010 (AY2013/4 Semester 1)Recess Extra Class - 3

Summary (2/2)  Week 4:  Selection statements: ‘if’, ‘if-else’, ‘switch’  Discussion session: Inaccuracy of real numbers, initialisation of variables, redundant assignment, writing functions.  Week 5:  Repetition statements: ‘while’, ‘do-while’, ‘for’  Discussion session: Good programming practice, using selection statements, conditional operator ?:, using repetition statements.  Week 6:  Functions with address parameters  Discussion session: Repetition statements, functions with address parameters, design issues, exploration on random numbers. CS1010 (AY2013/4 Semester 1)Recess Extra Class - 4

Skills  Using vim  Pseudo-code before code  Clear logic  Can you convince yourself that your algorithm works before you start typing the program?  Simplifying the problem  If you get a complex problem, what would you do? (Reference: Week 6 Discussion Q5 Asterisks)  Incremental coding  Do you type in the whole program at one go? Or a bit at a time?  Understanding compiler’s messages  Do you know where to zoom into your program to spot the error? CS1010 (AY2013/4 Semester 1)Recess Extra Class - 5

Week 6 Discussion Q5: Asterisks  (b) CS1010 (AY2013/4 Semester 1)Recess Extra Class - 6 * *** ***** * *** ***** * *** ***** ******* ********* *********** * *** ***** ******* ********* ***********  (c) * *** ***** * *** ***** * *** ***** ******* ********* *********** * *** ***** ******* ********* ***********

Big Question  Have you been writing a lot of programs by yourself?  Target: Write 150 programs by the end of this semester  For students with no experience: 200 programs  Possible! Average about 17 programs per week over 12 weeks. Less than 3 programs a day! CS1010 (AY2013/4 Semester 1)Recess Extra Class - 7

Tracing  Another important skill: Tracing codes.  Reinforce that program execution is done step by step following the sequence, selection and repetition control structures.  Every variable should be represented by a box, and its value updated during the trace.  Manually trace the given programs in the hand-out, and write out their outputs. CS1010 (AY2013/4 Semester 1)Recess Extra Class - 8

Count multiples of 5 or 7 (Practice Ex #18)  Write a program multiples5or7.c that asks user for a positive number num, and count the number of multiples of 5 or 7 in the range [1, num].  Your program should have a function count_multiples(int)  Time limit: minutes  Sample runs: CS1010 (AY2013/4 Semester 1)Recess Extra Class - 9 Enter positive integer: 10 There are 3 multiples of 5 or 7 in [1,10]. Enter positive integer: 10 There are 3 multiples of 5 or 7 in [1,10]. Enter positive integer: 6 There is 1 multiple of 5 or 7 in [1,6]. Enter positive integer: 6 There is 1 multiple of 5 or 7 in [1,6]. Enter positive integer: 50 There are 16 multiples of 5 or 7 in [1,50]. Enter positive integer: 50 There are 16 multiples of 5 or 7 in [1,50].

Perfect numbers (Practice Ex #19) (1/2)  Definition:  A perfect number is a positive integer that is the sum of its proper positive divisors.  Examples:  6 is a perfect number, because 6 =  8 is not a perfect number, because 8   100 is not a perfect number, because 100   Write a program check_perfect.c that asks user repeatedly for a non-negative integer, and stops when the number is zero.  It should have a function is_perfect(int) that returns 1 if the parameter is a perfect number, or 0 otherwise.  For each positive integer entered, your program is to check whether it is a perfect number or not. CS1010 (AY2013/4 Semester 1)Recess Extra Class - 10

Perfect numbers (Practice Ex #19) (2/2)  Time limit: minutes  Sample run: CS1010 (AY2013/4 Semester 1)Recess Extra Class - 11 Enter number: 6 6 is a perfect number. Enter number: 8 8 is a not perfect number. Enter number: is not a perfect number. Enter number: 0 Enter number: 6 6 is a perfect number. Enter number: 8 8 is a not perfect number. Enter number: is not a perfect number. Enter number: 0

Check order of input data (Pract. Ex #20) (1/2)  Write a program check_order.c to read in a list of positive integers.  The program is to continue asking for the next positive integer as long as the integers entered so far are in increasing order.  The moment the input data are not in increasing order, or the input value is zero, the input ends.  The program should then report whether the input data are in increasing order or not.  You may assume that at least one positive integer is entered. If that is the case, we treat the list as in increasing order. CS1010 (AY2013/4 Semester 1)Recess Extra Class - 12

Check order of input data (Pract. Ex #20) (2/2)  Time limit: minutes  Sample runs: CS1010 (AY2013/4 Semester 1)Recess Extra Class - 13 Enter positive integer: 3 Enter positive integer: 0 Data are in increasing order. Enter positive integer: 3 Enter positive integer: 0 Data are in increasing order. Enter positive integer: 10 Enter positive integer: 12 Enter positive integer: 21 Enter positive integer: 0 Data are in increasing order. Enter positive integer: 10 Enter positive integer: 12 Enter positive integer: 21 Enter positive integer: 0 Data are in increasing order. Enter positive integer: 100 Enter positive integer: 102 Enter positive integer: 100 Data are not in increasing order. Enter positive integer: 100 Enter positive integer: 102 Enter positive integer: 100 Data are not in increasing order. Enter positive integer: 7 Enter positive integer: 31 Enter positive integer: 56 Enter positive integer: 56 Data are not in increasing order. Enter positive integer: 7 Enter positive integer: 31 Enter positive integer: 56 Enter positive integer: 56 Data are not in increasing order.

Reminders Revise all of the following  Textbook and lecture notes  Discussion questions  Lab exercises Write many programs! Post queries on IVLE forum and read postings by others You CAN succeed! CS1010 (AY2013/4 Semester 1)Recess Extra Class - 14

End of File