Question

In: Computer Science

Create a program that will loop and prompt to enter the highlighted data items in the...

Create a program that will loop and prompt to enter the highlighted data items in the structure below. This is every item except customerNumber , isDeleted and newLine;


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;
};

Always set the item isDeleted to 'N' and newline to '\n'. The item newLine is a convenient item that is there to assist in viewing the contents of the file using "type filename" the cmd window.

Notepad will show the binary chars and will not line up the data as expected. You may see some odd characters after the expected data for the character arrays. That is normal for C/C++.

The item customerNumber should start at 0 and increase by 1 for every record written.


Once the data in the structure is loaded, write it to the file "Customers.dat" and prompt to continue. If the reply is to not continue, close the file and exit.

The file "Customers.dat" must be opened in Binary mode.

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.

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

#include <iostream> // header file for input output using cout, cin etc

#include <fstream> // header file for file handling

using namespace std;

const int NAME_SIZE = 20; // constant for size of name

const int STREET_SIZE = 30; // // constant for size of street address

const int CITY_SIZE = 20; // constant for size of city

const int STATE_CODE_SIZE = 3; // constant for size of statecode

// structure for customers will all the required fields

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()

{

        struct Customers c;

        long cus_num = 0;

        char choice;

        fstream f("customers.dat", ios::out | ios::binary | ios::app);

        do

        {
                cus_num++;

                c.customerNumber = cus_num;

                f << c.customerNumber << " "; // storing the Customer number in file

                cout << endl
                     << "Please enter your name:"; // asking user for name, storing in c.name structure

                cin >> c.name;

                f << c.name << " "; // storing name in file

                fflush(stdin);

                cout << endl
                     << "Please enter street address 1:"; // asking user for street address 1, storing in c.StreetAddress1 structure

                cin >> c.streetAddress_1;

                f << c.streetAddress_1 << " "; // storing street address 1 in file

                fflush(stdin); // to clear the input buffer

                cout << endl
                     << "Please enter street address 2:"; // asking user for street address 2, storing in c.StreetAddress2 structure

                cin >> c.streetAddress_2;

                f << c.streetAddress_2 << " "; // storing street address 2 in file

                fflush(stdin);

                cout << endl
                     << "Please enter city:"; // asking user for city, storing in c.City structure

                cin >> c.city;

                f << c.city << " "; // storing city in file

                fflush(stdin);

                cout << endl
                     << "Please enter state:"; // asking user for state, storing in c.State structure

                cin >> c.state;

                f << c.state << " "; // storing state in file

                fflush(stdin);

                cout << endl
                     << "Please enter zip code:"; // asking user for zip code, storing in c.ZipCode structure

                cin >> c.zipCode;

                f << c.zipCode << " "; // storing zipcode in file

                c.isDeleted = 'N'; // storing 'N' in c.isDeleted and storing it in file

                f << c.isDeleted << " ";

                c.newLine = '\n'; // storing '\n' in c.newLine and storing it in file

                f << c.newLine;

                cout << endl
                     << "Do you want to continue with more records [y/n] :"; // Asking user if he wants to continue

                cin >> choice;

        } while (choice == 'y' || choice == 'Y'); // loop again if user response is y or Y

        // come out of the loop if user response is n or N

        cout << endl
             << endl
             << "The data is successfully stored in the file customers.dat";

        // close the file object

        f.close();
}

Related Solutions

Create a program that will loop and prompt to enter the highlighted data items in the...
Create a program that will loop and prompt to enter the highlighted data items in the structure below. This is every item except customerNumber , isDeleted and newLine; 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; }; Always set the item isDeleted to 'N' and...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter payroll information Employee name and create variable for scanner Hours worked Hourly pay rate Federal tax rate State tax rate Declare variable doubles for gross pay, federal, state and total deduction Display payroll statement example: Name of employee Hours worked Hourly pay rate Gross pay which is equal hours worked multiply hourly pay rate Federal withholding which is equal of gross pay multiply federal...
Create a program that will prompt me for each of the following items: 1. Date of...
Create a program that will prompt me for each of the following items: 1. Date of Birth 2. Typical wake up time 3. Next Dentist Appointment. ( Date and Time) Create a Date structure and a method to load and return the date structure. Create a Time-of-day structure and a method to load and return the Time-of-day structure. Create a DateTime structure that includes the Date and Time-Of-Day structure. The Date structure should include year, month, day. The Time-of-day structure...
Create a C++ program which will prompt the user to enter a password continually until the...
Create a C++ program which will prompt the user to enter a password continually until the password passes the following tests. Password is 6 chars long Password has at least 1 number If the input does not match the tests, it will input a specific error message. "Pass must be 6 chars long." If the input is allowed, print a message saying "Correct Password Criteria."
Create a program that creates a sorted list from a data file. The program will prompt...
Create a program that creates a sorted list from a data file. The program will prompt the user for the name of the data file. Create a class object called group that contains a First Name, Last Name, and Age. Your main() function should declare an array of up to 20 group objects, and load each line from the input file into an object in the array. The group class should have the following private data elements: first name ,last...
c++ code: prompt user to enter a number then add loop that checks a list of...
c++ code: prompt user to enter a number then add loop that checks a list of numbers then display numbers that are higher or equal to the user's input.
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT