CIS 327 Lab 5

Points: 30 Due Date: Monday September 29, 2003

This will mean working with a standard template list. You can use the code in the example as a reference. You will create a class that will represent a customer that you are trying to call before the Do Not Call list becomes effective. Each customer object will have a first and last name and a phone number. These can all be represented as strings. You will need some other data fields as well.

You will need another class that represents the worklist for the day. It contains the list of customers and is used to record statistics about the work. In this you will record how many sales, how many didn't answer and how many asked to be removed.

To load the list, I have provided some data in this file. We haven't talked about file reading yet so here is some code that sets up the file to be read. To use this, you have to put the data file in the project. You can do this by using the add menu item under project or by copying the file into the Debug directory under the project folder. In the main() for your program do this:
First, add a #include to get the file i/o routines. This goes after the one for iostream

		#include <fstream>
Then, in main(), create a file object and open it like this.
	ifstream indata; 
	indata.open("lab5data.txt");
	if(!indata) {
		cerr << "File open failed" << endl;
		return 0;
	}
To read the data just put a while loop something like this:
		while(!indata.eof()) {
		   indata >> lname >> fnamne >> phone;
		}
I put a little sample file reader program here.

Here is what this does. First read in all the data and create objects of the customer type for each line in the file. Put these in the list object that is stored in the worklist object. Then start the simulation. You don't have to type anything to make this work. The program will run until one of several things happens. If all phone numbers are removed from the list, then stop. If you have gotten at least one successful sale, one no answer and one removal, you can stop.

Each time around the loop will represent one call. You should start with the first number on the list and go to the end. If you get to the end and haven't met the criteria above, then start over at the beginning of the list. For each call, you will generate a random number between 0 and 99, I'll show you how below. If the number is between 0 and 29, the call was not answered. If the number is between 30 and 40, the customer should be removed. If the number is between 41 and 60, the customer bought something and shouldn't be called again. If the number is between 61 and 99, the customer said no but can be called again. To generate a random number, just include

		#include <>math.h>
Then this expression will store a number between 0 and 99 in x;
	int x = rand() % 100;

After the loop is over, I want two reports. One of them is the number of calls attempted, the number of customers sold to and the number who asked to be removed, The other report will show for each customer how many times they were called. Removed customers will not show up in this report.

You should write a main program that demonstrates that all these functions work. You should catch obvious errors in the functions.

Spend a lot of time thinking before you write. There are ways to solve this that are simple to write, once you think of them and ways that are simple to think of but hard to write.

Deliverables:

You should turn in a listing of the program. Staple the cover sheet to that.

Notes

Start as soon as you can, pointers are quite tricky and can be confusing. Think about how you will do this so you can ask questions during lab.
ASK if you have any questions.