Question
Create a menu for the following tasks: 1. Add Customer Data 2. Show Existing Customer Data 3. Delete Customer Data 4. UnDelete Customer Data X.
Create a menu for the following tasks:
1. Add Customer Data
2. Show Existing Customer Data
3. Delete Customer Data 4. UnDelete Customer Data
X. Exit
Menu Item 1 should do the tasks originally done in Assignment 2.
Menu Item 2 should be a coded in a method showExistingCustomerData. It should read the "Customer.dat" file and display CustomerNumber, CustomerName and isDeleted.
Menu Item 3 should prompt for a Customer Number to delete. It should then read the Customer Data file and if a matching customer is found, it should changed the item isDeleted to Y and 'update' the file. If no customer number is found, it should display "Customer Number #### not found to delete.". ( ##### is the entered customer number). If the customer is already deleted, it should display "Customer is already deleted".
A note regarding 'updates'. You can rewrite the entire structure or use the file.seekp methods to do the updates.
Menu Item 4 should prompt for a Customer Number to un-delete. It should then read the Customer Data file and if a matching customer is found, it should changed the item isDeleted to N and 'update' the file. If no customer number is found, it should display "Customer Number #### not found to delete.". ( ##### is the entered customer number). If the customer is already not deleted, it should display "Customer is not already deleted"
Tips:This task may require you to change how the file is opened or optionally use additional file open and closes. Always confirm the file does not get deleted after a program restart.
"Customers.dat"
The program needs to create the Customers.dat file if it does not exist.
const int NAME_SIZE = 20; const int STREET_SIZE = 30; const int CITY_SIZE = 20; const int STATE_CODE_SIZE = 3;
struct Customers { long customerNumber; char name[NAME_SIZE]; char streetAddress_1[STREET_SIZE]; char streetAddress_2[STREET_SIZE]; char city[CITY_SIZE]; char state[STATE_CODE_SIZE]; int zipCode;
char isDeleted; char newLine; };
#include
#include
#include
using namespace std;
const int NAME_SIZE = 20;
const int STREET_SIZE = 30;
const int CITY_SIZE = 20;
const int STATE_CODE_SIZE = 3;
const string FILENAME = "Customers.dat";
struct Customers {
long customerNumber;
char name[NAME_SIZE];
char streetAddress_1[STREET_SIZE];
char streetAddress_2[STREET_SIZE];
char city[CITY_SIZE];
char state[STATE_CODE_SIZE];
int zipCode;
char isDeleted;
char newLine;
};
int main()
{
cout<<"1 > Add Customer Data " << endl;
cout<<"2 > Show Existing Customer Data" << endl;
cout<<"3 > Delete Customer Data" << endl;
cout<<"4 > UN-Delete Customer Data" << endl;
Customers customer;
char again;
fstream customersFile(FILENAME, ios::in | ios::binary);
if (customersFile.fail()) {
cout << FILENAME << " not found. Will build it." << endl;
}
customersFile.close();
customersFile.open(FILENAME, ios::app | ios::binary);
do {
customer.isDeleted = 'N';
customer.newLine = ' ';
cout << "Enter the following Customer Information for Customer Number " << custNumber << endl;
cout << "Customer Name: ";
cin.getline(customer.name, NAME_SIZE);
cout << "Street Address 1: ";
cin.getline(customer.streetAddress_1, STREET_SIZE);
cout << "Street Address 2: ";
cin.getline(customer.streetAddress_2, STREET_SIZE);
cout << "City: ";
cin.getline(customer.city, CITY_SIZE);
cout << "State: ";
cin.getline(customer.state, STATE_CODE_SIZE);
cout << "Zip Code: ";
cin >> customer.zipCode;
cin.ignore();
customersFile.write(reinterpret_cast
cout << "Enter another customer record ? :";
cin >> again;
cin.ignore();
custNumber++;
} while (toupper(again)== 'Y');
customersFile.close();
system("pause");
return 0;
}
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