Question
#include #include #include #include #include #include using namespace std; const int NAME_SIZE = 51; const int ADDR_SIZE = 51; const int CITY_SIZE = 20; const
#include
const int NAME_SIZE = 51; const int ADDR_SIZE = 51; const int CITY_SIZE = 20; const int STATE_SIZE = 15; const int ZIP_SIZE = 6; const int PHONE_SIZE = 14; const int PAYMENT_DATE_SIZE = 11; struct Customer { char name[NAME_SIZE]; char address[ADDR_SIZE]; char city[CITY_SIZE]; char state[STATE_SIZE]; char zip[ZIP_SIZE]; char phone[PHONE_SIZE]; double acct_balance; char payment_date[PAYMENT_DATE_SIZE]; }; void displayMenu(); int getMenuChoice(); int enterRecords(Customer); int searchName(Customer); int searchAndDisplay(Customer); int searchAndDelete(Customer); int searchAndChange(Customer); void showRecord(Customer); int displayContents(Customer);
int main() { int choice; char again = 'N'; Customer person; do { displayMenu(); choice = getMenuChoice(); switch(choice) { case 1: enterRecords(person); break; case 2: searchAndDisplay(person); break; case 3: searchAndDelete(person); break; case 4: searchAndChange(person); break; case 5: displayContents(person); break; case 6: cout > again; while (again != 'Y' && again != 'y' && again != 'N' && again != 'n') { cout > again; } cin.ignore(); } while (toupper(again) == 'Y'); cout
void displayMenu() { cout
int getMenuChoice() { int choice; cout > choice; cin.ignore(); while (choice 6) { cout > choice; } return choice; }
int enterRecords(Customer person) { char again; fstream records("records.dat", ios::out | ios::app | ios::binary); if (!records) { cout > person.acct_balance; cin.ignore(); cout (&person), sizeof(person)); cout > again; while (again != 'Y' && again != 'y' && again != 'N' && again != 'n') { cout > again; } cin.ignore(); } while (toupper(again) == 'Y'); records.close(); }
int searchName(Customer person) { char name[NAME_SIZE]; bool found = false; int pos = 0; fstream records; records.open("records.dat", ios::in | ios::binary); if (!records) { cout (&person), sizeof(person)); while (!records.eof()) { if (strcmp(person.name, name) == 0) { found = true; break; } // If name wasn't found in the first record, read the next record from the file. records.read(reinterpret_cast
} records.close(); if (found == true) . { cout
int searchAndDisplay(Customer person) { long recNum; cout (&person), sizeof(person)); showRecord(person); records.close(); }
int searchAndChange(Customer person) { long recNum; cout (&person), sizeof(person)); showRecord(person); cout > person.acct_balance; cin.ignore(); cout (&person), sizeof(person)); records.close(); }
int searchAndDelete(Customer person) { long recNum; int count = 0; cout (&person), sizeof(person)); while(!records.eof()) { if(deleteLocation != ((count) * sizeof(person))) { records.seekg((count) * sizeof(person), ios::beg); records.read(reinterpret_cast
void showRecord(Customer person) { cout
int displayContents(Customer person) { fstream records; records.open("records.dat", ios::in | ios::binary); if (!records) { cout (&person), sizeof(person)); while (!records.eof()) { showRecord(person); records.read(reinterpret_cast Above is the code that was posted by an expert in response to my question. When I run the code above, my program isn't functioning correctly. There are no errors in the error box, and I created the records and temp files (I changed them to .txt instead of .dat). But, when I run the code and enter a menu choice, the program aborts. I don't know what's wrong with it. (I had to change the format in order to post the question.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started