CSCI 1320 (Principles of Computer Science I):
Sample Programs
Disclaimer: Code linked from this page is intended as a
cleaned-up and commented version of examples from class.
Many programs could be further improved with
regard to functionality or design, but then they would
no longer be as close to what we did in class.
Programs
- "Hello, world" program (8/28)
hello.scala.
- Two versions of program to count out change (9/11)
countchange-val.scala,
countchange-var.scala.
- Two more versions of program to count out change (9/16)
countchange-val-2.scala,
countchange-var-2.scala.
- Sketch of program to calculate letter grade (9/16)
grades.scala.
- Revision of letter-grade program using function (9/23)
grades-2.scala.
- Bounding-box function (9/23)
bbox.scala.
- Factorial functions (9/25)
factorial.scala.
- Program to "count down" using recursion (not in class)
countdown.scala.
- Program to sum numbers using recursion (10/07)
sum.scala.
- Fibonacci function (not in class)
fibonacci.scala.
- Four-function calculator program (10/07)
calc.scala.
- Array demo program, recursive version (10/09)
array-demo.scala.
- List demo program, recursive version (10/09)
list-demo.scala.
- Array demo program, collection-methods version (not in class)
array-demo-2.scala.
- List demo program, collection-methods version (not in class)
list-demo-2.scala.
- Function to check whether string is a palindrome (10/20)
palindrome.scala.
- Function to compute variance (10/20)
variance.scala.
- Array demo program, loop version (10/30, partly)
array-demo-3.scala.
- List demo program, loop version (not in class)
list-demo-3.scala.
- Program to sum integers using loop (10/30)
sum-loop.scala.
- Program to find primes (10/30)
primes.scala.
- Simple "ASCII art" program to test/display bounding box
function, preliminary version (11/04)
ascii-art-1.scala.
- Simple "ASCII art" program to test/display bounding box
function, revised version (not in class?)
ascii-art-2.scala.
- Program to sum integers read from file (11/06)
sum-from-file.scala.
- Program to echo command-line arguments (11/11)
echo-args.scala.
- Program to count lines in files given as command-line arguments (11/11)
count-lines.scala.
- Program to combine files (not in class)
combine-files.scala.
- Bounding-box function, revised to use case class (11/11)
bbox-case-class.scala.
- Program to sum integers read from file, version that deals more
nicely with common errors (11/13):
sum-from-file-2.scala.
- Revision of letter-grade program to get input from file (11/13):
grades-3.scala.
- Sorting and searching (11/20, Dr. Lewis):
sorts.scala.
- GUI "hello world" programs (11/25):
gui-hello.scala,
gui-hello-with-button.scala.
- Simple GUI "sampler" program,
multiple versions with slightly different layouts (12/02):
gui-sampler.scala,
gui-sampler-2.scala,
gui-sampler-3.scala.
- Simple graphics "sampler" program (12/04):
graphics-sampler.scala.
- Example GUI programs (11/25, 12/02, 12/04):
Other files