Learning Objectives For Computer Science 2
Learning Objectives For Computer Science 2
1. Knowledge/Comprehension Objectives:
(a) Students will explain basic ideas of an Abstract Data Type (ADT): interfaces, member data
and member functions (including overloaded operators if the language provides them), object
initialization (e.g., constructors) and termination (e.g., destructors). Students will explain the
public/private distinction and why it is important. They will know language features used to
implement those (e.g., classes in C++).
(b) Students will understand the concept of a linked-list and implement it using pointers and dy-
namic variables. They will implement basic linked-list operations, some of them both recursively
and non-recursively. They will explain the shallow copy vs. deep copy distinction and why it is
important to consider both types of copying.
(c) Students will know the stack and queue ADTs. Students will implement these two classes
efficiently, implemented as both linked-lists and arrays. They will know at least one standard
application each of stacks and queues.
(d) Students will implement insertion-sort and merge-sort. They will understand the concept of big-
O. They will explain, intuitively, why these two sorting algorithms are correct, why mergesort
is O(n log(n)), and why insertion sort is O(n2 ) but not O(n log(n)).
2. Application Objectives:
(a) From a problem description, students will design a solution, including
• identifying appropriate ADTs/classes (including specifying appropriate private/public parts
and constructors and clearly describing responsibilities),
• implementing the ADTs/classes, and
• using (objects of) the ADTs/classes in programs to solve the problem.
When appropriate they will compose classes to represent multiple levels of abstraction and/or
objects containing data described naturally by other classes.
(See Appendix A for guidance on expected sophistication of ADTs and classes.)
(b) Students will further develop their abilities to design and write complex programs, employing
both ADTs/classes as above and top-down design. Students will select appropriate collection
classes from lists, arrays, stacks, and queues.
(See Appendix B for guidance on expected sophistication of programs.)
(c) Given problem descriptions and straightforward but unfamiliar class interfaces, students will
write (fairly simple) algorithms for the problems using those classes. For example, given a
graphics class for displaying cards on the screen, students would program a simple card game.
(d) Students will continue to develop their skills in writing self-documenting programs, including
the skills described for CS 1 plus, for each user-defined class, (a) writing a clear class name
and good member functions names, explanatory comments, and invariant conditions, and (b)
explaining the function of the entire program in terms of the function of its classes.
1
Correlation to published CS & ECE Program Outcomes
Appendices
1. Reverse Polish calculator. This program involves designing and implementing a Reverse Polish calculator
for evaluating Reverse Polish (postfix) expressions. It will utilize two main classes: a calculator class and a
calculator interface class.
The user will enter a character string representing a postfix expression. The expression will then be evaluated
and the result displayed. Allow the user to keep entering postfix expressions until he/she enters the empty
expression (i.e., the null string). Pairs of adjacent elements (operands and operators) in the expression string
should be separated by one or more blanks. The operands of the expression should be decimal floating-point
numbers and the operators should be the standard operations of addition (+), subtraction (−), multiplication
(∗) and division (/). A example expression string is
12.7 23 - 3.14 *
The calculator interface separates the elements of the expression string, converting operands as necessary from
representations to floating-point number representations, and sends them to the calculator for evaluation. (You
may assume that individual entries — numbers or operators — are always separated by spaces.)
1
Note, for example, that it makes no sense to multiply dollars-and-cents times dollars-and-cents and get dollars-and-cents.
2
represented, of course, by 3 points or 3 lines, not 6 real numbers
3
with operations ∪, ∩, −, isEmpty — no fancy algorithms are expected
2
The calculator class should utilize the stack class, with the stack implemented using a linked list. The calculator
class should include functions for the operations of entering a number (pushing the number on the stack),
addition, subtraction, multiplication, division, and obtaining the current value of the expression, i.e., retrieving
the number at the top of the stack.
2. Ordered Implementation of Sets. Given class lists (ordered alphabetically according to last name) for all
the courses being offered at College UCompute, write a program that computes and outputs an ordered list
(without repeats) of all the students at College UCompute. In the design of your program you are to utilize a
class OrderedSet. It should have an operation union where A.union(B) replaces A with A ∪ B and set B to
the empty set. Implement class OrderedSet so that the union can be performed using only a constant amount
of additional storage.
3. Generating random numbers without duplicates. Write a program that outputs a random sequence of
integers without duplicates. Design the client program so that the user is prompted for the size of the sequence
and its interval range — e.g., generate 177 random numbers from range [−43, 1147]. Your program will then
compute a random sequence within this range which contains no duplicates so long as the interval range is at
least as large as the sequence size specified. This program should utilize a class called RandomInt. This class
should be designed to allow the generation of a random number by drawing it from a given interval. Use this
class to generate the random sequence.
4. A class to represent the WWW. A web consists of sites that are linked by hyper-links. You are to design
and implement a class called Web for web objects.
This class will use a 2-dimensional array A known as the adjacency matrix for the web object. The sites of the
web are labeled 0, 1, ..., n-1, where n is the total number of sites. The adjacency matrix is defined by
A[i][j] = true if there is a link on site i to site j, and A[i][j] = false otherwise.
You are to provide the implementation code for class Web. It should have three constructors: (1) a default
constructor that creates an empty web (no sites), (2) a constructor Web(n) that creates a web with n sites,
but no links, and (3) a copy constructor. In addition, implement the following member functions.
• bool testLink(site i, site j) checks whether there is a link from site i to site j.
• int numSites() returns the number of sites in the web.
• int linkSize() returns the number of links in the web.
• void addLink(site i, site j) adds a link from site i to site j. (What if there already is a link?
What if there is no site i? Make reasonable decisions and say, in a comment, why you made them.)
• void display() outputs the adjacency matrix of the web, nicely formatted.
The indegree of a site is the total number of other sites that link to that site. Write an auxiliary function
(i.e., not a member function of class Web) that takes a Web object as an argument and prints a list of the sites,
sorted in order of descending indegrees.
5. Triangles as a foundation class. Define and implement a class that allows triangles to be represented as
objects and allows some operations to be performed on triangles. Each triangle is stored as three points, each
given by its (x, y) coordinates. The functions that can be performed on a triangle include:
• compute the area, perimeter, incenter, and circumcenter of the triangle;
• determine if the triangle is obtuse/right/acute;
• determine if the triangle is contained within a single quadrant;
• determine if two triangles are similar;
• determine if two triangles are congruent;
• determine if two triangles overlap.
3
6. Parabolas as a foundation class. Define and implement a class that allows parabolas to be stored as
objects. Each parabola is defined by giving the coordinates of the vertex and any other one point on the
parabola. Write functions to perform the following operations:
• find the points of intersection of the parabola with the x and the y axes;
• find the points of intersection of two parabola — if they don’t intersect then print a message accordingly;
• determine whether a parabola opens upwards or downwards;
• given two parabolas find out a point which lies inside both the parabolas.
7. Simple Discrete Event Simulation. A bank is asking you to estimate the amount of time customers will
stand in line at the bank.
• You are given a file, one line for each customer, with data separated by spaces, e.g.
Doe John 10 45 14
meaning that John Doe arrived at 10:45 with transactions that will take him 14 minutes (after he reaches
the teller). There are no spaces inside the customers’ names, e.g., it’s deGaulle Charles, not de Gaulle
Charles. The input file is sorted in order of increasing arrival time. You are not told how big the file is.
• The branch bank has one teller. At all times keep track of all the customers currently in the bank. If
there are customers in the bank, one is dealing with the teller, and the others are waiting in a line (queue)
to see the teller. When a new customer comes into the bank, if there are no other customers in the bank,
the customer goes directly to the teller. If there are other customers in the bank, the customer goes to
the back of the line.
• When customers reach the teller, they spend the number of minutes input for their transactions with
the teller and then leave the bank. When the teller is finished dealing with a customer, if there are more
customers in line, the teller tells the customer at the head of the line to leave the line and move up to
the teller.
• Write a program (a simple “discrete event simulation”) that (1) stores, for any given time, what each
customer in the bank is currently doing, and (2) the time the next event will occur — i.e., when the
current customer at the teller will finish or when the next customer will arrive, whichever comes first.
Also keep track of the current time, with a “clock.” When you have finished processing an “event” (a
customer leaving the teller or a new customer entering the bank), look for the time of the next “event,”
jump your clock to that time, and process that event. (When a customer finally reaches the teller, you
will then be able to compute the time when that customer will finish.)
As the program runs, customers will be moved into the bank and to the back of the queue, off the front
of the queue and to the teller, and then back out of the bank.
• Your program do the above simulation until it exhausts all customers in the input file. When the last
customer in the file has left the bank, output summary statistics. Output: the total number of customers,
the average transaction time per customer, and the maximum and average amounts of time the customers
spend in line.
• Have an object called a statistician (probably the unique object of a type class Statistician;
rather like a baseball statistician, not like a mathematics faculty member).
When customers reach the teller, they tell the statistician how long they waited in line and what their
transaction times were. The statistician stores running information, and at the end of the day, the
statistician can compute and output final results.)