CS1010: Programming Methodology
Workshop Overview 2 25 July 2014 Introduction to Computer Programming (L1 & L2) Variables and Operators Basic Input/Output Control Flow Basic Testing and Debugging Problem Solving with Algorithmic Thinking (L3 & L4) Introduction to Programming Language Programming Language Specific Topics Programmin g language specific syllabus Common syllabus
Introduction to Computer Programming (L1 & L2) Variables and Operators Basic Input/Output Control Flow Basic Testing and Debugging Problem Solving with Algorithmic Thinking (L3 & L4) Introduction to Programming Language Programming Language Specific Topics CS1010 Syllabus 3 25 July 2014
Module Website 4 25 July
IVLE 5 25 July 2014 Watch out for announcements Participate in the forums Multimedia videos
Description and Objectives 6 25 July 2014 Introduces the fundamental concepts of problem solving by computing and programming using an imperative programming language. Outcomes Solve simple algorithmic problems Write good small programs C as a tool Not just about C
Skills 7 25 July 2014 Language constructs Problem solving Coding
Workload Lectures: 3 hours/week in a lab setting Discussion sessions: 2 hours/week from week 3 in a lab setting Continual assessments: Take-home lab assignments 2 Practical Exams Term Test Final Exam Refer to module website July 2014
What to prepare? 9 25 July 2014 Check out CS1010 website Read document “Intro Workshop: Getting Started with UNIX and CodeCrunch) ( Learn UNIX Learn vim
Taxi Fare (1/4) The taxi fare structure in Singapore must be one of the most complex in the world! See Write a program Week4_TaxiFare.c that reads the following input data (all are of int type) from the user, and computes the taxi fare: dayType: 0 represents weekends and public holidays (PH for short); 1 represents weekdays and non-PH boardHour, boardMin: the hour and minute the passengers board the taxi (eg: if the passengers board the taxi at 2:27 PM) distance: the distance of the journey, in metres Your program should have a function float computeFare(int dayType, int boardTime, int distance) The parameter boardTime is converted from the input data boardHour and boardMin. It is the number of minutes since 0:00hr. Eg: If boardHour and boardMin are 14 and 27 respectively, then boardTime is July
Taxi Fare (2/4) To implement the actual taxi fare could be a PE question. In this exercise, we use a (grossly) simplified fare structure: Basic Fare: Surcharge (applicable at the time of boarding): Flag-down (inclusive of 1 st km or less)$3.40 Every 400m thereafter or less up to 10.2km$0.22 Every 350m thereafter or less after 10.2km$0.22 dayTypeMidnight charge (12am – 5:59am) Peak hour charge (6am – 9:29am) Peak hour charge (6pm – 11:59pm) 0: Weekends & PH50% of metered fare None25% of metered fare 1: Weekdays and non-PH 50% of metered fare 25% of metered fare 25 July
Taxi Fare (3/4) You are given an incomplete program Week4_TaxiFarePartial.c. Complete the program. This exercise is mounted on CodeCrunch. Sample runs below for your checking Day type: 0 Boarding hour and minute: Distance: Total taxi fare is $9.12 First 1km: $3.40 Next 9.2km: 23 $0.22 = $5.06 Next 750m: 3 $0.22 = $0.66 Basic fare = $9.12 No surcharge Total fare = $9.12 Day type: 1 Boarding hour and minute: 9 20 Distance: 6123 Total taxi fare is $7.83 First 1km: $3.40 Next 5123m: 13 $0.22 = $2.86 Basic fare = $6.26 Surcharge = 25% $6.26 = $1.57 Total fare = $7.83 Day type: 1 Boarding hour and minute: 5 59 Distance: 9000 Total taxi fare is $11.70 First 1km: $3.40 Next 8km: 20 $0.22 = $4.40 Basic fare = $7.80 Surcharge = 50% $7.80 = $3.90 Total fare = $ July
Taxi Fare (4/4) Note that due to inaccuracy of floating-point number representation, depending on how you code your formula to compute the taxi fare, the result may defer slightly from the model output CodeCrunch refers to. Hence, your program may fail CodeCrunch test. In this case, if the difference is very small (probably in the second decimal place), just treat your answer as correct. 25 July
Candles Alexandra has n candles. He burns them one at a time and carefully collects all unburnt residual wax. Out of the residual wax of exactly k (where k > 1) candles, he can roll out a new candle. Given the values n and k, find out how many candles he can burn. 25 July Example: n = 10 and k = 3 Answer: 14
End of file