Question
Copy Assignment 1 to Assignment 2. Relabel this assignment to be Assignment 2. If there were comments made regarding the grading of Assignment 1, apply
Copy Assignment 1 to Assignment 2. Relabel this assignment to be Assignment 2. If there were comments made regarding the grading of Assignment 1, apply those changes to assignment 2.
-
Modify this program to open the file "Customers.dat" so that all data can be read, and data written or appended to this file.
-
Add an option 2 and 3 to the menu so that the menu appears as below:Menu options '2' and '3' should now be considered a valid choice.
- 1. Add Data 2. Update Data 3. Display all data X. Exit Program
-
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. Use this number as the base when adding new customer data.
-
The program should be able to start multiple times and add data with increasing customerNumbers. There should be no duplicated customer numbers.
-
Menu Option 2 should do the following tasks
-
Prompt for a customer number to change.
-
Enter the address information ( Street 1 & 2, City , State and Zipcode)
-
Find the record for the customer number and replace the address information.
-
-
Menu Option 3 should do the following tasks
-
Reset the file pointer to the beginning of the file.
-
For each record in the file, display the customer number, customer name and all address information. The items isDeleted and newLine are not to be displayed.
-
Here is my code. I'm not sure how to do these new questions correctly.
#include
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 info; fstream dataFile; char again = -1; char choice; info.customerNumber = 0; info.isDeleted = 'N'; info.newLine = ' ';
dataFile.open("Customers.dat", ios::out | ios::binary);
do { cout << "MENU "; cout << "---- "; cout << "1. Add Data "; cout << "X. Exit Program "; cout << "Enter a choice: "; cin >> choice; cin.ignore();
switch (choice) { case '1':
cout << "Name: "; cin.getline(info.name, NAME_SIZE); cout << "Address 1: "; cin.getline(info.streetAddress_1, STREET_SIZE); cout << "Address 2: "; cin.getline(info.streetAddress_2, STREET_SIZE); cout << "City: "; cin.getline(info.city, CITY_SIZE); cout << "State: "; cin.getline(info.state, STATE_CODE_SIZE); cout << "Zip Code: "; cin >> info.zipCode;
dataFile.write(reinterpret_cast
cout << "Would you like to enter another record? (Y or N): "; cin >> again; cin.ignore(); break;
case 'x': case 'X': dataFile.close(); cout << "Done!"; return 0;
default: cout << "Invalid option! Don't know how to restart this code without it messing up my again input. "; cout << "When I add 'choice != ' to the while statement along with the 'again' it messes up the loop. "; return 0; } } while ((again == 'y') || (again == 'Y'));
dataFile.close(); cout << "Data has been loaded to file!";
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