CMSC 341 Fall 1998  Data Structures - Project 1

Assigned:
    Section 101: Tuesday 9/8/98
    Section 201: Wednesday 9/9/98
Due:
    Section 101:  Midnight, Sunday 9/27/98
    Section 201:  Midnight, Sunday 9/27/98

The Project

Computers store integers as signed numbers. In an 8-, 16- or 32-bit integer, the high order bit is the sign bit (1 = negative, 0 = positive), and the remaining bits indicate the magnitude. In this project, you will create and implement a Signed Number class.

Purpose:

The purpose of this project is to introduce you to C++ programming and to compilation of multiple files. The project also introduces the use of a Makefile. This is not a hard project to write, but it will raise some questions and problems which may take a while to resolve.

Description:

I will provide two files for your project -- the makefile and a test program. The files "Makefile" and "project1.C" are located on gl, in the directory /afs/umbc.edu/users/d/e/dennis/pub/cs341/proj1. Copy them into your working directory. You will provide the following files: 1. a header file named SignedNr.h which contains your class definition 2. a source file named SignedNr.C which implements your class If you name your files as I do and produce no other source files, then you can use Makefile and project1.C with no changes. You are free to produce any files you wish, and name them anything you wish except that you MUST name the results file project1.results and the executable project1. Changing the names of the other files may mean that you will have to change the Makefile to reflect your changes. You may also have to change project1.C to #include additional or different files. In any event, you are responsible for the correct compilation and submission of your project. You may develop your project on any system you want, but it MUST compile, link and execute on the UMBC Unix GL system. You must submit ALL files (including the Makefile and project1.C) which are needed to sucessfully build your executable.

The Specific tasks:

1. write the SignedNr class, putting the definition in SignedNr.h and the implementation in SignedNr.C. Your class should contain two data members. One holds the sign (1 = negative, 0 = positive) and one holds the magnitude (absolute value). 2. write the following constructors a. the default constructor SignedNr::SignedNr() which initializes the SignedNr to zero b. SignedNr::SignedNr (int value) which initializes the SignedNr to the specified value (positive or negative) c. SignedNr::SignedNr(int sign, int value) which initializes the SignedNr to the specified sign and value d. the copy constructor SignedNr::SignedNr (const SignedNr&). Each constructor should print an appropriate message indicating that it has been called. For example, a call to SignedNr::SignedNr(int value) might output something like "constructor SignedNr(6) called". 3. Write a destructor for SignedNr (the destructor will not actually destroy anything). The destrcutor must output a message indicating that it has been called and indicate the object that is being destroyed. 4. Overload the arithemetic operators +, *, and += for SignedNr. 5. Overload the asignment operator =. 6. Overload the relational operartors == and < which return boolean values 1 or 0. 7. Overload the unary operator- which changes the sign of the SignedNr and the unary operator! which returns 1 or 0, depending on whether the SignedNr is zero or not. 8. Overload the operator << for printing SignedNrs. This operator should output the appropriate sign and value. For negative numbers, output the value immediately after the minus sign (no spaces) For example, "-6". For positive values, a + sign is not required.

Hint:

When coding the operators, be sure to consider the various combinations of signs (i.e both positive, both negative, one positive and one negative). Also don't forget to handle SignedNr objects whose value is zero. Your code will be easier if you guarantee that a SignedNr with value of zero always has a "positive" sign.

Compiling the Project

A Makefile has been provided to help you in compiling your project and in cleaning up your directory * To compile the project, type make * To remove backup files from your directory, type make clean * To remove backup files, object files, and core, type make cleaner * To remove backup files, object files, core, and the project1 executable itself, type make cleanest

Submitting Results

Results are to be submitted in a file named project1.results. To produce the results file, execute your program by typing project1 > project1.results. ALL files necessary to successfully compile your project must be submitted. ALL means "all header files, all source files and your Makefile", even those supplied by me. You must also submit your results file. To avoid penalty for lateness, projects must be submitted by 11:59:59 pm of the due date. If available, we will use the submit program to submit our files.

Project Grading

Any project that does not build (i.e. the make command does not run to completion without errors and does not produce and executable) will be limited to a maximum grade of 50%. Any project that does not produce the correct results will be limitied to a maximum grade of 80%. Any project submitted at least 24 hours before midnight of the due date will recieve a 5 point bonus. Late projects will be accepted up to 48 hours late with a 5 point penalty per day. I.e between 1 second and 24 hours late -- 5 point penalty between 24 - 48 hours late-- 10 point penalty no project will be accepted more than 48 hours late without prior approval which will only be given under dire circumstances. The close the deadline gets, the more dire the circumstances must be. Projects will be graded on the following criteria 1. style 2. comments 3. structure 4. proper execution

Help

Help is available for this project. The Computer Science Help Center is staffed with knowledgeable tutors who can help with the programming aspects of the project. TAs are also available -- see the home page for TA contact information.

Last Modified

Sunday Sept. 20, 1998 6:15 pm by Dennis L. Frey