Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS1010: Programming Methodology

Similar presentations


Presentation on theme: "CS1010: Programming Methodology"— Presentation transcript:

1 CS1010: Programming Methodology http://www.comp.nus.edu.sg/~cs1010/ http://www.comp.nus.edu.sg/~cs1010/

2 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

3 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

4 Module Website 4 25 July 2014 http://www.comp.nus.edu.sg/~cs1010

5 IVLE 5 25 July 2014  https://ivle.nus.edu.sg https://ivle.nus.edu.sg Watch out for announcements Participate in the forums Multimedia videos

6 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

7 Skills 7 25 July 2014 Language constructs Problem solving Coding

8 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 http://www.comp.nus.edu.sg/~cs1010/1_module_info/sched.html http://www.comp.nus.edu.sg/~cs1010/1_module_info/sched.html 8 25 July 2014

9 What to prepare? 9 25 July 2014 Check out CS1010 website http://www.comp.nus.edu.sg/~cs1010 Read document “Intro Workshop: Getting Started with UNIX and CodeCrunch) (http://www.comp.nus.edu.sg/CS1010/3_a/labs.html)http://www.comp.nus.edu.sg/CS1010/3_a/labs.html Learn UNIX Learn vim

10 Taxi Fare (1/4) The taxi fare structure in Singapore must be one of the most complex in the world! See http://www.taxisingapore.com/taxi-fare/http://www.taxisingapore.com/taxi-fare/ 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: 14 27 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 867. 25 July 2014 10

11 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 2014 11

12 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: 14 27 Distance: 10950 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 = $11.70 25 July 2014 12

13 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 2014 13

14 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 2014 14 Example: n = 10 and k = 3 Answer: 14

15 End of file


Download ppt "CS1010: Programming Methodology"

Similar presentations


Ads by Google