The George Washington University
School of Engineering and Applied Science
Department of Computer Science
CSci 131 -- Algorithms and Data Structures I
Project #1
Due Date: start of class, Monday, January 28, 2002
http://www.seas.gwu.edu/~csci131/spring02/131s02p1.html

This project depends on material in Chapters 1 and 2 of the data structures book, as well as on the exception-handling and file material in the book used in Csci 51 (especially Section 7.6 and Section 10.3). All code files (.ads and .adb) mentioned in this handout can be found online in your programs131 directory on hobbes.

The purpose of this project is to get you (back) into developing software with Ada 95. This project and the next several projects will, progressively, develop and refine a data base for handling motor vehicle records. Since each project will build on the previous one, you must complete each one on schedule!

Part I. Completing the initial version of the Cars package.

You will begin this part in your first lab. The file cars.ads contains the interface (specification) for a very basic package (class, software component) to handle car records. This package provides a few types, a constructor ("setter") operation (method) and a set of selector ("getter") operations (methods):

PACKAGE Cars IS
------------------------------------------------------------------
--| This package provides data structures and operations for
--| simple car records, each record containing a tag number,
--| car make, purchase price, weight, and owner's name.
--| The package makes use of resources provided
--| by the package Currency.
--|
--| Author: Michael B. Feldman, The George Washington University
--| Last Modified: January 2002
------------------------------------------------------------------

  -- constant and type definitions

  TagLength:  CONSTANT Positive :=  6;
  NameLength: CONSTANT Positive := 10;

  SUBTYPE TagType  IS String(1..TagLength);
  SUBTYPE NameType IS String(1..NameLength);
  SUBTYPE WeightRange IS Integer RANGE 500..2500; -- weight in kg

  TYPE CarBrands IS (Ford, Chevrolet, Honda, Subaru);

  TYPE CarType IS PRIVATE;

  -- operations

  -- constructor

  FUNCTION MakeCar(OneTagNumber: IN TagType;
                   OneBrand:     IN CarBrands;
                   OnePrice:     IN Currency.Quantity;
                   OneOwner:     IN NameType;
                   OneWeight:    IN WeightRange) RETURN CarType;
  -- Pre: all input parameters are defined
  -- Post: returns a value of type CarType

  -- selectors

  FUNCTION RetrieveTagNumber (OneCar: IN CarType) RETURN TagType;
  FUNCTION RetrieveBrand     (OneCar: IN CarType) RETURN CarBrands;
  FUNCTION RetrievePrice     (OneCar: IN CarType) RETURN Currency.Quantity;
  FUNCTION RetrieveOwner     (OneCar: IN CarType) RETURN NameType;
  FUNCTION RetrieveWeight    (OneCar: IN CarType) RETURN WeightRange;
  -- Pre:  OneCar is defined
  -- Post: each selector retrieves its desired field

PRIVATE

  TYPE CarType IS RECORD
    TagNumber: TagType     := "xxxxxx";
    Brand:     CarBrands   := CarBrands'First;
    Price:     Currency.Quantity;
    Owner:     NameType    := "nnnnnnnnnn";
    Weight:    WeightRange := WeightRange'First;
  END RECORD;

END Cars;

The file cars.adb contains a partially implemented body for this package. The selectors are coded, but the constructor is a stub. In this part, your task is to complete the stub. The file basic_test_cars.adb contains a simple test program so you can see the results of your work. Before completing the stub, the output of this program is

Values for OneCar:
xxxxxx
FORD
nnnnnnnnnn
0.00
500
Values for OneCar:
              >>>>> Entering RetrieveTagNumber
              >>>>> Leaving RetrieveTagNumber
xxxxxx
              >>>>> Entering RetrieveBrand
              >>>>> Leaving RetrieveBrand
FORD
              >>>>> Entering RetrieveOwner
              >>>>> Leaving RetrieveOwner
nnnnnnnnnn
              >>>>> Entering RetrievePrice
              >>>>> Leaving RetrievePrice
0.00
              >>>>> Entering RetrieveWeight
              >>>>> Leaving RetrieveWeight
500

after completing the stub, the output should be

Values for OneCar:
VANITY
HONDA
John Smith
16000.00
750
Values for OneCar:
              >>>>> Entering RetrieveTagNumber
              >>>>> Leaving RetrieveTagNumber
VANITY
              >>>>> Entering RetrieveBrand
              >>>>> Leaving RetrieveBrand
HONDA
              >>>>> Entering RetrieveOwner
              >>>>> Leaving RetrieveOwner
John Smith
              >>>>> Entering RetrievePrice
              >>>>> Leaving RetrievePrice
16000.00
              >>>>> Entering RetrieveWeight
              >>>>> Leaving RetrieveWeight
750

Part II. Developing the IO Child Package for Cars.

In the manner of Chapter 2 in the data structures book, we will follow the design principle of separating interactive and file input/output from computational methods. By analogy with Rationals.IO and Currency.IO, in this part of the project you will develop and test a child package Cars.IO. The interface is in cars-io.ads:

WITH Ada.Text_IO;
PACKAGE Cars.IO IS
------------------------------------------------------------------
--| This package provides Get and Put operations for values of
--| type Cars.CarType.
--|
--| Author: Michael B. Feldman, The George Washington University
--| Last Modified: January 2002
------------------------------------------------------------------

  PROCEDURE Get (Item: OUT CarType);
  -- Pre:  None
  -- Post: Gets a car record from the keyboard, robustly

  PROCEDURE Get (File: IN Ada.Text_IO.File_Type; Item: OUT CarType);
  -- Pre:  File is defined and is open for input
  -- Post: Gets a car record from the file named in File;
  --       assume all values in File
  --       are valid and in the proper sequence

  PROCEDURE Put (Item: IN CarType);
  -- Pre:  Item is defined
  -- Post: Displays one car record on the screen

  PROCEDURE Put (File: IN Ada.Text_IO.File_Type; Item: IN CarType);
  -- Pre:  File is defined and is open for output
  -- Post: Writes a car record to the file named in File

END Cars.IO;

Your task here is to develop and test the body. Use a test program modeled on the basic one, with code added to make sure all methods in the IO package are working properly. An important aspect of the file-oriented IO is that Put must write a value to the file in a form that Get can read later on. This is called composability of operations: a file written with a succession of Puts must be readable with the same number of Gets.

What to submit:

For Part I, submit listing (.lss, .lsb) files for the cars package and the basic test program, and a turnin showing a successful test of the package after you have completed the stub.

For Part II, submit a test plan for testing the IO package, listing files, and a turnin showing one or more successful test runs.