CS 14 - Lab 0


CS 14 Homepage

Lab 0

The lab assignment for this lab is completely optional however I highly suggest that you complete the lab. The assignment is designed to give you a bit of practice with coding and classes to get you back into the swing of programming. This is very important for those of you that haven't programmed in a while and are a bit rusty.

Review for proficiency exam

I suggest you look over the study guide for the proficiency exam. If you are not familiar with some of the things on this list, I suggest you look through a general C++ programming book or search on the web for more information.

Integer set lab practice

In this lab you will practice:

Create a class called IntegerSet. A set is represented initially as an array of ones and zeros. Array element a[i] is 1 if the integer i is in the set. Array element a[j] is 0 if the integer j is not in the set. The default constructor initializes a set to the so-called empty-set (i.e. a set whose array representation contains all zeros).

An object of type IntegerSet is instantiated by passing to the constructor an integer representing the range of the set. For example, a set of the integers 0 to 99 is instantiated as follows:

An array containing the appropriate number of elements is allocated dynamically and initialized by the constructor.

Provide member functions for the common set operations. For example, provide a unionOfIntegerSets member function that creates a third set which is the set- theoretic union of two existing sets (i.e. an element of the third array's set is assigned a 1 if that element is 1 in either or both of the existing sets).

Provide an intersectionOfIntegerSets member function that creates a third set which is the set-theoretic intersection of the two existing sets (i.e. an element of the third set's array is set to 0 if that element is 0 in either or both of the existing sets and an element of the third set's array is set to 1 if that element is 1 in each of the existing sets).

Provide an insertElement member function that inserts a new integer k into a set (by setting a[k] to 1). Provide a deleteElement function that deletes integer m (by setting a[m] to 0).

Provide a setPrint member function that prints a set as a list of numbers seperated by spaces. Print only those elements which are present in the set (i.e. their position in the array has a value of 1). Print --- for an empty set.

Provide an isEqualTo member function that determines whether two sets are equal.

Provide a copy constructor that takes as a parameter a reference to an IntegerSet object.

Provide all of these options on a menu for the user. Continue to let the user choose actions until they choose to exit.

Make sure to use good programming style throughut.

Make sure to provide good error checking throughout. When you pair up with another group to test your code, they will be trying to find those error conditions you did not check for.

Problem-Solving Tips

Questions/Activities

© 2003 UC Riverside Department of Computer Science & Engineering. All rights reserved.