Computer Science 261

Second Programming Exercise

Due: various (two due dates have been changed)

Please note the change in the length of the part name field

This is an exercise in three parts (mostly review)

1. (10 pts.) Implement a solution to problem 1.13(b). Strings should be accepted by cin, and will consist of a string of left and right parenthesis followed by a period ('.'). The total number of characters (including period) will not exceed 20.

 This will be due Tuesday, Sept. 28 (after the exam Friday). Call your program paren.cpp and place the source only in your handins folder. (please see the note at the end of this write-up)

2. Create an object called a PartObj with the following (private) fields:

More fields may be added in later exercises.

The object should have two constructors (the default constructor, and one which will accept part number, part name, and amount fields (see below)), and a print method. These should be written so that the following code works:

 

int main()
{
     PartObj Part1, Part2("12345", "BOLT", 100);
 
     Part2.print();
 
     Part1 = PartObj("54321", "NUT", 50);
     Part1.print();
 
     return 0;
}

 

Call this program part01.cpp, and place (as always, source only) in your handins folder. This program is due Thursday, Sept. 23 (the day before the exam). Please note the important note at the end of this write-up

 

3. Create an inventory object as an array of no more than 100 parts objects. This array, together with a variable that holds the actual number of parts, should be private.

 Create two constructors: a default constructor that simply sets the "count" variable to zero, and a constructor that accepts the name of a file of parts records (a string) and reads the records in the file into the array. Note that you will need to use the public constructor for the part object in this constructor.

Create a public method to produce a report of the records in the part file. Your method should (for the moment) use the print method of the part object (so not a report in the usual sensewith columns and column headers).

Your class definition should work with the following code:

int main()
{
 
     InventoryObj CompanyInventory;
     CompanyInventory = InventoryObj("parts.dat");
     CompanyInventory.print();
 
     return 0;
}

 The file parts.dat is now available on Plato in my handouts folder for this class

 Call this program parts02.cpp, and place it in the handins folder. This program will be due Thursday, Sept. 31.

 Important note:

A note on programs: Because of the technique I use to grade programs, programs must be named exactly as requested (including attention to case). No additional commands (such as "do you want to run this again") should be included. These programs are compiled and run by a Unix shell script which is pretty unforgiving about changes in file names and expected inputs.

 

-Bob