Use of pointers for final project.

I am getting a C2039 error when I build the project. Stating "setName" is not a member of std::basic_string<char,_traits<char<,std::allocator<char<<. I am supposed to use pointers for the "customer Name and Address". Then at the end I need to be able for the user to end the program with "Are you finished shopping Y/N?" then if they enter Y, the program ends (escape from loop my Prof keeps telling me)


#include <iostream>
#include <string>
#include <cstdlib>//General Utilities Library for general function purposes

#include "customer.h""

using namespace std;
using std::string;

//Void Function for Week 2
void greeting()
{
cout << "Welcome to Golf Ballz Inc! \n";
}

int main()
{
//declaring variables
string Name, Address;
char response;

string *pName, *pAddress;

Customer Client_1; //Customer Class implemented here

//greeting, name and address gathering
pName = &Name;
pAddress = &Address;

Client_1.setName(*pName);
Client_1.setAddress(*pAddress);

greeting();

cout << "Please enter your name: \n";

getline (cin, Name);

cout << "Welcome " << Client_1.getName() << "!" << endl << endl;

cout << "Pleae enter your shipping address: \n\n";

getline(cin, Address);


//verifying address

cout << "You entered your shipping address as: " << Client_1.getAddress() << endl << endl;





//list of products

cout << "Here is a list of available products we offer: \n";

cout << "Mens Golf Ballz \n Come in a variety of hardness and spin control options to rival the Pro's on tour! \n";

cout << "Womens Golf ballz \n Geared toward our beautiful golf girlz on the course! \n";

cout << "Kids Golf Ballz \n Offered in a variety of fun colors and designs! \n\n";

cout << " Each golfer can choose from a variety of colors and designs. \n\n";


cout << "Would you like to place an order? (Y/N)\n";
cin >> response;

//Week 4 I deleted my Week 2 use of Cases and Strings statements with the use of arrays I didn't need them. The array's replaced the function of each case.

string PRODUCT[3] = { "Men's Golf Ballz", "Women's Golf Ballz", "Kids Golf Ballz" };

int QUANT[3];

double PRICE[3] = { 23.00, 20.00, 15.00 };
//List of products and price in PRODUCT array
cout << "Product #1 - Men's Golf Ballz are $23.00/dozen" << endl;
cout << "Product #2 - Women's Golf Ballz are $20.00/dozen" << endl;
cout << "Product #3 - Kid's Golf Ballz are $15.00/dozen" << endl;

double total = 0;//inistialize total to zero
//for loop to allow customer to input amount of each product desired
for (int counter = 0; counter < 3; counter++)
{
cout << "Enter quantity for Product # " << counter + 1 << ": ";
cin >> QUANT[counter];// customer enters quantities under each product type

total += QUANT[counter] * PRICE[counter];//equation to give final total of all products
}
cout << "Your total bill is : $" << total << endl; //final statement that gives total bill due

}
cout << "Are you finished shopping? (Y/N)";
cin >> response;

system("PAUSE");

return 0;
}

Customer.h FILE

// Header = Function Declaration

#include <iostream>
#include <string>

using namespace std;


#ifndef CUSTOMER_H
#define CUSTOMER_H

class Customer {

public:
//Default Constructor
Customer();

//Overload Constructor
Customer(string);


private:
// Variables
string newName;
string newAddress;

Customer(string name, string address);

};

#endif
Last edited on
What's in customer.h?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Header = Function Declaration

#include <iostream>
#include <string>

using namespace std;
using std::string;

#ifndef CUSTOMER_H
#define CUSTOMER_H

class Customer {

public:
	//Default Constructor
	Customer();

	//Overload Constructor
	Customer(string);


private:
	// Variables
	string newName;
	string newAddress;

Customer(string name, string address);

};

#endif 
Last edited on
Hmm. In your main file you're doing things like Client_1.setName(name) and Client_1.getAddress(). However, Client_1 is an object of type Customer, and from your Customer.h file it looks like none of those methods are members of the Customer class.

The compiler error would suggest that you're doing something like name.setName(), which doesn't make sense because name is of type std::string, and strings don't know how to "setName".

I think you're more than 1 error away from completion.
customer.cpp
----------------
Line 5: Extraneous " on #include

Line 8: Although not an error, this using is unnecessary, since you've already brought in the entire std namespace on the previous line.

Line 30-31: You have no setName() or setAddress() functions in your class declaration. In addition, Name and Address are empty at this point.

Line 39: Customer has not getName() function.

Line 48: Customer has no getAddress() function,. In addition, you never stored the address into the Customer instance.

Line 67-68: What's the point of this question, since you don;t do anything with the answer?

Lines 84-90: While not a compilation error, you assume the customer will always order 3 items.

Line 93: Extraneous } This terminates main().

Lines 94-95: What's the point of this question? You don;t do anything with the response.

customer.h
----------
Line 6: Not a good idea for using namestd std; in a header file.

Line 7: No reason for this using as you've already brought in the entire std:: namespace on the previous line. Best practice is to qualify all string references with std:: in your header file rather than forcing in the entire std:: namespace.

Lines 9-10: These should be at the top of the file. No reason to read the iostream and string headers again if customer.h has already been included.

Line 20: No getters or setters declared.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.




Last edited on
Topic archived. No new replies allowed.