Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include #include using namespace std; //declaration of class class Customer { /

ID: 3785994 • Letter: #

Question

#include #include using namespace std; //declaration of class class Customer { // members are private by default string c_name; string c_address; // you explicitly declare the public section public: Customer(); void setName(string n); void setAddress(string a); string getName(); string getAddress(); }; Customer:: Customer() { // constructor c_name = NULL; c_address = NULL; } void Customer::setName(string n) { c_name = n; } void Customer::setAddress(string a) { c_address = a; } string Customer::getName( ) { return c_name; } string Customer::getAddress( ) { return c_address; } //declaration of structure struct Product { string p_name; double price; float quantity; }; int main() { Customer c1; int p,order = 0; string c_name, c_address; cout << "Please enter number of products" <> p; Product *products = new Product[p]; //stucture array for(int i=0; i> products[i].p_name; cout << "Please enter product price" <> products[i].price; cout << "Please enter product quantity" <> products[i].quantity; order += (products[i].price * products[i].quantity) ; } cout << "Please enter customer's name " << endl; cin >> c_name; c1.setName(c_name); cout << "Please enter customer's address " << endl; cin >> c_address; c1.setAddress(c_address); cout << "Name: " << c1.getName(); cout << "Address: " << c1.getAddress(); cout <<"Total Order Value: "<< order << endl; // Display the result return 0; } can some one help me with this code. this line is not working Customer:: Customer() { // constructor c_name = NULL; c_address = NULL; }

Explanation / Answer

When object is created, by default constructor is called.In constructor you initialised c_name and c_address as NULL.

But in main(),again you declared c_name,c_address because of this you are getting error.

if you don't want to get this error and want to use those variables, use object reference as

c1.c_name

c1.c_address in main()