In: Computer Science
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; }
/* 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 */