CSCI 240 Spring 2014

Program 10
Classes
(100 points)


Overview

For this assignment, modify the Seller class from program 9 and modify some of the code from program 8 so that it will work with an array of class objects rather than an array of structures.

Modifications to the Seller class

The following methods should be added to the class:

void increaseSalesTotal( double increaseAmount )

This method will increase a Seller's sales total by a specific amount. It takes one argument: a double that represents the amount to increase the Seller's sales total. It returns nothing.

If the passed in increaseAmount is greater than or equal to 0, it should be added to the salesTotal data member. Otherwise, an error message should be displayed and the salesTotal data member should remain unchanged.

char * getFirstName()

This method returns a Seller's first name data member. It takes no arguments.

prototype:   char * getFirstName();

Method:
char * Seller::getFirstName()
  {
  return firstName;
  }

The * is something new for the 240 class. It is used to "tell" the compiler that the method will be returning an address. This is satisfied by the method returning the name of the character array. This topic will be discussed in further detail in the 241 class :-)

char * getLastName()

This method returns a Seller's last name data member. It takes no arguments. Use the code for getFirstName as a pattern for this method.

char * getID()

This method returns a Seller's ID number. It takes no arguments. Use the code for getFirstName as a pattern for this method.

Modifications to Program 8

For this assignment, along with the methods for the Seller class, there will also be functions. They will all be taken from program 8 and will need to be modified so that they work with an array of class objects rather than an array of structures.

Make sure that the prototypes for these functions are placed *AFTER* the Seller class definition but *BEFORE* int main().

int buildSellerArray( Seller sellerArray[] )

This function will be called to read the seller data into the seller array. As in program 8, the data will be coming from an input file. For this assignment, the file is named sellers10.txt and it has the same format and data as the sellers8.txt file from program 8.

In program 8, it's possible that a bunch of assignment statements were used to "fill" the various data members of the structure. So maybe something like:

Seller oneSeller;
string strValue;

inFile >> strValue;
oneSeller.firstName = strValue;    - OR -    sellerArray[sub].firstName = strValue;

The code will need to be modified for this program because the data members for a class object will be private and therefore they cannot be directly accessed using the dot notation. Instead, one of the set access methods will have to be used. So the earlier code becomes:

Seller oneSeller;
char strValue[80];        <--- note the change from string data type

inFile >> strValue;
oneSeller.setFirstName( strValue );    - OR -    sellerArray[sub].setFirstName( strValue );

void printSellerArray( Seller sellerArray[], int size )

This function should print the contents of the seller array. Unlike program 8, there will not be a cout statement to display the information for a Seller. Instead, the print method should be called for each element in the array of Sellers.

void sortSellersByID( Seller sellerArray[], int size )

This function should sort the seller array in ascending order by the seller ID using the selection sort algorithm covered in class.

The logic for this function is the same as in program 8. However, the comparison on the decision statement will have to be changed so that it will use:

  1. the strcmp function to compare two strings that are stored in character arrays
  2. the getID method when accessing the ID data member for an element in the array of Sellers

int findSellerID( Seller sellerArray[], int size, char searchID[] )

This function will be called to find the position of the seller array element with a seller ID that matches searchID. Note the change to the last argument for the function.

The logic for this function is the same as in program 8. However, the comparison on the decision statement will have to be changed so that it will use:

  1. the strcmp function to compare two strings that are stored in character arrays
  2. the getID method when accessing the ID data member for an element in the array of Sellers

void processSales( Seller sellerArray[], int size )

This function will read a series of sales records, each containing a last name, a first name, and a sales amount. For each sales record, the method should search for the seller name and, if found, should add the sales amount to the sales total for that seller. If a seller name is not found, an error message should be printed.

Again, the logic for the function will be the same as in program 8. The changes that need to made to implement the logic are:

  1. Change the declaration for the search id string so that it is a character array
  2. Change the input file to sales10.txt from sales8.txt
  3. Use the increaseSalesTotal method to add the salesAmount from the input file to the sales total for the Seller at element index of the seller array

main()

If main was written correctly in program 8, there is no need to change anything in main for this program.

Programming Notes

  1. The two input files for the program are sellers10.txt and sales10.txt

  2. Each method AND function must have a documentation box.

  3. Hand in a copy of your source code using Blackboard.

Output

The output for this program is the same as the output for program 8.

                  Seller Listing

Name                          Seller ID    Sales

Billick, Lance                BIL912        783.33
Burruel, Erik                 BUR091       4839.12
Burdge, Clayton               BUR146        101.35
Caraveo, Lorrie               CAR026       1019.45
Christoff, Ted                CHR728       1204.95
Dauber, Tabatha               DAU083       8349.55
Deforge, Nannie               DEF201       8934.43
Glessner, Mathew              GLE726       3943.32
Helberg, John                 HEL834       3320.99
Hoops, Allan                  HOO737        874.97
Jones, Ann                    JON374       3825.85
Limas, Kelly                  LIM529       7493.15
Martucci, Cody                MAR389       3847.90
Marciniak, Hugh               MAR423       7374.23
Martinez, Roger               MAR723       2783.32
Monroig, Harriett             MON283       1938.02
Oestreich, Darryl             OES873       1994.55
Piekarski, Neil               PIE129       5562.44
Rollman, Ken                  ROL333        914.97
Shuttleworth, Penelope        SHU837       3921.29
Smith, John                   SMI902       1205.78
Sugg, Louisa                  SUG762       8373.22
Tekulve, Hillary              TEK711       2392.34


   Sales Transactions

Seller ID     Sale Amount

GLE726           914.23
HEL834           307.34
SHU837           192.34
BUR146           410.35
ROL333          1400.34
CAR026           519.65
JON374           342.78
BUR146           431.35
MAR723           286.42
LIM529           793.41
GLE727        Error - ID not found
MON283          1382.50
DAU083           349.65
TEK711           392.34
BIL912          1736.38
DEF201           921.48
CAR026          1239.54
BUR146          1201.32
CHR728           204.55
MAR423           332.44
HOO737           537.79
MAR389           384.20
BUR091           639.62
MAR423           374.23
MON283          1228.52
LIM529           493.15
SHU837           321.29
SUG762           313.21
BUR146           131.35


                  Seller Listing

Name                          Seller ID    Sales

Billick, Lance                BIL912       2519.71
Burruel, Erik                 BUR091       5478.74
Burdge, Clayton               BUR146       2275.72
Caraveo, Lorrie               CAR026       2778.64
Christoff, Ted                CHR728       1409.50
Dauber, Tabatha               DAU083       8699.20
Deforge, Nannie               DEF201       9855.91
Glessner, Mathew              GLE726       4857.55
Helberg, John                 HEL834       3628.33
Hoops, Allan                  HOO737       1412.76
Jones, Ann                    JON374       4168.63
Limas, Kelly                  LIM529       8779.71
Martucci, Cody                MAR389       4232.10
Marciniak, Hugh               MAR423       8080.90
Martinez, Roger               MAR723       3069.74
Monroig, Harriett             MON283       4549.04
Oestreich, Darryl             OES873       1994.55
Piekarski, Neil               PIE129       5562.44
Rollman, Ken                  ROL333       2315.31
Shuttleworth, Penelope        SHU837       4434.92
Smith, John                   SMI902       1205.78
Sugg, Louisa                  SUG762       8686.43
Tekulve, Hillary              TEK711       2784.68