Download presentation
Presentation is loading. Please wait.
Published byBeatrix Golden Modified over 9 years ago
1
Two-week ISTE workshop on Effective teaching/learning of computer programming Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay Lecture 1, Introduction to Programming Monday 28 June 2010
2
Overview Teaching and Learning Computer Programming The three contexts of data and information handling Human, computing environment, program Mr Dumbo: Model of Computing for a program Dumbo’s memory How Dumbo interacts with us Dumbo’s computing Instructions and their execution Dumbo’s ability to store programs
3
Teaching Computer Programming The following sequence is often observed: Computers are introduced, with some information on hardware, operating systems, compilers, and editors Syntax of the chosen programming language is explained with examples Different features such as data types, control structures, arrays, functions, etc., are covered ‘Advanced’ topics such as pointers, structures, files, etc., are discussed The subject is often called by the language used. Thus we have C programming, Java programming, etc.
4
Learning Computer Programming Students first struggle with actual computers, often failing to type correctly and speedily They then struggle to understand the programming concepts which are being doled out one by one Several first year students have studied in their own language. They find difficulty in understanding lectures given in English, and with English books While they may sketchily understand individual programming concepts, they are uncomfortable writing full programs. Size of their average program rarely exceeds 100 Lines of Code (LoC) They struggle to learn problem solving due to the emphasis on details of syntax.
5
Information Handling in different contexts The Human way has evolved from spoken languages to written scripts to organized information management using spoken words, handwritten documents, letters, books, instruction manuals, data sheets, registers and ledgers, forms, etc. In particular, human exchange of information, when done manually, can take multiple forms. Consider the following exchanges between a manager (M) and a clerk (C)
6
Human information exchange – scene 1 (M) Has read the temperature in the room from an instrument which gives readings in Fahrenheit. Assume the value is 86 0 F. (M) asks (S) to convert it in centigrade. (M) can give this value to (S) in many ways: 1. Verbally tells him : 86 2. Writes the value on a piece of paper as (a) 86 (b) Eighty Six (c) Temperature is 86 0 F
7
Human information exchange – scene 1... (S) Calculates the converted value in degree Centigrade using the well known formula C = (F-32) x 5/9, finds out it is 30 0 C. Again (S) can give this value to M in many ways: 1. Verbally tells him : 30 2. Writes the value on a piece of paper as (a) 30 (b) Thirty (c) Temperature is 30 0 C
8
Human information exchange – scene 2 Results of an exam, in the form of a list of roll numbers of students who have passed the examination along with the marks scored, have been declared in a news paper. (M) Asks (S) to find whether a student has passed the exam. (M) Can give to (S) the desired roll number in any of the ways we have seen. How would (M) give the list of declared roll numbers? 1. Write down all the numbers on a page in ascending order of marks and give it 2. Hand over the news paper to (S) which has the list in ascending order of roll numbers
9
Context of the Computing Environment Hardware (monitor and Key board) Operating Systems, command prompt File system: Directories, subdirectories and files Compilers, linkers, executables Debuggers, Development Environment Students have to cope up with all of this without properly understanding the underlying principles
10
Environment of a program The ‘model’ of computing implemented by our program as seen by the user Variables Memory locations Data types Input output, files Use of control structures and data structures in the program
11
Teaching of CS 101 at IIT Bombay The course is titled “ Computer Programming and Utilization”, emphasizing problem solving We currently use C/C++ to convey programming concepts We always discuss a problem first, describe a solution (i.e., evolve an algorithm) and then develop the program to implement that algorithm. We attempt to show complete programs. “Segments” are discussed only in the context of a full program Lab assignments often have ready programs which they have to suitably modify. Students form a team to do a course “project”. The code written often exceeds 2000 LoC
12
Approach chosen in this Workshop We will keep in mind the syllabus usually followed in most colleges. We will generally cover topics in that order. However, the IIT style is chosen to always take a problem, work out its solution first, and then discuss the complete program. Each problem and corresponding program will have a new programming concept implicitly introduced Labs will require modifying and executing given programs. There will be group projects
13
Buddhu Ram Computer - Mr Dumbo We will use the second caricature having a monitor as its head A keyboard is not shown, but learners will assume it by implication
14
Buddhu Ram Computer - Mr Dumbo Dumbo cannot do anything on his own but can execute given instructions correctly Can do arithmetic, logical comparisons, manipulate strings, etc. Essentially, can manipulate values, and produce resultant values He can Compute So he is a computer
15
Dumbo has poor memory Dumbo cannot remember anything in his head
16
Dumbo has poor memory Dumbo uses a cupboard with drawers as memory Dumbo’s memory A B C D F E
17
Dumbo can store values in his memory Each drawer contains some value, for example A number: 437 A name (string): Ranade Location B: 437 Location F: Ranade B F 437 Ranade Dumbo’s memory
18
Some Peculiarities of memory Each location can contain only one value And not multiple values How does a value get into a location? Dumbo stores a given value Dumbo calculates and stores that value Some values may already exist in a location (How?) Such values are ‘unknown’ or ‘undefined’ Not supplied by us
19
Exchanging values with Dumbo Dumbo uses a cart (‘Data Bus’) to move values in and out He can put a value in a location as instructed or can copy a value from a location and give it to us A B C D F E 58
20
Exchanging values with Dumbo … But Dumbo does anything only if instructed So if we give an instruction: cin >> B; Why do we to use ‘>>’ ? Why cin?, why not any other phrase, such as input, read, get ? Or even scanf(“%d”, &B); Dumbo will collect a value given by us, take it to his memory cupboard, store it in location B Any earlier value will be overwritten
21
Exchanging values with Dumbo … Dumbo can output values from locations to us The instruction to do so is cout << G; cout << a << g << coeff << root; Dumbo will copy values from memory locations and present these to us Values in locations are not changed A useful additional feature cout << "Value of count is” << c;
22
Let us try out Dumbo’s Input/Output cout << “Give value for B”; cin >> B; A B C D F E 437
23
Let us try out Dumbo’s Input/Output … cout << "Give value for F"; cin >> F; A B C D F E Ranade
24
Dumbo Computing If two numbers are stored in drawers A and B, say 35 and 12, Dumbo can add these and store the result in a drawer, say, SUM, B SUM 12 ? A
25
Dumbo Computing We instruct him by saying: SUM = A + B; B SUM 12 ? A [35]
26
Dumbo Computing … How will Dumbo do this? Dumbo uses rough sheets or ‘Registers’ Access the location A and copy the value (35) into a register Access the location B and copy the value (12) into another register Add the two values to get (47) Store the result value back in location SUM Location SUM will now contain value 47
27
Dumbo Computing Dumbo uses a set of local registers Working Sheets on a table B SUM 12 ? A 35 12 47
28
Result of Dumbo Computing A and B continue to hold the existing values Location SUM will now contain 47 B SUM 12 47 A [35]
29
Animated Dumbo An Introduction to Dumbo Showing Dumbo, his memory drawers and a typical input operation Dumbo performing computations Showing addition of two numbers
30
How do we give instructions Most machines take one instruction at a time, and execute it special Dumbo is special We can write all our instructions in advance, and give the entire lot to him programThis collection is called a program Dumbo has a ‘stored program’ capability
31
Where does Dumbo keep the program? In the same memory! Dumbo uses some space for storing data values, and another separate space in the same cupboard to store instructions of our program Instruction space Data Space
32
A complete program // program 1 (prog1.cpp) #include // #include for c programs, for using scanf, printf using namespace std; // this program reads two integer numbers and calculates the sum int main() { int A; int B; int SUM; cout << “Give two numbers” << “\n”; cin >> A >> B; SUM = A + B; cout << “Sum is” << SUM << "\n"; return 0; }
33
Convert temperature from 0 C to 0 F // Program 2 (prog2.cpp) #include using namespace std; // this program converts from Centigrade into Fahrenheit int main() { float C; float F; cout << “Temperature in degree Centigrades ?"; cin >> C; F=C*9/5+32; cout << F << “\n”; return 0; }
34
Quiz 1 Approximately, how many different programming languages have been defined so far by the computer scientists? (you have to guess) (A) About 5 (B) 6 to 20 (C) 21 to 100 (D) More than 100
35
Quiz 2 The symbol “\n” in the instruction: cout << F << “\n”; Will produce the following additional output: (A)Nothing visible, an end of line is inserted (B) \n (C) n (D)I cannot guess
36
Home Assignment Rewrite the programs to as proper C programs How will you explain the difficult syntax and its semantics (meaning) of the input/output instructions in C to a novice student? (scanf and printf)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.