Question

In: Computer Science

C++ comments would be nice, especially with "Customers.dat" part. Please don't use an already answered solution...

C++

comments would be nice, especially with "Customers.dat" part.

Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasions.

I'll most certainly upvote if program is right. I always do

......

......

Statement: 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.
Deliverable is a working CPP program.

Solutions

Expert Solution

C++ program:

#include<iostream>
#include<fstream>
#include<string>
#include<ios>
#include<limits>
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;
};

int main(){
    
     //make a new object of Customers struct
     Customers c;
     c.customerNumber = 0;
    
    //opening the file in binary mode
    ofstream fp("Customers.dat", ios::out | ios::binary);
    if(!fp) {
        cout << "Cannot open file!" << endl;
        return 0;
    }

    //take user inputs continuously until user asks for exit
    while(1){

      


        //cin.getline is used to input a line with spaces .
        cout<<"\n\nName: ";
        cin.getline(c.name, NAME_SIZE);

        cout<<"\nStreet Address 1: ";
        cin.getline(c.streetAddress_1, STREET_SIZE);

        cout<<"\nStreet Address 2: ";
        cin.getline(c.streetAddress_2, STREET_SIZE);

        cout<<"\nCity: ";
        cin.getline(c.city, CITY_SIZE);

        cout<<"\nState: ";
        cin>>c.state;

        cout<<"\nZip Code: ";
        cin>>c.zipCode;

        //flush input stream
        cin.ignore(numeric_limits<streamsize>::max(),'\n');

        //setting values of isDeleted amd newLine
        c.isDeleted = 'N';
        c.newLine = '\n';
        
        //incrementing customer count
        c.customerNumber++;

        //write data to Customers.dat
        fp.write((char*)&c, sizeof(Customers));


        char op2;

        cout<<"\nDo you want to continue? (Y/N): ";

        cin>>op2;

        //flush input stream
        cin.ignore(numeric_limits<streamsize>::max(),'\n');

        //checking if user wants to exit the program
        if(op2 == 'N') {
            cout<<"Exiting the program....."<<endl;

            //closing the file
            fp.close();
            break;
        }

    }
    return 0;
}

Output:


Related Solutions

Good morning, Yes I did post part a Someone answered part (a) and (c) already. Here...
Good morning, Yes I did post part a Someone answered part (a) and (c) already. Here is the answered part (A). Can you complete part B please Thank you Here is part (A) again Comprehensive Problem 5 Part A: Note: You must complete part A before completing parts B and C. Genuine Spice Inc. began operations on January 1 of the current year. The company produces 8-ounce bottles of hand and body lotion called Eternal Beauty. The lotion is sold...
I HAVE ALREADY CORRECTLY COMPLETED PART A AND B PLEASE COMPLETE PART C ONLY Part A...
I HAVE ALREADY CORRECTLY COMPLETED PART A AND B PLEASE COMPLETE PART C ONLY Part A In late 2020, the Nicklaus Corporation was formed. The corporate charter authorizes the issuance of 6,000,000 shares of common stock carrying a $1 par value, and 2,000,000 shares of $5 par value, noncumulative, nonparticipating preferred stock. On January 2, 2021, 4,000,000 shares of the common stock are issued in exchange for cash at an average price of $10 per share. Also on January 2,...
PLEASE ANSWER C&D ONLY . THE REST HAS ALREADY BEEN ANSWERED. Say the marginal tax rate...
PLEASE ANSWER C&D ONLY . THE REST HAS ALREADY BEEN ANSWERED. Say the marginal tax rate is 20 percent and that government expenditures do not change with output. Say also that the economy is at potential output and that the deficit is $450 billion.     a. What is the size of the cyclical deficit? Answer = $0   b. What is the size of the structural deficit?    Answer = $450 billion.    c. How would your answers to a and...
I already answered the first three questions and put the answer down I just don't know...
I already answered the first three questions and put the answer down I just don't know how to answer the last question which asks to calculate K in the rate law? A clock reaction is run at 20 ºC with several different mixtures of iodide, sodium bromate and acid, to form iodine. Thiosulfate is used to react with the iodine formed initially. Starch indicator is added to form a blue color when all the thiosulfate has been used up and...
Can you explain and answer part e and part f please? I already understand parts c...
Can you explain and answer part e and part f please? I already understand parts c and d Firm 1 and Firm 2 are functioning in a market as competitors. The inverse market demand for chicken is given by P (Y ) = 100 − 2Y , and the total cost function for any firm in the industry if given by TC(y) = 4y. (c) Suppose that two Cournot firms operated in the market and the reaction firm for Firm...
using C , comments will be appreciated. I already posted this before and I am looking...
using C , comments will be appreciated. I already posted this before and I am looking for different answer. please answer both part of the question. A) Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating point number number1is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differingbit is encountered. The fact that...
Answer this fully please, type your answer, someone already answered it here but it was wrong,...
Answer this fully please, type your answer, someone already answered it here but it was wrong, only answer (((Quick ratio: ))))))and its not 1.2, 1.2 if you get any of these numbers dont reply to my question please PepsiCo, Inc. (PEP), the parent company of Frito-Lay snack foods and Pepsi beverages, had the following current assets and current liabilities at the end of two recent years: Current Year (in millions) Previous Year (in millions) Cash and cash equivalents $9,158 $9,096...
Please answer with a new answer not one that has already been answered on here before....
Please answer with a new answer not one that has already been answered on here before. Many supervisors are not well-trained on the difficult task of terminating an employee and instead resort to other methods of forcing someone out of the organization. Methods include giving the employee unpleasant work tasks, reducing their hours, or modifying their jobs in some negative way. What are the ethical issues raised by this strategy and what are the risks to the organization?
I've seen this question answered for C but I don't know how to translate to Java....
I've seen this question answered for C but I don't know how to translate to Java. Write a program that requests the hours worked in a week and the basic pay rate, and then prints the gross pay (before tax), the taxes, and the net pay (after tax). Assume the following: Basic pay rate: from user's choice Overtime (in excess of 40 hours) = time and a half (i.e., if the hours worked is 45, the hours for pay will...
There was a person who answered this before, please don't answer again. Your handwriting is illegable...
There was a person who answered this before, please don't answer again. Your handwriting is illegable and the topic is jobs in American, not India. To the next person answering this, please don't look up the answer on Chegg and give me the same answer the previous poster gave. THIS IS AN ESSAY QUESTION SO PLEASE ANSWER THOROUGHLY AND DESCRIBE WHY: From The Economic Way of Thinking Name three areas where US governments should concentrate as far as providing jobs.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT