Customer Data

I am a beginner when it comes to programming and I learn better visually when it comes to writing code. Once i see the code i can then figure out what it is doing and i develop a better understanding for it. I am working on a homework assignment and i am unsure as to what the problem is. Here is a breakdown of what it is i am supposed to do.

Customer Data. This program will have two classes. The first class defines a person, which means this class can be used for anything that involves a person. We will use it to define a Customer but it could be used to define a Student.

Create a class called PersonData and it will have its class declaration in PersonData.h and its implementation in PersonData.cpp. This class will have private data member’s lastName, firstName, address, city, state, zip and phone number as strings. Write the appropriate accessor and mutator functions for these member variables. It should have two constructors. One constructor is a default constructor that sets all of the data members to empty strings. A second constructor has parameters for all of its data members.

Create a class called CustomerData which will have its class declaration in CustomerData.h and its implementation in CustomerData.cpp. This class will be a derived class of PersonData. This class will have two private data members for the customer number (customerNumber) as an integer; the other will be called mailingList which is a bool to indicate if they want to be on the mailing list or not. Write appropriate accessor and mutator functions for these data members. This class will also have two constructors. It will have a default constructor that sets its data members to zero and false. The other constructor will have parameters to set all of the data members of the two classes.

Create a program that will create two instances of the CustomerData class. It must create one instance using the default constructor and then another using the second constructor. Once both instances are fully populated with data, call a function that will display the customer information.

void displayCustomer(CustomerData c)

The problem I am having is that it is not displaying the customer information.
I have included my code and i hope this is in the proper format for the forum. I apologize if this an inconvenience.

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
  #pragma once
#ifndef PersonData_H
#define PersonData_H

#include <string>
#include <iostream>
using namespace std;


class PersonData 
{
private:
	string lastName;
	string firstName;
	string address;
	string city;
	string state;
	string zipCode;
    string phoneNum;

public:
	PersonData();
	~PersonData();
	PersonData(string last, string first, string address, string city, string s, string zip, string phone);


	//Accessors
	void setlastName(string last);
	void setfirstName(string first);
	void setaddress(string add);
	void setcity(string c);
	void setstate(string s);
	void setzipCode(string zip);
	void setphoneNum(string phone);

	//Mutators

	string getlastName();
	string getfirstName();
	string getaddress();
	string getcity();
	string getstate();
	string getzipCode();
	string getphoneNum();

};
#endif // !PersonData_H;

#include "stdafx.h"
#include <string>
#include <iostream>
#include "PersonData.h"

using namespace std;


PersonData::PersonData()
{
	lastName = "";
	firstName = "";
	address = "";
	state = "";
	city = "";
	zipCode = "";
	phoneNum = "";

}


PersonData::~PersonData()
{
}

PersonData::PersonData(string last, string first, string add, string c, string s, string zip, string phone)
{
	lastName = last;
	firstName = first;
	address = add;
	city = c;
	state = s;
	zipCode = zip;
	phoneNum = phone;
}

void PersonData::setlastName(string last)
{
	lastName = last;
}

void PersonData::setfirstName(string first)
{
	firstName = first;
}

void PersonData::setaddress(string add)
{
	address = add;
}

void PersonData::setcity(string c)
{
	city = c;
}

void PersonData::setstate(string s)
{
	state = s;
}

void PersonData::setzipCode(string zip)
{
	zipCode = zip;
}

void PersonData::setphoneNum(string phone)
{
	phoneNum = phone;
}

string PersonData::getlastName()
{

	return lastName;
}

string PersonData::getfirstName()
{
	return firstName;
}

string PersonData::getaddress()
{
	return address;
}

string PersonData::getcity()
{
	return city;
}

string PersonData::getstate()
{
	return state;
}

string PersonData::getzipCode()
{
	return zipCode;
}

string PersonData::getphoneNum()
{
	return phoneNum;
}

#pragma once
#ifndef CustomerData_H
#define CustomerData_H

#include <iostream>
#include <string>
#include "PersonData.h"
#include <string>
#include <iostream>

using namespace std;

class CustomerData : public PersonData
{
private: 
	int customerNUM;
	bool mailingList;
public:
	CustomerData();
	CustomerData(string last, string first, string add, string c, string s, string zip, int custNUM, bool mail);
	

	//Accessors
	void setcustomerNUM(int custNUM);
	void setmailingList(bool mail);
	//Mutators
	int getcustomerNUM();
	bool getmailingList();
};
#endif // !CustomerData_H;

#include "stdafx.h"
#include "CustomerData.h"
#include "PersonData.h"

#include <iostream>
#include <string>

using namespace std;


CustomerData::CustomerData()
{
	customerNUM = 0;
	mailingList = false;
}


CustomerData::CustomerData(string last, string first, string add, string c, string s, string zip, int custNUM, bool mail)
{
	
	customerNUM = 0;
	mailingList = false;
}

void CustomerData::setcustomerNUM(int custNUM)
{
	customerNUM = custNUM;
}

void CustomerData::setmailingList(bool mail)
{
	mailingList = mail;
}

int CustomerData::getcustomerNUM()
{
	return customerNUM;
}

bool CustomerData::getmailingList()
{
	return mailingList;
}

#include "stdafx.h"
#include <iostream>
#include <string>
#include "CustomerData.h"

void displayCUSTOMER(CustomerData C); //function used to display the customer information from an instance of CustomerData



int main()
{
	CustomerData defaultCON; //object relates to the default constructor in CustomerData

							 //object uses the second constructor in Customer Data to populate the information fields. 
	CustomerData info("Smith", "Joan", "123 Main Street", "Smithville", "NC", "99999", 12345, true);

	cout << " Customer #1 \n";
	cout << " ____________ \n";
	displayCUSTOMER(defaultCON);
	cout << " Customer #2 \n";
	cout << " ____________ \n";
	displayCUSTOMER (info);

    return 0;
}

void displayCUSTOMER(CustomerData C)
{
	cout << " Last Name: " << C.getlastName() << endl; 
	cout << " First Name: " << C.getfirstName() << endl;
	cout << " Address: " << C.getaddress() << endl;
	cout << " State: " << C.getstate() << endl;
	cout << " City: " << C.getcity() << endl;
	cout << " Zip: " << C.getzipCode() << endl;
	cout << " Customer Number: " << C.getcustomerNUM() << endl;
	cout << " Mailing List? " << C.getmailingList() << endl;
}
closed account (SECMoG1T)
hey you need to initialize the inherited persondata object in the custormerdata constructors

1
2
3
4
5
6
7
8
9
10
11
12
13
CustomerData::CustomerData()
///:personData(),customerNUM( 0),mailingList(false) like this
{
	
}


CustomerData::CustomerData(string last, string first, string add, string c, string s, string zip, int custNUM, bool mail)
///:personData(last,first,add,c,s, zip, phone) , customerNUM(custNUM),mailingList(mail)
{
	
	
}


//my constructors are abit different from yours , prefer direct to copy
//initialization to minimize the work your constructors have to do. (advice)

Note: if you create an object with the default constructor you will need to use its mutators so to set it's data fields otherwise the will remain empty.

e.g
1
2
3
4
5
customerData cust;

cust.setsomedetails(detail);

cust.setotherdetails(others);
Last edited on
I thought i did initialize here in the following code:

CustomerData::CustomerData()
{
customerNUM = 0; //initialized customer number as zero
mailingList = false;//Intitialized Boolean as false
}


CustomerData::CustomerData(string last, string first, string add, string c, string s, string zip, int custNUM, bool mail)
{

customerNUM = 0;
mailingList = false;
}
Last edited on
closed account (SECMoG1T)
@EricT07 those initialization are for the class CustomerData data members, you have to keep in mind that the customerData class also inherits addational members from the class PersonData, those members too needs to be initialized and the only way to initialize them is by calling personaData constructors in the CustomerData constructors like in the example i provided earlier.
closed account (SECMoG1T)
try this
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  #pragma once
#ifndef PersonData_H
#define PersonData_H

#include <string>
#include <iostream>



class PersonData 
{
private:
	std::string lastName;
	std::string firstName;
	std::string address;
	std::string city;
	std::string state;
	std::string zipCode;
        std::string phoneNum;

public:
	PersonData();
	~PersonData();
	PersonData(std::string last, std::string first, std::string address, std::string city, std::string s, std::string zip, std::string phone);


	//Accessors
	void setlastName(std::string last);
	void setfirstName(std::string first);
	void setaddress(std::string add);
	void setcity(std::string c);
	void setstate(std::string s);
	void setzipCode(std::string zip);
	void setphoneNum(std::string phone);

	//Mutators

	std::string getlastName();
	std::string getfirstName();
	std::string getaddress();
	std::string getcity();
	std::string getstate();
	std::string getzipCode();
	std::string getphoneNum();

};
#endif // !PersonData_H;

#include "stdafx.h"
#include "PersonData.h"


PersonData::PersonData()
 :lastName(""),firstName(""), address(""), state(""),city(""), zipCode(""), phoneNumber("")
{

}


PersonData::~PersonData()
{
}

PersonData::PersonData(std::string last, std::string first, std::string add, std::string c, std::string s, std::string zip, std::string phone)
 :lastName(last), firstName(first), address(add), city( c), state( s),	zipCode (zip), phoneNum( phone)
{
	
}

void PersonData::setlastName(std::string last)
{
	lastName = last;
}

void PersonData::setfirstName(std::string first)
{
	firstName = first;
}

void PersonData::setaddress(std::string add)
{
	address = add;
}

void PersonData::setcity(std::string c)
{
	city = c;
}

void PersonData::setstate(std::string s)
{
	state = s;
}

void PersonData::setzipCode(std::string zip)
{
	zipCode = zip;
}

void PersonData::setphoneNum(std::string phone)
{
	phoneNum = phone;
}

std::string PersonData::getlastName()
{

	return lastName;
}

std::string PersonData::getfirstName()
{
	return firstName;
}

std::string PersonData::getaddress()
{
	return address;
}

std::string PersonData::getcity()
{
	return city;
}

std::string PersonData::getstate()
{
	return state;
}

std::string PersonData::getzipCode()
{
	return zipCode;
}

std::string PersonData::getphoneNum()
{
	return phoneNum;
}

#pragma once
#ifndef CustomerData_H
#define CustomerData_H


#include "PersonData.h"



class CustomerData : public PersonData
{
private: 
	int customerNUM;
	bool mailingList;
public:
	CustomerData();
	CustomerData(std::string last, std::string first, std::string add, std::string c, std::string s, std::string zip,std::string phone, int custNUM, bool mail);
	

	//Accessors
	void setcustomerNUM(int custNUM);
	void setmailingList(bool mail);
	//Mutators
	int getcustomerNUM();
	bool getmailingList();
};
#endif // !CustomerData_H;

#include "stdafx.h"
#include "CustomerData.h"
#include "PersonData.h"



CustomerData::CustomerData()
 : personData() , customerNUM ( 0),mailingList( false)
{
	
}


CustomerData::CustomerData(std::string last, std::string first, std::string add, std::string c, std::string s, std::string zip,std::string phone, int custNUM, bool mail)
 : personData(last,first,add,c,s,zip,phone), customerNUM(custNUM), mailingList(mail)
{

}

void CustomerData::setcustomerNUM(int custNUM)
{
	customerNUM = custNUM;
}

void CustomerData::setmailingList(bool mail)
{
	mailingList = mail;
}

int CustomerData::getcustomerNUM()
{
	return customerNUM;
}

bool CustomerData::getmailingList()
{
	return mailingList;
}

#include "stdafx.h"
#include "CustomerData.h"

void displayCUSTOMER(CustomerData C); //function used to display the customer information from an instance of CustomerData



int main()
{
	CustomerData defaultCON; //object relates to the default constructor in CustomerData

defaultCon.setlastName("adria");
defaultCon.setfirstName("McRey");
defaultCon.setaddress("0874784784");
defaultCon.setcity("L.A");
defaultCon.setstate("California");
defaultCon.setzipCode("00000");
defaultCon.setphoneNum("1234567");
defaultCon.setcustomerNUM(5555);
defaultCon.setmailingList(true);

							 //object uses the second constructor in Customer Data to populate the information fields. 
	CustomerData info("Smith", "Joan", "123 Main Street", "Smithville", "NC", "99999", 12345, true);

	std::cout << " Customer #1 \n";
	std::cout << " ____________ \n";
	displayCUSTOMER(defaultCON);
	std::cout << " Customer #2 \n";
	std::cout << " ____________ \n";
	displayCUSTOMER (info);

    return 0;
}

void displayCUSTOMER(CustomerData C)
{
	std::cout << " Last Name: " << C.getlastName() << std::endl; 
std::	cout << " First Name: " << C.getfirstName() << std::endl;
	std::cout << " Address: " << C.getaddress() << std::endl;
	std::cout << " State: " << C.getstate() << std::endl;
	std::cout << " City: " << C.getcity() << std::endl;
	std::cout << " Zip: " << C.getzipCode() << std::endl;
	std::cout << " Customer Number: " << C.getcustomerNUM() << std::endl;
	std::cout << " Mailing List? " << C.getmailingList() << std::endl;
}
i tried adding the code for personData to initialize the values, atleast that is the way i interpreted it. However it says the variables are undefined. These variables should pull from personData but they are not. I may be misinformed as well so please bare with me. I'm still learning. I appreciate the help

CustomerData::CustomerData()
: PersonData(last, first, add, c, s, zip, phone), customerNUM(customerNUM), mailingList(false);
{
customerNUM = 0;
mailingList = false;
}

Why is the code written like that? It doesn't seem right to me. How do i properly show the code on here?
However it says the variables are undefined.


It looks like there is some confusion over consistency with variables names and their associated functions. If the member variable is Phone, then I name the functions and their arguments after it directly:


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
private:

std:string Phone

// Paramters are const, we are not changing them inside the ctor
// I append Arg to the member variable name, it's not an argument - I find it easy to do - not that misleading, 
// one could append Param  or something similar, but be consistent
// pass std::string and any class type by reference
// I format like this - IMO it's easier to read

PersonData(const std::string& LastNameArg,
                      const std::string& FirstNameArg, 
                      const std::string& AddressArg, 
                      const std::string& CityArg, 
                      const std::string& StateArg, // changed s to State - that is what it actually is, don't over abbreviate
                      const  std::string& ZipArg, 
                      const std::string& PhoneArg)

// ....
// ....

PersonData::PersonData(const std::string& LastNameArg,
                      const std::string& FirstNameArg, 
                      const std::string& AddressArg, 
                      const std::string& CityArg, 
                      const std::string& StateArg, // changed s to state - that is what it actually is, don't over abbreviate
                      const  std::string& ZipArg, 
                      const std::string& PhoneArg)

                      : // colon introduces member initialisation list
                      // http://en.cppreference.com/w/cpp/language/initializer_list

                      // do these in the same order as in the class declaration 
                     LastName(LastNameArg),
                     FirstName(FirstNameArg),
                      Address(AddressArg),
                      City(CityArg),
                      State(StateArg),
                      Zip(ZipArg),
                      Phone(PhoneArg)
{
// do data validation here

}

// ....
// ....

// Name the get functions with "get" pre-pended to member variable name to remain consistent
// do a similar thing with set functions to be consistent

// Mark get functions const, we are not changing any values

	//Mutators

	std::string getLastName() const;
	std::string getFirstName() const;
	std::string getAddress() const;
	std::string getcity() const;
	std::string getState() const;
	std::string getZip() const;
	std::string getPhone() const;




Ideally, Name should be it's own class. Could have a std::vector of names as a member variable. Address should have it's own class as well.

Why is the code written like that?


It isn't - see the documentation for member initialization list.

How do i properly show the code on here?


You have, but read this to see how to do line numbers with code fragments - [code firstline=100 ] :

http://www.cplusplus.com/articles/z13hAqkS/

Topic archived. No new replies allowed.