Question

In: Computer Science

find all the errors c++ should be able to be compiled and run to perform the...

find all the errors c++

should be able to be compiled and run to perform the task

#include iostream
#include <string>
Using namespace std;

class Customer {
    // Constructor
    void Customer(string name, string address) : cust_name(name), cust_address(address)
    {
         acct_number = this.getNextAcctNumber();
    }

    // Accessor to get the account number
    const int getAcctNumber() { return acct_number; }

    // Accessor to get the customer name
    string getCustName(} const { return cust_name; }

    // Accessor to get the customer  address
    string getCustAddress() const { return cust_address; }

    // Set a customer name and address
    static void set(string name, string address);

    // Set a customer address
    void setAddress(string cust_address) {  cust_address = cust_address; }

    // Get the next account number for the next customer.
    static const unsigned long getNextAcctNumber() { ++nextAcctNum; }

    // input operator
    friend Customer operator>> (istream& ins, Customer cust);

    // output operator
    friend void operator<< (const ostream& outs, const Customer &cust) const;

  private
    string cust_name;                           // customer name

    unsigned long acct_number;                  // account number

    string cust_address;                        // customer address

    static const unsigned long nextAcctNum;
};

const int MAX_CUSTOMERS=20; // Change this to a smaller number to test.

// Declare the class variable nextAcctNum
unsigned long Customer::nextAcctNum=10000;

// set the customer name and address
// @param name: the customer name
// @param address: the account address
void Customer::set(string name, string address) : cust_name(name), cust_address(address)
{
}

// input operator reads customer as a name and address on two separate lines.
// name
// address1
friend Customer Customer::operator>>(istream& ins, Customer cust)
{
    getline(cin, cust.cust_name);
    getline(cin, cust.cust_address);
    return *this;
}

// output operator
friend void Customer::operator<<(const ostream& out, const Customer& cust) const
{
    out << acct_number << “: “ << cust_name << “\n“ << cust_address << endl;
}

int main()
{
    Customer custList[MAX_CUSTOMERS];

    cout << “Enter the customer list one per line\n”;
    // Read in customer list.
    for (int i = 0; i < MAX_CUSTOMERS; i++)
    {
       cin >> custList[i];
    }

    // Get customer address changes
    for (int i = 0;  i < MAX_CUSTOMERS; i++)
    {   
       int answer;
       cout << “Address change for  “ << custList.acct_number[i] << “? (y or n) : “;
       cin >> answer;
       if (answer == ‘y’) {
          cin >> input;
          custList.setAddress[i] = input;
       }
    }
‘
    // Write out customer list.
    for (int i = 0; I < MAX_CUSTOMERS; i++)
    {
        cout << custList[i];
    }

    return 0;
}

Solutions

Expert Solution

/* I HAVE CHANGE MAXCUSTOMERS TO 2 YOU CAN CHANGE TO BIGGER */

#include <iostream>
#include <string>

using namespace std;

class Customer {
   public:
   Customer(){
       this->acct_number = this->getNextAcctNumber();
   }
// Constructor
Customer(string name, string address) : cust_name(name), cust_address(address)
{
this->acct_number = this->getNextAcctNumber();
}

// Accessor to get the account number
const int getAcctNumber() { return acct_number; }

// Accessor to get the customer name
string getCustName() const { return cust_name; }

// Accessor to get the customer address
string getCustAddress() const { return cust_address; }

// Set a customer name and address
void set(string name, string address);

// Set a customer address
void setAddress(string cust_address) { this->cust_address = cust_address; }

// Get the next account number for the next customer.
static unsigned long getNextAcctNumber() { ++nextAcctNum; }

// input operator
friend istream & operator >>(istream& ins, Customer &cust);

// output operator
friend ostream & operator << (ostream& outs, const Customer &cust) ;
  
private:
string cust_name; // customer name
   unsigned long acct_number; // account number
  

string cust_address; // customer address

static unsigned long nextAcctNum;
};

const int MAX_CUSTOMERS=2; // Change this to a smaller number to test.

// Declare the class variable nextAcctNum
unsigned long Customer::nextAcctNum=10000;

// set the customer name and address
// @param name: the customer name
// @param address: the account address
void Customer:: set(string name, string address)
{
   this->cust_name = name;
   this->cust_address = address;
}

// input operator reads customer as a name and address on two separate lines.
// name
// address1
istream & operator >>(istream& ins, Customer &cust)
{
   cout<<"Enter Customer name: ";
getline(ins, cust.cust_name);
cout<<"Enter Customer address: ";
   getline(ins, cust.cust_address);
   cust.set(cust.cust_name,cust.cust_address);
return ins;
}

// output operator
ostream & operator <<( ostream& out, const Customer& cust)
{
out <<"Account Number: "<<cust.acct_number << ": " <<"Name : "<< cust.cust_name << "\n" <<"Address :"<< cust.cust_address << endl;
   return out;
}

int main()
{
Customer custList[MAX_CUSTOMERS];
   string input;
cout << "Enter the customer list one per line\n";
// Read in customer list.
for (int i = 0; i < MAX_CUSTOMERS; i++)
{
cin >> custList[i];
}

// Get customer address changes
for (int i = 0; i < MAX_CUSTOMERS; i++)
{   
char answer;
cout << "Address change for " << custList[i].getCustName() << "? (y or n) : ";
cin >> answer;
if (answer == 'y') {
cout<<"Enter Address: ";
       cin >> input;
custList[i].setAddress(input) ;
}
}

// Write out customer list.
for (int i = 0; i < MAX_CUSTOMERS; i++)
{
cout << custList[i];
}

return 0;
}

/* OUPUT */

/* PLEASE UPVOTE */


Related Solutions

**NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WITH NO ERRORS** **TO CREATE...
**NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WITH NO ERRORS** **TO CREATE THIS JAVA PROGRAM USE ECLIPSE NEON** The assignment is as follows: Connect four is a two-player board game in which the players alternately drop colored disks into a seven-column, six-row vertically-suspended grid. The objective of the game is to connect four same-colored disks in a row, a column, or a diagonal before your opponent can do likewise. The program prompts a player to drop...
“One should not expect auditors to find all flaws and errors in an accounting system.” Post...
“One should not expect auditors to find all flaws and errors in an accounting system.” Post your response giving reasoned arguments as to why you agree or disagree.
One should not expect auditors to find all flaws and errors in an accounting system.” Post...
One should not expect auditors to find all flaws and errors in an accounting system.” Post your response giving reasoned arguments as to why you agree or disagree.
**Review the following passages for sentence fragments, comma splices, and run on sentences. **Correct all errors...
**Review the following passages for sentence fragments, comma splices, and run on sentences. **Correct all errors where necessary, and bold each correction. • “It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the...
Review the following passages for sentence fragments, comma splices, and run on sentences. Correct all errors...
Review the following passages for sentence fragments, comma splices, and run on sentences. Correct all errors where necessary, and bold each correction. • “It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the...
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
In all health science professions you will find it is critical to be able to work...
In all health science professions you will find it is critical to be able to work with teams. Think about how teams will be used in the careers you are considering. Then also discuss what skills you think are important in order to be a leader and a member of a team in the BSHS program.
Write a MATLAB code for importing an image and then being able to find all the...
Write a MATLAB code for importing an image and then being able to find all the coordinates that would draw that image on a plot column by column and row by row with a continuous line.
Need C++ code to be able to run, keep getting a constant value error #include #include...
Need C++ code to be able to run, keep getting a constant value error #include #include #include #include #include #include using namespace std; using namespace std::chrono; int c; void insertionSort(int* arr, int n) { for (int i = 1;i < n;i++) { int v = arr[i]; int j; for (j = i - 1;j > -1;j--) { c++; if (arr[j] > v) { arr[j + 1] = arr[j]; } else { break; } } arr[j + 1] = v; }...
Please answer all a,b,c,d!!! Assume calendar year-ends for all companies and that all errors are material....
Please answer all a,b,c,d!!! Assume calendar year-ends for all companies and that all errors are material. a. Quigley Down Under Co. bought a machine on January 1, 2017 for $1,400,000. The machine had an estimated residual value of $120,000 and a ten-year life. “Machine expense” was debited on the purchase date for $1,400,000. Quigley uses straight-line depreciation for all assets. The error was discovered on June 15, 2018 after the books had been closed for 2017. What journal entry (if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT