Introduction to Software Design

Course Overview
CS221 – Advanced Programming
Fall 2007 : Ray S. Babcock
Computer Science Department
Montana State University
Finally! Not an introductory course! 



An old 1976 book had the following title:
 Algorithms + Data Structures =
Programs
 By Nicklaus Wirth
Both Algorithms AND Data Structures
should be considered equally important
when solving problems using programs.
Time – Space tradeoff.
 Time and space are inversely
proportional.
CS221 F'07
Course Overview
2
Time VS Space

To produce the same solution in less space (memory) an increase
of computation time is necessary.
 The Invoice File Sorting Problem from 1975.







CS221 F'07
Many invoices for each month during the year.
Random Access Memory was extremely limited. 64K
Yes, only 64K, and the OS took up 32K!!
Can’t load all the invoices into RAM.
Can load all the invoices on the huge 128K 8-inch Floppies.
No disk sort commands (like the Linux sort command).
How would you solve this problem?
Course Overview
3
The Invoice File Solution


The disk (floppy) file management system had up to 16 file units.
 A separate file can be “opened” on each file unit.
We opened a separate file for each month:
 Opened “Jan” on file unit 1.
 Opened “Feb” on file unit 2.
 …
 Opened “Dec” on file unit 12.
 Opened “Input” on file unit 13.
CS221 F'07
Course Overview
4
Invoice File Solution (continued)





Now for each Invoice in the input file (opened on 13)
 Read one invoice into memory.
 Extract the month code (1 – 12) as an integer.
 Write the invoice to the “month” file unit.
 Repeat.
Close all 13 file units.
One pass through the input file and it was done!
Only memory for one invoice needed!
Cool!
CS221 F'07
Course Overview
5
Algorithms

In this course we will cover extensively
 Traversals and Searches



Linear
Binary
Sorting




CS221 F'07
Selection
Bubble
Insertion
(and more lightly: Shell, Merge, Heap, and Quicksort)
Course Overview
6
Data Structures


In this course we will cover extensively
 Lists
 Stacks
 Queues
We will touch lightly on
 Trees
 Priority Queues
 Graphs
CS221 F'07
Course Overview
7
Course Title?









Advanced Programming (new) versus Data Structures (old) ?
Event-Oriented Programming.
Java AWT and SWING for GUI building.
UML (appendix B and used throughout).
Software Design.
Program Correctness and Efficiency (Big O notation).
Java Inheritance.
Java Class Hierarchies.
And last but certainly not least Abstract Data Types.
CS221 F'07
Course Overview
8
What is a type?



What does it mean by specifying:
 int
 double
 boolean
 String
Is 2+2 calculated the same as 2.0+2.0 ?
What does memory look like?
CS221 F'07
Course Overview
9
0005540
0005560
0005600
0005620
0005640
0005660
0005700
0005720
0005740
0005760
0006000
0006020
0006040
0006060
0006100
0006120
0006140
0006160
0006200
0006220
0006240
0006260
0006300
0006320
0006340
c910
8955
c085
a360
0000
3f80
e800
0424
ffff
0000
8303
c483
ec83
2404
c085
fcb4
fffd
e8ea
55ff
458b
c0d8
f9de
a33c
d824
def9
CS221 F'07
90c3
56e5
0b7f
0804
44c7
44c7
fdc2
0000
44c7
04c7
24c6
5b20
c710
0000
107f
ffff
83ff
fe12
e589
0b0c
38a1
e8d9
0804
83c0
d9e1
9090
8353
c483
db31
0c24
0424
ffff
0000
0824
0124
44a1
5d5e
2404
0000
3fe8
60be
01c3
ffff
5657
0845
04a3
e9dc
d089
01ea
f05d
9090
20ec
5b20
7489
0003
0000
44c7
04c7
001e
001b
04a3
ede9
4000
3de8
fffe
04a3
c683
c483
8353
850f
8308
c9d9
c829
1489
758b
9090
44a1
5d5e
1424
0000
0000
0824
1e24
0000
e800
8308
fffc
0000
fffd
83ff
3108
3b0c
5b10
1cec
00c8
01e8
5dd9
e883
db24
8bf0
9090
04a3
79e9
44c7
44c7
04c7
0000
0000
44c7
fe9a
03e8
55ff
49e8
a1ff
10c4
89db
441d
5d5e
558b
0000
0489
8bf0
8901
2404
440d
9090
8308
fffd
1024
0824
9724
3f80
e800
0424
ffff
c339
e589
fffe
a344
5e5b
2434
04a3
87e9
8b10
db52
db24
f07d
2404
c483
04a3
9090
03e8
beff
0004
0000
000d
44c7
fd06
0000
c383
867c
5356
c7ff
0804
e95d
05e8
7c08
fffc
144d
2404
2404
158b
04db
de04
8308
Course Overview
Segment from a CS425
program that displays a
bézier curve! (obviously )
10
A Type Simply limits



The values
The operations
Helps prevent the following:
 Assume I let and integer MONTH stand for the current
month. (1 = Jan, 2 = Feb, … 12 = Dec).
 Now I work my way through the year by using MONTH =
MONTH + 1
 What happens when I use that expression when MONTH
equals 12? What is month 13?
 The March 0 story.
CS221 F'07
Course Overview
11
Some In Class Examples.

Given: (ignore the – bullets!)
 int a = 2;
 int b = 4;
 int c = 5;
 double d = 1.2;
 double e = 2.4;
 double f = 3.6;
 double g = 1.55;
 double sum = 0.0;
 What prints System.out.println(expression);
CS221 F'07
Course Overview
12
Integers a=2,b=4,c=5
Doubles d=1.2,e=2.4,f=3.6,g=1.55,sum=0.0










(a/b)
0
(b/a)
2
(1/a)
0
c/a
2
a/d
1.6666666666666667
CS221 F'07
Course Overview
13
Integers a=2,b=4,c=5
Doubles d=1.2,e=2.4,f=3.6,g=1.55,sum=0.0








(e/d)
2.0
(f/2)
1.8
(2147483647 + 1)
-2147483648
Did you get them all right?
You’re playing with type and internal representation!
CS221 F'07
Course Overview
14
What about the following?
sum = 0.0;
for(int i=0; i<100; i++) sum=sum+g;
System.out.println(“sum=“+sum);
 What Prints?
 sum=155.00000000000003
 Why?
CS221 F'07
Course Overview
15
ADT





The built-in types don’t cover all our needs.
Most modern languages allow us to define an Abstract Data
Type.
We define
 The type name.
 The permitted values.
 The permitted operations (methods)
Often, one of the first things to design for a solution are a set of
Abstract Data Types.
We’ll do this often in this course.
CS221 F'07
Course Overview
16