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,...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
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...
Please Provide the solution in java, already have a question which is answer in C++. Language:...
Please Provide the solution in java, already have a question which is answer in C++. Language: java. Please don't provide your email for private answer. Q1. Implement a program which allows the user to find the shortest path between two nodes in a graph possibly passing through a third node. I.e. the user should be able to ask questions like: Which is the shortest path from A to B passing through C? The program should output an ordered list of...
***PLEASE READ CAREFULLY. IF NOT ANSWERED IN FLOWGORITHM PLEASE DON'T ANSWER*** Can you please create a...
***PLEASE READ CAREFULLY. IF NOT ANSWERED IN FLOWGORITHM PLEASE DON'T ANSWER*** Can you please create a flowgorithm chart for the problem below. Also, provide pseudocode as well. Please do not answer if you cannot put into a flowgorithm chart. Pseudocode needed as well. Thank you! Design the logic for a program that outputs every number from 1 through 15 along with its value times 10 and times 100. Make the output look like below: Number is 1 Times 10 is...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT