



|
|
Byron's CSC212 Web Site
|
Class Notes
Monday October 23 , 2000
|
|
|
Notes on Incremantal Programming using Functional Application Architecture.
Class Notes --
Monday October 23 , 2000
CSC212 - October 23, 2000
=========================
Lecture Topic: PROGRAMMING ASSIGNMENT #4
Incremental Programming using Functional Application
Architecture
Example:
P0
static public void main (------)
{
// Read & Echo Two Integers
int a = IO.read_int();
int b = IO.read_int();
IO.println("a= " + a);
IO.println("b= " + b);
}
P1
static public void main (------)
{
// Same As P0
-----
-----
// Compute and print the max value
int max = max (a, b);
IO.println(max);
}
static private int max (int a, int b)
{
if (a > b);
}
return a,
{
else
}
return b
}
P2
static private int max (int a, int b)
{
P0
P1
P2 Print min value
int min = min (a, b)
IO.println("min= " + );
P3
static privte int max (int a, int b)
{
P0
P1
P2
// Compute and display the difference
int diff = max - min
IO.println("diff = * + diff);
}
P4
// Final Version
Simply delete all output statments other than the
final output statemant.
Problem:
Read several (at least one) non-negative integer and
compute their real average.
"while loop" data type
{
<?program> ->
// Establish an "accumulator"
int sum = 0
// Establish a counter to count data
int count = 0
// Sum the integers
int sum = IO.read_int();
while (num >= 0)
{
sum = sum + num;
count = count + 1; // count++
num = IO.read_int();
}
// Compute & display the average
double ave = (double) sum / (double) count;
IO.println("ave = " + ave);
}
Hand Simulation:
In -> 5 10 -2
Environment
sum -> 0 5 15
count -> 0 1 2
num -> 5 10 -2
ave -> 7.5
Out -> 7.5
Problem: Read several non-zero integers and display the
largest of three.
Ex:
In -> 10 7 95 4 66 0
Out -> 95
In -> -10 -7 -95 -4 -66 0
Out -> -4
Comparison Trials
10
10 vs 7 -> 10
10 vs 95 -> 95
95 vs 4 -> 95
95 vs 6 -> 95
=======================================================
123456789112345678921234567893123456789412345678951234567
|
|
|