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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++ program

#include<iostream>
#include<fstream>
#include<string>

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<char*>(&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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY