5
5
// Course# : CS115-1601A-01
6
6
// Course : Programming with C++
7
7
// Instructor : Instructor Charles Hale
8
- // Version : Week 5 - 5
9
- // Last updated: January 2025
8
+ // Version : Week 5 February 08, 2016
9
+ // Last updated: January 28, 2025
10
10
// Copyright : Educational Purposes
11
- // Description : C++, Ansi-style Successful Compile, Run, and updated application with objects, classes, functions, pointers
11
+ // Description : C++, Ansi-style Successful Compile, Run, and updated application with objects, classes, functions, pointers, input validation, error logging
12
12
// ============================================================================
13
13
14
14
#include < iostream>
@@ -40,20 +40,23 @@ class StoredCustomerData {
40
40
public:
41
41
42
42
void setCustomerFirstName () {
43
+ // Display the opening statement once
44
+ cout << " Welcome to Fix All Systems Inc." << endl;
45
+ cout << " *******************************" << endl;
46
+ cout << " Create your Customer Account for faster check-out and SAVINGS!!!" << endl;
47
+ cout << " *******************************" << endl;
48
+
43
49
while (true ) {
44
- cout << " Fix All Systems Inc." << endl;
45
- cout << " *******************************" << endl;
46
- cout << " Create your Customer Account for faster check-out and SAVINGS!!!" << endl;
47
- cout << " *******************************" << endl;
50
+ // Prompt for first name
48
51
cout << " Enter your First Name: " ;
49
52
cin >> customerFirstName;
50
53
51
54
// Validate input
52
55
if (validateInput (customerFirstName, " ^[A-Za-z]{1,50}$" )) {
53
- break ;
56
+ break ; // Exit the loop if input is valid
54
57
} else {
55
58
string errorMsg = " Invalid first name: " + customerFirstName;
56
- logError (errorMsg);
59
+ logError (errorMsg); // Log the error
57
60
cout << " Invalid input. Please try again." << endl;
58
61
}
59
62
}
@@ -66,7 +69,7 @@ class StoredCustomerData {
66
69
67
70
// Validate input
68
71
if (validateInput (customerLastName, " ^[A-Za-z]{1,50}$" )) {
69
- break ;
72
+ break ; // Exit the loop if input is valid
70
73
} else {
71
74
string errorMsg = " Invalid last name: " + customerLastName;
72
75
logError (errorMsg);
@@ -82,7 +85,7 @@ class StoredCustomerData {
82
85
83
86
// Validate input
84
87
if (validateInput (zipCode, " ^\\ d{5}$" )) {
85
- break ;
88
+ break ; // Exit the loop if input is valid
86
89
} else {
87
90
string errorMsg = " Invalid zip code: " + zipCode;
88
91
logError (errorMsg);
@@ -183,17 +186,34 @@ int main() {
183
186
cout << " Welcome to the Customer Information Program!" << endl;
184
187
cout << " Please enter the requested details below." << endl;
185
188
186
- StoredCustomerData customerData;
189
+ StoredCustomerData* customerData = new StoredCustomerData () ;
187
190
188
191
// Collect and validate user input
189
- customerData.setCustomerFirstName ();
190
- customerData.setCustomerLastName ();
191
- customerData.setZipCode ();
192
+ customerData->setCustomerFirstName ();
193
+ customerData->setCustomerLastName ();
194
+ customerData->setZipCode ();
195
+
196
+ // Display newly created customer account and use object
197
+ // to get values from private variables in the class.
198
+ // Accessing member class "StoredCustomerData" using the member access operator (->) to retrieve stored data in memory.
199
+ cout << " Your new Customer Account has been created:" << endl;
200
+
201
+ // Utilize the reference operator to display the memory address for the customer account number
202
+ cout << " Account Number: " << customerData << endl;
203
+
204
+ // Display the full customer information using getter methods
205
+ cout << " Welcome " << customerData->getCustomerFirstName () << " " << customerData->getCustomerLastName () << endl;
206
+ cout << " From ZIP Code: " << customerData->getZipCode () << endl;
207
+ cout << " *******************************" << endl;
208
+ cout << " *******************************" << endl;
192
209
193
210
// Create and display the service list
194
211
ServiceList services;
195
212
services.displayServiceList ();
196
213
214
+ // Free allocated memory
215
+ delete customerData;
216
+
197
217
return 0 ;
198
218
}
199
219
0 commit comments