C++ program #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; 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; }; void add_data(int no_of_records, ofstream& fout) { struct Customers c; cout << "Enter the Customer data:" << endl; cout << "Name:"; cin >> c.name; cout << "Street Address 1:"; cin >> c.streetAddress_1; cout << "Street Address 2:"; cin >> c.streetAddress_2; cout << "City:"; cin >> c.city; cout << "State:"; cin >> c.state; cout << "Zip Code:"; cin >> c.zipCode; cout << endl; c.customerNumber = no_of_records; c.isDeleted = 'N'; c.newLine = '\n'; cout << "Customer Details are:" << endl; cout << "\tCustomer Number:" << c.customerNumber << endl; cout << "\tName:" << c.name << endl; cout << "\tStreet Address 1:" << c.streetAddress_1 << endl; cout << "\tStreet Address 2:" << c.streetAddress_2 << endl; cout << "\tCity:" << c.city << endl; cout << "\tState:" << c.state << endl; cout << "\tZipCode:" << c.zipCode << endl; fout.write(reinterpret_cast(&c), sizeof(Customers)); } void display_menu(int no_of_records, ofstream& fout) { string choice; cout << "Choose the task:" << endl; cout << "1. Add Data" << endl; cout << "2. Update Data" << endl; cout << "3.Display Data" << endl; cout << "X. Exit Program" << endl; cin >> choice; if (choice == "1") { add_data(no_of_records, fout); no_of_records = no_of_records + 1; display_menu(no_of_records, fout); } elseif (choice == "X") { cout << "Done!" << endl; } else { cout << "Invalid Choice!!! Please try again." << endl; display_menu(no_of_records, fout); } } int main() { ofstream fout; fout.open("Customers.dat"); if (!fout) { cout << "Cannot open file!" << endl; return1; } fout.close(); fout.open("Customers.dat", ios::binary | ios::app); if (!fout) { cout << "Cannot open file to append!" << endl; return1; } int no_of_records = 0; display_menu(no_of_records, fout); fout.close(); ifstream inputFile; inputFile.open("Customers.dat", ios::binary); if (!inputFile) { cout << "Cannot open the file to read!" << endl; return1; } Customers c; cout << "Customer Details are:" << endl; while (inputFile.read((char*)&c, sizeof(Customers))) { cout << "\tCustomer Number:" << c.customerNumber << endl; cout << "\tName:" << c.name << endl; cout << "\tStreet Address 1:" << c.streetAddress_1 << endl; cout << "\tStreet Address 2:" << c.streetAddress_2 << endl; cout << "\tCity:" << c.city << endl; cout << "\tState:" << c.state << endl; cout << "\tZipCode:" << c.zipCode << endl; cout << endl; } return0; } 1. Modify this program to open the file "Customers.dat" so that all data is written to the end of the file AND to allow the file to be read. 2. Create a method called "getLargestCustomerNumber" and call it after the "Customers.dat" file has been opened. Read all the existing customerNumbers and determine the largest customerNumber - do not assume the last record in the file is the largest number. Use this number as the base when adding new customer data. 3. Display the customer number calculated for the customer number that is receiving input. 4. The program needs to create the Customers.dat file if it does not exist. 5. The program should be able to start multiple times and add data with increasing customerNumbers. There should be no duplicated customer numbers.
C++ program
1. Modify this program to open the file "Customers.dat" so that all data is written to the end of the file AND to allow the file to be read.
2. Create a method called "getLargestCustomerNumber" and call it after the "Customers.dat" file has been opened. Read all the existing customerNumbers and determine the largest customerNumber - do not assume the last record in the file is the largest number. Use this number as the base when adding new customer data.
3. Display the customer number calculated for the customer number that is receiving input.
4. The program needs to create the Customers.dat file if it does not exist.
5. The program should be able to start multiple times and add data with increasing customerNumbers. There should be no duplicated customer numbers.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images