Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. Modify this program to open the file "Customers.dat" so that all data can be read, and data written or appended to this file.

  2. 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. 1. Add Data 2. Update Data 3. Display all data X. Exit Program
  3. 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.

  4. The program should be able to start multiple times and add data with increasing customerNumbers. There should be no duplicated customer numbers.

  5. Menu Option 2 should do the following tasks

    1. Prompt for a customer number to change.

    2. Enter the address information ( Street 1 & 2, City , State and Zipcode)

    3. Find the record for the customer number and replace the address information.

  6. Menu Option 3 should do the following tasks

    1. Reset the file pointer to the beginning of the file.

    2. 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 #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 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(&info), sizeof(info)); info.customerNumber++;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

=+6 Who is the peer of the IA ?

Answered: 1 week ago

Question

How do carrots help you see in the dark?

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago