#include using namespace std; /* Name: Cameron Alston Section: CISP 400 - Fall 2007 - Wei Title: Customer Records SCR: 9/26/07 Intial design and coding. Alston 9/27/07 Finished coding, documented. Alston */ // Enumerated definitions. #define LINE 80+1 #define CHAR12 16+1 #define STATE 2+1 #define MAXRECS 20 // Customer information array-structure definitions. typedef struct { char name[LINE], address[LINE], city[CHAR12], state[STATE], phoneNum[CHAR12], payDate[CHAR12]; int zip; float balance; } CustomerData; typedef CustomerData Accounts[MAXRECS]; // Functions. int EnterData(Accounts database, int count, int &choice); void ChangeName(char newName[]); void ChangeAddress(char newAddress[]); void ChangeCity(char newCity[]); void ChangeState(char newState[]); void ChangeZip(int &zip); void ChangePhone(char newPhone[]); void ChangeBalance(float &newBalance); void ChangePayDate(char newPayDate[]); int main() { Accounts database; int count = 0, numRecs, accountSelect, memberSelect, choice, pause = 0; cout << "This is a program for entering and changing account data.\n\n\nWould you like to enter a record?" << endl << endl; cout << "1. Yes" << endl << "2. No" << endl << endl << "Choice: "; cin >> choice; while(choice != 1 && choice != 2) { cout << "Please enter 1 or 2..." << endl; cin >> choice; } fflush(stdin); while(choice == 1) { choice = EnterData(database, count, choice); count++; } numRecs = count; cout << endl << endl << "Would you like to change any of the data that was entered?" << endl << endl; cout << "1. Yes" << endl << "2. No" << endl << endl << "Choice: "; cin >> choice; while(choice != 1 && choice != 2) { cout << "Please enter 1 or 2..." << endl; cin >> choice; } fflush(stdin); while(choice == 1) { cout << endl << endl << "Which account would you like to change? (1-" << numRecs << ")" << endl << endl << "Choice: "; cin >> accountSelect; cout << endl << endl << "Which element would you like to change?" << endl; cout << "1. Name\n2. Address\n3. City\n4. State\n5. ZIP\n6. Phone Number\n7. Account Balance\n8. Date of Last Payment" << endl << endl << "Choice: "; cin >> memberSelect; while(memberSelect < 1 || memberSelect > 8) { cout << "Please enter a value from within the range 1 to 8..."; cin >> memberSelect; } fflush(stdin); switch(memberSelect) { case 1: ChangeName(database[accountSelect - 1].name); break; case 2: ChangeAddress(database[accountSelect - 1].address); break; case 3: ChangeCity(database[accountSelect - 1].city); break; case 4: ChangeState(database[accountSelect - 1].state); break; case 5: ChangeZip(database[accountSelect - 1].zip); break; case 6: ChangePhone(database[accountSelect - 1].phoneNum); break; case 7: ChangeBalance(database[accountSelect - 1].balance); break; case 8: ChangePayDate(database[accountSelect - 1].payDate); default: break; } cout << endl << endl <<"Would you like to change more data?" << endl << endl; cout << "1. Yes" << endl << "2. No" << endl << endl << "Choice: "; cin >> choice; while(choice != 1 && choice != 2) { cout << "Please enter 1 or 2..." << endl; cin >> choice; } fflush(stdin); } cout << endl << endl << "Would you like to see the records?" << endl << endl; cout << "1. Yes" << endl << "2. No" << endl << endl << "Choice: "; cin >> choice; while(choice != 1 && choice != 2) { cout << "Please enter 1 or 2..." << endl; cin >> choice; } fflush(stdin); if(choice == 1) { for(count = 0; count < numRecs; count++) { cout << endl << endl; cout << "Account Number: " << count + 1 << endl; cout << "Customer Name: " << database[count].name << endl; cout << "Street Address: " << database[count].address << endl; cout << "City: " << database[count].city << ", " << database[count].state << ", " << database[count].zip << endl; cout << "Home Phone: " << database[count].phoneNum << endl; cout << "Account Balance: " << database[count].balance << endl; cout << "Date of Last Payment: " << database[count].payDate; } } cout << endl; cin >> pause; return 0; } int EnterData(Accounts database, int count, int &choice) { cout << endl << endl; cout << "Name: "; cin.getline(database[count].name, LINE); cout << endl; cout << "Address: "; cin.getline(database[count].address, LINE); cout << endl; cout << "City: "; cin.getline(database[count].city, CHAR12); cout << endl; cout << "State: "; cin.getline(database[count].state, STATE); cout << endl; cout << "ZIP: "; cin >> database[count].zip; cout << endl; fflush(stdin); cout << "Phone: "; cin.getline(database[count].phoneNum, CHAR12); cout << endl; cout << "Balance: "; cin >> database[count].balance; cout << endl; fflush(stdin); cout << "Last Payment Date: "; cin.getline(database[count].payDate, CHAR12); cout << endl << endl; cout << "Would you like to enter another record?" << endl << endl; cout << "1. Yes" << endl << "2. No" << endl << endl << "Choice: "; cin >> choice; while(choice != 1 && choice != 2) { cout << "Please enter 1 or 2..." << endl; cin >> choice; } fflush(stdin); return choice; } void ChangeName(char newName[]) { cout << endl << endl; cout << "Please enter the new name: "; cin.getline(newName, LINE); } void ChangeBalance(float &newBalance) { cout << endl << endl; cout << "Please enter the new balance: "; cin >> newBalance; fflush(stdin); } void ChangeAddress(char newAddress[]) { cout << endl << endl; cout << "Please enter the new address: "; cin.getline(newAddress, LINE); } void ChangeCity(char newCity[]) { cout << endl << endl; cout << "Please enter the new city: "; cin.getline(newCity, LINE); } void ChangeState(char newState[]) { cout << endl << endl; cout << "Please enter the new state: "; cin.getline(newState, LINE); } void ChangeZip(int &newZip) { cout << endl << endl; cout << "Please enter the new ZIP: "; cin >> newZip; fflush(stdin); } void ChangePhone(char newPhone[]) { cout << endl << endl; cout << "Please enter the new phone number: "; cin.getline(newPhone, LINE); } void ChangePayDate(char newPayDate[]) { cout << endl << endl; cout << "Please enter the new last date of payment: "; cin.getline(newPayDate, LINE); }