Answer to Question #256589 in C++ for sidra

Question #256589

Define a class Customer that holds private fields for a customer's ID, first name, last name, address and credit limit.

Define functions that set the fields of customer. For example setCustomerID().

Define functions that show the fields of customer. For example getCustomerID().

Use constructor to set the default values to each of the field.

Overload at least six constructor of the customer class.

Define a function that takes input from user and set the all fields of customer data.

Define a function that displays the entire customer’s data.


1
Expert's answer
2021-10-25T16:54:33-0400
#include <iostream>
using namespace std;

class Customer{
    private:
    
        int customerID;
        string firstname;
        string lastname;
        string address;
        int creditlimit;
        
    public:
        void setCustomerID(int id){
            customerID=id;
        }
        int getCustomerID(){
            return customerID;
        }
        
        Customer(){
            
        }
        
        Customer(string fn, string ln){
            firstname=fn;
            lastname=ln;
        }
        Customer(int id, int c){
            customerID=id;
            creditlimit=c;
        }
        Customer(int id){
            customerID=id;
        }
        Customer(int id, string fn, string ln){
            customerID=id;
            firstname=fn;
            lastname=ln;
        }
        Customer(int id, string addr){
            customerID=id;
            address=addr;
        }
        Customer(int id, string fn, string ln,string a,int c){
            customerID=id;
            firstname=fn;
            lastname=ln;
            address=a;
            creditlimit=c;
        }
        void getData(){
            cout<<"\nEnter customer ID: ";
            cin>>customerID;
            cout<<"\nEnter first name: ";
            cin>>firstname;
            cout<<"\nEnter last name: ";
            cin>>lastname;
            cout<<"\nEnter address: ";
            cin>>address;
            cout<<"\nEnter credit limit: ";
            cin>>creditlimit;
        }
        void display(){
            cout<<"\nCustomer ID: "<<customerID;
            cout<<"\nFirst name: "<<firstname;
            cout<<"\nLast name: "<<lastname;
            cout<<"\nAddress: "<<address;
            cout<<"\nCredit limit: "<<creditlimit;
        }
};


int main()
{
    Customer c;
    c.getData();
    c.display();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS