|
CS12 Array Processing - 20 points |
|
This project is designed to give students practice with array declaration, loading, and processing.
Customer information (id, name, discount code) stored in a data file should be loaded into
three parallel arrays. The discount code should then be looked up in a discount code array
to get the discount rate. The appropriate discount rate should then be loaded into the
4th parallel array. The values in the four parallel arrays should be displayed in list boxes
so that manipulation of the data can be displayed. Two constant arrays to store the discount codes
and discount rates will be needed.
The four parallel arrays should be able to hold up to 10 customers.
The program should allow the user to load the arrays once, sort by id, sort by name, and search
by name. The name to search for will be entered in a textbox. If there is a match in the list,
the name should be selected in the list box. If the name is not found, a message should
be displayed in a label. The early exit logic should be included in the search routine
(see lecture notes and cs12ex).
Sample Form:
Additional Notes:
Consider coding the program incrementally.
1st: code load, assign, and display methods
2nd: code sort by id and swap values methods
3rd: code sort by name and search by name
Discount
Code Rate
A 0.03 Administrators
F 0.05 Faculty
S 0.10 Student
X 0.00 No Discount
Each data item is stored on separate lines so use ReadLine.
3030
Johnson
F
1010
Smith
S
4040
Lopez
A
6060
Sailor
X
2020
Davis
F
5050
Jones
S
Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//Project: CS12 Array Processing
//Programmer: Your Name
//Description: Load a list of Customer Ids, Names, and Discount Codes from a file.
// The list can hold up to 10 customers.
// Lookup the discount code in a array to get the discount Rate.
// Data is displayed in list boxes.
// The user can sort the list by Id or Name and search by name.
using System.IO; // FileStream and StreamReader
namespace CS12
{
public partial class CS12Form : Form
{
public CS12Form()
{
InitializeComponent();
}
//Declare class-level arrays
//Use cintNumberOfCustomers to process arrays because arrays
//may be partially loaded. Count set in LoadArrays.
int cintNumberOfCustomers;
//Declare constant arrays
//Size of array determined by the number of values provided.
//Note the values are enclosed in braces and not parenthesis.
private void btnLoadArrays_Click(object sender, EventArgs e)
{
}
void assignDiscountRate()
{
}
void displayArrays()
{
//This method is a look up routine.
//The items being compared must match exactly, so the comparison operator to use is ==
}
private void btnSortById_Click(object sender, EventArgs e)
{
}
void swapArrayValues(int i, int intMinSubscript)
{
}
private void btnSortByName_Click(object sender, EventArgs e)
{
}
private void btnSearchByName_Click(object sender, EventArgs e)
{
//Include Early Exit logic
//An early exit from a search can occur when we know that
//the value we are looking for will not be found in the array. To
//implement an early exit, the array most be sorted ascending.
//If we can determine that a value will not be found, we should
//not search the remainder of the array.
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}//end of class
}//end of namespace
Revised: 12/15/2008 - www.mc.maricopa.edu/~marquez/cis162ad/cs12_arrays.html