CSE 1341: CS I (Fall, 1999)
Topics Covered between Exams #1 and #2
Thursday, 10/7/99
- Exam#1 review:
- distribution and interpretation
- some common problems:
- B(I.1): language characteristics
- I.2: truth table
- I.3: "for" <=> "while", how to handle loop index increment
- III.2: data type and loop count (also prompt)
- IV: "switch" inside loop
- partial sample solutions to Exam#1: e1.c
- functions: introduction and concept
- example functions in e1.c
- definition and body
- how to call it
- how to declare it
- hw#7
Tuesday, 10/12/99
Thursday, 10/14/99
- questions about hw#7?
- appearances of functions in programs
- function declarations: function prototypes
- result/return type and argument specifier
- procedures in C (vs. in other languages)
- function definitions: body
- function calls:
- parameter/argument passing
- call handling and stack concept
- library vs. user defined functions
- function declarations compared to variable declaration
- declare before use
- default for functions (but not for variables in C)
- default for variable in other programming languages
- functional structure in C:
- flat structure in C vs. other languages
- compare to variables: global, local, and within blocks
- scope rules (comparison)
- why functions?
- divide-and-conquer for large problems/applications
- top-down design or stepwise refinement
- repeated operations
- cohesion within a block/sub-task
- coupling: where to cut things off
- additional examples from Chapter 4
- no parameter/no return value: gameloop.c,
- one papameter/return value: iseven.c and c2ftable.c,
- sharing information among functions
- parameters/arguments
- reference by value
- reference by address
- global variables: use with caution
- among different files
- a look ahead: hw#8
Tuesday, 10/19/99
- exam#2 information
- functions and algorithms: example programs
- factorials: fact.c, p.147 and p.152
- combinations: combine.c
- stepwise refinement example in Section 5.6,
- and the final program calendar.c
- statistics and search (max, min, avg, match, selection, etc.)
- algorithms: testing for primality
- basic ideas and implementation:
- definition about factors
- check the number of factors
- implementation: primes1.c
- conformance and verification
- demonstrating correctness
- inspection (desk-checking) vs. formal verification vs. testing
- alternative algorithms and implementations
- efficiency issues: primes2.c
- no need to get check multiple factors
- short-cut the loop once the answer is found
- even numbers?
- implementation: primes2.c
- efficiency issues: primes3.c
- problem in primes2.c: specical case for 2
- efficiency in loops: sqrt function
- implementation: primes3.c
- hw#8
Thursday, 10/21/99
- questions about hw#8
- algorithms: greatest common divisor
- brute-force: gcd.c
- efficiency issues
- a more efficient algorithm: euclid.c
- numerical algorithms efficiency improvement
- make use of logical relations among items
- stop early: primes3.c;
- stop when answer is found
- stop before redundant situation appears
- jump over unnecessary steps: euclid.c;
- using bigger steps: primes3.c
- avoid un-necessary computation inside loop:
- e.g. move sqrt() outside of the loop in primes3.c
- algorithm comparison: recursion vs. iteration
- compare iterative Factorial (p.147 and p.604)
- recursive Factorial (p.605)
- efficiency comparison
- solution ideas: clarity comparison
- trade-off between the two.
- functions and pointers
- an introduction to pointers
- sharing more than one data items
- the meaning of "&"
- the meaning of "*"
- xfer.c: example program for "transfer()"
- looking ahead: graphics library and hw#9
- for now: design on paper
Tuesday, 10/26/99
- partial solution to hw#8.
- standard C vs. functional libraries and interfaces
- library functions: system and user defined
- interface: usage vs. implementation
- usability/function vs. portability/maintainability
- (standard) formatted I/O (text 15.5, pp.539-547)
- printf()
- "scanf()"
- use of header files
- abstraction, specification and prototype
- use in structured and object-oriented programming
- link to top-down design and stepwise refinement
- graphics library
- graphics.h
- list of graphics library functions: p.227
- what they do: specification (pp.228-230)
- new: initializing package
- examples: arc1.c, arc2.c, drawcirc.c, oneline.c
- building your own tools: example programs
- examples: drawcirc.c, drawbox.c, drawcbox.c
- larger problem: e.g. "house.c" using stepwise refinement
- top-down vs. bottom-up design
- functions/tools from "house.c" that can be used for your hw#8:
- DrawCenteredCircle()
- DrawBox()
- DrawGrid()
- hw#9
- design process and document
- program implementation/debugging/documentation
- demo
Thursday, 10/28/99
- questions about hw#9?
- principle of enumeration
- representing non-numerical information
- coding scheme
- character representation
- constant representation
- enumerated types
- variables of enumerated types
- example: typedef enum {CSE, EE, ME} DeptInSEAS;
- associated values:
- default: start with 0 and go up
- over-write default values
- individual definition, example
- mixture, example
- example: ATM with enumerated types
- atm.c
- new data type: optionT
- use in declarations/prototypes/parameters
- associated values
- advantage of enumerated types
- automatic coding by compilers
- simpler than named constants
- easy for reading/comprehension/modification
- debugging help
- characters
- data type: char answer='y';
- example in primefactor.c
- single quote vs. double quote
- ASCII code (p.309)
- special characters (p.311)
Tuesday, 11/2/98
- computation with characters
- utilities based on ASCII code properties
- ctype.h library and interface
- test: islower(ch), isupper(ch), isalpha(ch), isdigit(ch), isalnum(ch),
ispunct(ch), isspace(ch)
- convert: toupper(ch), tolower(ch)
- example in primefactor.c
- input: getchar()
- output: "%c" with printf()
- sample programs
- sketch for "tolower()" (p.315)
- sketch for "IsVowel()/main()" (p.316)
- use of "getchar()":
- lastchar.c
- functions and algorithms with character type
- strings as character arrays (later)
- hw#10
- review for Exam#2
- topics covered: on-line list
- focus on functions and algorithms
- use of library functions, particularly graphics.h and ctype.h
Thursday, 11/4/99
Prepared by Jeff Tian
(tian@seas.smu.edu).
Last update Nov. 3, 1999.