CS500 - Computer Science for CIT
Summer/2000
Classes: TR 05:30-09:15 p.m., 208 Maria Sanford Hall
Instructor: Dr. Zdravko Markov, MS 203, (860)-832-2711, http://www.cs.ccsu.edu/~markov/,
e-mail: markovz@ccsu.edu
Office hours: MTWR 04:00-05:00 p.m., or by appointment
Description: This is a transition courses for students without
Computer Science undergraduate degree. The course is designed to acquaint
the students with the main ideas and techniques they need to know for taking
the core courses in the CIT curriculum. The course consists of three parts.
The first part is an introduction to computer architecture at the assembly
language level. It is based on the MIPS processor, a simple clean RISC
processor whose architecture is easy to learn and understand. The second
part of the course discusses the fundamental concepts of programming through
Java. This is the major part of the course where the basic programming
structures and object-oriented methodology are studied. In the end of the
course a short introduction to the Web and HTML is provided.
Textbook: John Lewis and William Loftus, Java Software Solutions,
Second edition, Addison Wesley, 2000.
Recommended reading: John Waldron, Introduction to RISC Assembly
Language Programming, Addison-Wesley, 1999.
Programming: The first part of the course teaches assembly programming
on a SPIM simulator. This is a MIPS machine simulator available as a free
software for Unix, DOS, and Windows. The second part of the course uses
Java Development Kit, a software system for developing Java programs also
available as a free software for various platforms and operating systems.
WEB resources:
-
SPIM simulator: A
free software simulator for running MIPS R2000 assembly language programs
available for Unix, DOS, and Windows. Documentation for the Windows interface
to SPIM: postscript
or Adobe PDF file.
-
Assemblers, Linkers,
and the SPIM Simulator (Adobe PDF file): Appendix A of Hennessy &
Patterson, Computer Organization and Design: The Hardware/Software Interface,
Second Edition, Morgan Kaufmann Publishers, Inc., 1997.
-
A resource
page of John Waldron's book Introduction to RISC Assembly Language
Programming.
-
The Web page of the Java Software
Solutions book
-
Java Development Kit, version
1.2
-
Dr.
Neville's Java Resources page
-
Web consortium
-
Ghostscript, Ghostview
and GSview
Assignments and grading: There will be 4 programming assignments
totaling 100 points. The letter grade will be calculated according to the
following table:
A |
A- |
B+ |
B |
B- |
C+ |
C |
C- |
D+ |
D |
D- |
F |
95-100 |
90-94 |
87-89 |
84-86 |
80-83 |
77-79 |
74-76 |
70-73 |
67-69 |
64-66 |
60-63 |
0-59 |
Tentative schedule of classes and assignments
-
Computer organization and design - hardware
software interface
-
MIPS assembly programming
-
Project 1 due. Object-oriented
programming in Java. Objects and primitive data. Read Chapter
2.
-
Program structure: statements, control, loops.
Read Chapter 3.
-
More control structures: for loop, if-else,
switch, use of boolean variables.
-
Project 2 due. Writing
classes. Read Chapter 4.
-
Data structures: string decomposition and using
the stack
-
Project 3 due. Arrays,
vectors and sorting. Read Chapter 6.
-
Enhancing classes. Read Chapter 5.
-
Project 4 due. The
Web and HTML. Read Appendix J
CS500 - Class #1
Computer organization and design - hardware software interface
-
Levels of abstraction in describing computers
-
Software
-
Computer architecture = Instruction set architecture + Machine organization
-
Hardware
-
Levels of computer architecture in more depth
-
Software: application, operating system, firmware
-
Languages: machine language, assembly language, higher level languages
-
Instruction set architecture:
-
Data types and structures
-
Instruction set
-
Instruction formats
-
Addressing modes and accessing data and instructions
-
Exception handling
-
Basic components of the computer
-
Processor: datapath and control
-
Memory
-
I/O system
-
Stored program concept: programs and data, fetch&execute cycle
-
MIPS architecture (SPIM simulator)
-
Processor: general purpose registers, PC and other registers (register
window)
-
Memory: program memory (text segment window), data memory (data segment
window)
-
I/O system: system calls, message window
-
Fetch&execute: MIPS machine simulation (go, single step)
-
Representing instructions and data
-
First MIPS program (Random.asm)
Exercises
-
Write a program to calculate the average of three numbers entered by the
user.
-
Write a program to calculate the age of a person in years and months by
using DOB and today's date both entered as two integers - month and year.
CS500 - Class #2
MIPS assembly programming
-
Control flow structures - branches: leap year example (Leap.asm)
-
Loops: Euclid's algorithm (Euclid.asm)
Exercises
-
Write a program to print N random numbers, where N is entered by the user.
-
Write a program to calculate the average of N random numbers, where
N is entered by the user.
CS500 - Class #3
Object-oriented programming in Java. Objects and primitive data
-
Objects and overall program structure (first
program in Java)
-
String concatenation and arithmetic addition (Addoperator.java)
-
Numeric input, constants, variables, type conversions, casting (Celsius.java)
-
Arithmetic expressions (Arithmetic.java)
-
Using class methods, strings (Jumble.java)
Exercises
-
Write a program to calculate the average of three numbers entered by the
user.
-
Write a program to calculate the age of a person in years and months by
using DOB and today's date both entered as two integers - month and year.
CS500 - Class #4
Program structure: statements, control, loops
-
Do-while loop (Dice.java)
-
Applets (DiceApplet.java and Dice.html)
-
While loop (Euclid-gcd.java). See
an applet implementation of Euclid here.
Exercises
-
Write a program that generates a random number and then asks the user to
guess this number. The program reads the user input in a loop and prints
whether the number entered is greater or less than the generated random
number until the user guesses the number.
-
Implement the version of the Euclid's algorithm based on subtraction. The
basic idea is the following: to find the GCD of two numbers by this algorithm,
repeatedly replace the larger by subtracting the smaller from it until
the two numbers are equal. For example: 132, 168 -> 132, 36 -> 96, 36 ->
60, 36 -> 24, 36 -> 24, 12 -> 12, 12 so the GCD of 132 and 168 is 12. This
implementation of GCD is based on the fact that gcd(a, b) = gcd(a-b, b).
CS500 - Class #5
More control structures: for loop, if-else, switch, use of boolean variables
-
Monte Carlo algorithm for calculating Pi (Pi.java)
-
Iterative approximation of Pi (iteration.java)
-
Nested loops (primes.java). For more
information about prime numbers see this
link.
-
Converting string to integer (str2int.java)
-
Simple calculator (calc.java)
Exercises
-
Use the digits.java program to prove
experimentally that if the sum of the digits of a number is 9, then the
number is multiple of 9 (what about the inverse?).
-
Modify the str2int.java program to convert hexadecimal numbers to decimal.
Add a loop to repeat the input if it is wrong.
-
Include the str2int.java code into calc.java program to read and verify
the numbers (to avoid the standard exception if a wrong argument is entered).
Add a loop to repeat the calculator execution.
CS500 - Class #6
Writing classes
-
Defining new classes (euclid.java) and
using them (use_euclid.java). Parameter
passing and returning values.
-
Encapsulation, visibility modifiers (rational.java
and use_rational.java).
-
Using new objects as parameters (series.java).
Exercises
-
Write a method for rational.java to read a rational number from the keyboard
(read two integers - numerator and denominator). Modify use_rational.java
to use this method.
-
Write a class "student" that represents the student name and the names
and grades for three courses he/she is taking. The class should provide
the following methods:
-
get_name() - returns the student name.
-
get_info() - returns a properly formatted string containing the student
name, classes and grades.
-
get_gpa() - returning the gpa as a floating point number between 0.0 and
4.0
Write a class that creates 3 student objects and prints their class information
and gpa's.
CS500 - Class #7
Data structures: string decomposition and using the stack
-
String decomposition, StringTokenizer class (reverse.java).
-
Using the stack: reverse1.java
-
Printing the stack: mystack.java and
reverse2.java
-
Using a stack to evaluate postfix expressions: Reverse Polish calculator
(polish.java)
Exercises
-
Modify calc.java to work with expressions
entered on a single line.
-
Write a program that evaluates expressions of the following type: a/b
+ c/d or a/b - c/d (a, b, c, d and the result are floating point
numbers). Use StringTokenizer class.
CS500 - Class #8
Arrays, vectors and sorting
-
Arrays of primitive data: min, max, bubble sort (array.java).
-
Initialization of arrays, searching arrays (index.java).
-
Dynamic arrays (vectors): implementing a stack (vect.java).
-
Arrays of objects, sorting strings, using a vector for sorting (online.java).
Exercises
-
Write a program to translate a letter grade (A, A-, B+, ...) into a point
grade (0-4).
-
Use the bubble sort algorithm to sort strings. Use compareTo(String str)
method.
CS500 - Class #9
Enhancing classes
-
Objects and references: simple linked list of objects (List.java)
-
List methods: list constructor, add, append, print (List1.java)
-
Trees and recursion (Tree.java)
-
Event programming, listeners, interfaces, polymorphism: creating an applet
with text input and output (Gcd.java and
Gcd.html)
Exercises
-
Create a linked list of strings by an interactive input and print the list
in normal and reverse order.
-
Create and print the tree for the expression a * b + c - d / f
-
Add input data validation to the Gcd applet.
-
Add a label and a TextField for the applet output.
CS500 - Class #10
The Web and HTML
-
A little history
-
1989, CERN: distribution of linked documents (nuclear physics)
-
1991, text-based prototype
-
1993, First graphical interface - Mosaic
-
1994: WWW consortium (CERN, MIT):
http://www.w3.org
-
The client side
-
WEB documents (pages) connected via hyperlinks (hypertext).
-
Hyperlinks: highlighted strings in text or images.
-
Browsers (text-based or graphical): tools for navigating the WEB.
-
Forms and Java applets
-
The server side
-
URL (Uniform Resource Locator): <protocol name>://<machine name>/<file
name>, e.g. http://www.w3.org/History.html
-
Steps of fetching http://www.w3.org/History.html
-
The browser determines the URL
-
The browser asks the local DNS (Domain Name System) server for the IP (Internet
Protocol) address
-
DNS replies with 18.23.0.23.
-
The browser makes a TCP (Transmission Control Protocol) connection to port
80 on 18.23.0.23
-
It then sends a GET /hypertext/WWW/History.html
-
The www.w3.org server send the file History.html
-
The TCP connection is released
-
The browser displays all the text in History.html
-
The browser displays all the images in History.html (new TCP connection
for each image)
-
Example of HTTP protocol in text:
C: telnet www.w3.org 80
T: Trying 18.23.0.23 ...
T: Connected to www.w3.org
T: Escape character is '^]'
C: GET /hypertext/WWW/TheProject.html HTTP/1.0
HTTP/1.0 200 Document follows
MIME-Version: 1.0
Server: CERN/3.0
Content-Type: text/html
Content-Length: 8247
<HEAD><TITLE> The World Wide Web Consortium
(W3C)</TITLE><HEAD>
<BODY>
<H1><IMG ALIGN=MIDDLE ALT="W3C" SRC="Icons/WWW/w3c_main.gif">
The World Wide Web Consortium </H><P>
The World Wide Web is the universe of network-accessible
information.
...
</BODY>
-
Using other protocols
-
HTTP Browser <---> FTP server
-
HTTP Browser <---> FTP Proxy server <---> FTP server
-
Proxy servers: translating protocols, caching pages, filtering information
-
HyperText Transfer Protocol (HTTP)
-
Simple (GET without the protocol version) and full requests
-
Methods (commands)
-
GET: request to read a Web page encoded in MIME (Multipurpose Internet
Mail Extensions - adding a header to describe the encoding)
-
HEAD: request to read a Web page header
-
PUT: request to store a Web page (may include authentication headers)
-
POST: request to append new data to a Web page (e.g. posting a message
to a news group)
-
DELETE: request to delete a Web page (may include authentication headers)
-
LINK: Connects two existing pages
-
UNLINK: breaks an existing connection between two pages
-
Writing Web pages in HTML
-
URL (Universal Resource Locator): a mechanism for naming and locating Web
pages
-
<Protocol>://<DNS name of the host>/<File name (with possible
shortcuts, e.g. ~user)>
-
Protocols:
-
The HTML language
-
Standardized markup language: how the documents are to be formatted and
reformatted (e.g. LaTeX), contrasted to WYSIWYG (not standardized, does
not allow reformatting)
-
Tags with parameters, e.g. <IMG SRC ="http://www.widget.com/image.gif"
ALT="AWI Logo">
-
Hyperlinks:
-
<A HREF="http://www.nasa.gov"> NASA's home page </A>
-
<A HREF="http://www.nasa.gov"> <IMG SRC="shuttle.gif" ALT="NASA">
</A>
-
Forms (HTML 2.0): two-way trafic between the page owner and page user,
<INPUT> tag. Example: book
order
-
CGI (Common Gateway Interface): a standard for handling forms' data. Example:
interfacing a database:
-
Write a script (program) to interface between a database and the Web
-
Store the script in the cgi-bin directory under an URL.
-
When retrieves a page located in cgi-bin the HTTP server executes
the script.
-
Put the script name in the ACTION parameter of the form.
-
The browser invokes the operation specified in METHOD (usually POST)
-
The script is started and presented with the form input data.
-
After the database retrieval the script produce an HTML file, which is
sent back to the browser.
-
This mechanism can be used to include selected ads in the Web page depending
on what the user is looking for.
-
Java
-
Applets
-
Implementing highly interactive Web pages
-
Running applications and using remote servers or databases
-
Adding animation and sound to the Web page without spawning and external
viewer
-
No need of standard for the Web protocols (HTTP, FTP etc.)
-
The Java system for the Web
-
A Java-to-bytecode compiler
-
A browser that understands applets (<APPLET> tag)
-
A bytecode interpreter
-
Security issues
-
Problem: running a program on the client's machine (possible crash, collecting
private information, consuming resources)
-
Solutions:
-
First barrier: strong typed language - array bounds checking, no pointers
(thus no memory access)
-
Second barrier: bytecode verifier
-
Third barrier: class loader (loading first system classes before looking
for user classes)
-
Fourth barrier: security measures built in the classes, e.g. file access
class (asking user if the applet needs file access).
-
More problems:
-
asking to access the /tmp directory
-
requiring network access to work
-
covert channels
-
Locating information on the Web
-
Example: indexing all keywords in the Web page titles
-
Data structures needed: URL table containing pointers to the heap where
URL's and Titles are stored; Hash table for fast access to the URL table;
Index table.
-
Searching (graph search): depth-first search (recursion, stack overflow),
breadth-first (more practical).
-
Indexing: extracting the words (excluding prepositions, articles etc.)
and creating the index.
-
Using the index: store it as a file and use the CGI to access the file.
-
Problems:
-
Some URL's are obsolete (point to pages that no longer exist)
-
Some machines are temporarily unreachable (choosing proper timeout)
-
How to choose the starting URL (there exists disjoint subsets of Web pages)
- collecting a large number of starting URL's (e.g. from a USENET or previous
version of the URL table)
-
Some documents cannot be indexed (e.g. images, audio)
-
About 20% of the Web pages have no title (or the title brings no information):
-
Indexing all the hyperlinks
-
Indexing all the important words in the text: top 10-20 words with the
largest occurrence frequencies in the page.
-
The search engine could run out of memory or disk space, or the search
might take too long: cooperating servers
Project 1
Write a MIPS program to print the minimum, maximum and the average of N
random numbers. N is an integer entered by the user. Use the code from
Random.asm
to generate the random numbers.
Project 2
Write a program (application in Java) to calculate the sum of the series
1+1/2+1/3+...+1/n in rational numbers (i.e.
represented as fractions). The value of n is a parameter entered by
the user. The following restrictions apply:
-
The program must use integer arithmetic only.
-
The sum of the series must be a rational number (fraction) in its canonical
(reduced) form. For example if the sum is 50/24 it must be reduced to 25/12.
-
The reduction to canonical form must be done by using the Euclid's algorithm.
Example: n=5, that is calculate 1+1/2+1/3+1/4+1/5. The program must do
the following:
-
Ask the user to enter the number of terms in the series.
-
The user enters 5
-
Calculate the sum of the fractions 1+1/2+1/3+1/4+1/5 = 274/120
-
Use the Euclid's algorithm to find the GCD of 274 and 120 (which is 2).
-
Simplify the fraction 274/120, i.e. 274/2 = 137 and 120/2 = 60
-
Print 137/60
Project 3
Write a program "calculator", that works with rational numbers. Use a control
structure similar to calc.java and for the calculations use the methods
from rational.java. The calculator should accept the following operations:
+, -, *, /. In addition operations for comparing rationals should be implemented
(>, <, =) . These operations should produce a boolean result (true/false).
All operations should be implemented as methods of the class rational.java.
Examples (the user input is in italics):
Numerator: 2
Denominator: 4
Operation: +
Numerator: 6
Denominator: 8
Result: 2/4 + 6/8 = 5/4
Numerator: 2
Denominator: 4
Operation: <
Numerator: 6
Denominator: 8
Result: 2/4 < 6/8 = true
Extra credit: Implement single line input for each rational number
and a new operation called ? (to check for <, > or =). Example:
2/4
?
6/9
Result: 2/4 < 6/8
Project 4
Write a program that creates an array of objects of class "student"
(Class #6, Exercise #2) and then prints the information for all students
(by using get_info() method) sorted by student's name
(lexicographic order) and by student's gpa (greatest first). Use
the bubble sort method for sorting. Two version of this program
are acceptable:
Version 1 (maximum 80 pts. out of 100): Create an array
of 5 students directly in the program by using constants
for the student constructor method. For example: st[0] = new student("John
Smith", "CS500", "A-", "IT501","C+", "CS501","B"); Then print the
sorted array by student name.
Version 2 (maximum 100 pts. out of 100): Implement a loop
to enter the student information interactively, i.e. implement commands
for adding a student and print the list of all students sorted by name
and by gpa.
Example of Version 2: student.java
and use_student.java implemented
by Salahuddin Akand.