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.
There are logical and run time errors in the code, as well as compilation errors. **...
There are logical and run time errors in the code, as well as compilation errors. ** Your objective is get the code to run, fix any bugs in the code and ** place validation needed to prevent any memory issues. Each function has a ** description of what it does next to its prototype. ** When you find a problem, fix it in the code and note it in this header comment below. ** Please note each problem you find...
1.Write complete programs. These programs should be able to compile and run. No psuedocode is allowed....
1.Write complete programs. These programs should be able to compile and run. No psuedocode is allowed. No comments are needed. These programs will be graded for syntax, semantics, and programming style. Write a complete program to display the following output: Plan to be spontaneous tomorrow. 2. Write complete programs. These programs should be able to compile and run. No psuedocode is allowed. No comments are needed. These programs will be graded for syntax, semantics, and programming style. Write a complete...
q7.1 Fix the errors in the code (in C) //This program should read a string from...
q7.1 Fix the errors in the code (in C) //This program should read a string from the user and print it using a character pointer //The program is setup to use pointer offset notation to get each character of the string #include <stdio.h> #include <string.h> int main(void){ char s[1]; scanf(" %c", s); char *cPtr = s[1]; int i=0; while(1){ printf("%c", cPtr+i); i++; } printf("\n"); }
**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...
C++ : Find the syntax errors in the following program. For each syntax error, fix it...
C++ : Find the syntax errors in the following program. For each syntax error, fix it and add a comment at the end of the line explaining what the error was. #include <iostream> #include <cmath> using namespace std; int main(){ Double a, b, c; 2=b; cout<<"Enter length of hypotenuse"<<endl; cin>>c>>endl; cout>>"Enter length of a side"<<endl; cin>>a; double intermediate = pow(c, 2)-pow(a, 2); b = sqrt(intermediate); cout<<"Length of other side is:" b<<endline; return 0; }
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT