Question
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
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.
please let me know if you are able to assist
#include "pch.h"
#include
#include
using namespace std;
const int NAME_SIZE = 20, STREET_SIZE = 30, CITY_SIZE = 20, 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;
};
int main()
{
Customers information;
char again;
fstream customer;
customer.open("customer.dat", ios::out | ios::app);
do
{
long cus_num = 0;
information.customerNumber = cus_num;
customer << information.customerNumber << "";
cout << "customerNumber";
cin.getline(information.customerNumber);
cout << "Enter the following information about a customer: ";
cout << "Name: ";
cin.getline(information.name, NAME_SIZE);
cout << "Address line 1: ";
cin.getline(information.streetAddress_1, STREET_SIZE);
cout << "Address line 2: ";
cin.getline(information.streetAddress_2, STREET_SIZE);
cout << "City: ";
cin.getline(information.city, CITY_SIZE);
cout << "State: ";
cin.getline(information.state, STATE_CODE_SIZE);
cout << "Zip Code: ";
cin >> information.zipcode;
cin.ignore();
customer.write(reinterpret_cast(&information), sizeof(information));
cout << "Do you want to enter another record? ";
cin >> again;
cin.ignore();
} while (again == 'Y' || again == 'y');
cus_num++;
customer.close();
return 0;
}
It is the first line of the code pch.h
not sure what else you are wanting
#include "pch.h" #include #include using namespace std; const int NAME_SIZE = 20, STREET_SIZE = 30, CITY_SIZE = 20, 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; }; int main() { Customers information; char again; fstream customer; customer.open("customer.dat", ios::out | ios::app); do { long cus_num = 0; information.customerNumber = cus_num; customer << information.customerNumber << ""; cout << "customerNumber"; cin.getline(information.customerNumber); cout << "Enter the following information about a customer: "; cout << "Name: "; cin.getline(information.name, NAME_SIZE); cout << "Address line 1: "; cin.getline(information.streetAddress_1, STREET_SIZE); cout << "Address line 2: "; cin.getline(information.streetAddress_2, STREET_SIZE); cout << "City: "; cin.getline(information.city, CITY_SIZE); cout << "State: "; cin.getline(information.state, STATE_CODE_SIZE); cout << "Zip Code: "; cin >> information.zipcode; cin.ignore(); customer.write(reinterpret_cast(&information), sizeof(information)); cout << "Do you want to enter another record? "; cin >> again; cin.ignore(); } while (again == 'Y' || again == 'y'); cus_num++; customer.close(); return 0; } 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.
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