using namespace std;
//My main method
int main()
{
Customer cust;
cust.setCustomerNumber(1);
char name[NAME_SIZE];
char streetAddress_1[STREET_SIZE];
char streetAddress_2[STREET_SIZE];
char city[CITY_SIZE];
char state[STATE_CODE_SIZE];
int zipCode;
do {
cout < "input="" name:="">
cin.getline(name, NAME_SIZE);
} while (!cust.setName(name));
do {
cout < "input="" street="" address="" 1:="">
cin.getline(streetAddress_1, STREET_SIZE);
} while (!cust.setStreetAddress1(streetAddress_1));
do {
cout < "input="" street="" address="" 2:="">
cin.getline(streetAddress_2, STREET_SIZE);
} while (!cust.setStreetAddress2(streetAddress_2));
do {
cout < "input="" city:="">
cin.getline(city, CITY_SIZE);
} while (!cust.setCity(city));
do {
cout < "input="" state="" code:="">
cin.getline(state, STATE_CODE_SIZE);
} while (!cust.setState(state));
do {
cout < "input="" zip:="">
cin >> zipCode;
} while (!cust.setZipCode(zipCode));
// displaying all customer details
cout < endl="">< "details="" of="" customer:="" "=""><>
cout < "customer="" number:="" "="">< cust.getcustomernumber()=""><>
cout < "name:="" "="">< cust.getname()=""><>
cout < "street="" address="" 1:="" "="">< cust.getstreetaddress1()=""><>
cout < "street="" address="" 2:="" "="">< cust.getstreetaddress2()=""><>
cout < "city:="" "="">< cust.getcity()=""><>
cout < "state:="" "="">< cust.getstate()=""><>
cout < "zip="" code:="" "="">< cust.getzipcode()=""><>
return 0;
}
//Declaring My Function NAME_SIZE/STREER_SIZE/CITY_SIZE/STATE_CODE_SIZE
const int NAME_SIZE = 20;
const int STREET_SIZE = 30;
const int CITY_SIZE = 20;
const int STATE_CODE_SIZE = 3;
//Customer Details
class Customer
{
private:
long customerNumber;
char name[NAME_SIZE];
char streetAddress_1[STREET_SIZE];
char streetAddress_2[STREET_SIZE];
char city[CITY_SIZE];
char state[STATE_CODE_SIZE];
int zipCode;
//Public Class as Assingment required
public:
void setCustomerNumber(long cn);
bool setName(char n[]);
bool setStreetAddress1(char sa[]);
bool setStreetAddress2(char sa[]);
bool setCity(char c[]);
bool setState(char s[]);
bool setZipCode(int z);
long getCustomerNumber();
char* getName();
char* getStreetAddress1();
char* getStreetAddress2();
char* getCity();
char* getState();
int getZipCode();
};
// setters
void Customer::setCustomerNumber(long cn)
{
customerNumber = cn;
}
bool Customer::setName(char n[])
{
//Confirmed NAME is not an empty string
//using Strcpy to copy one string to another
if (strlen(n) > 0)
{
strcpy(name, n);
return true;
}
return false;
}
bool Customer::setStreetAddress1(char sa[])
{
// Confirmed StreetAddress1 is not an empty string
if (strlen(sa) > 0)
{
strcpy(streetAddress_1, sa);
return true;
}
return false;
}
bool Customer::setStreetAddress2(char sa[])
{
// Confirmed StreetAddress2 is not an empty string
if (strlen(sa) > 0)
{
strcpy(streetAddress_2, sa);
return true;
}
return false;
}
bool Customer::setCity(char c[])
{
// Confirmed city is not an empty string
if (strlen(c) > 0)
{
strcpy(city, c);
//all characters of city are letters
for (int i = 0; i < strlen(city);="">
{
city[i] = toupper(city[i]);
if (city[i] < 'a'="" ||="" city[i]=""> 'Z')
return false;
}
return true;
}
return false;
}
bool Customer::setState(char s[])
{
// Confirmed state is not an empty string
if (strlen(s) > 0)
{
strcpy(state, s);
// Confirmed all characters of state are letters
for (int i = 0; i < strlen(state);="">
{
state[i] = toupper(state[i]);
if (state[i] < 'a'="" ||="" state[i]=""> 'Z')
return false;
}
return true;
}
return false;
}
bool Customer::setZipCode(int z)
{
// Confirmed zipCode is between [0,99999]
if (z >= 0 && z <=>=>
{
zipCode = z;
return true;
}
return false;
}
//Printing all the outputs
long Customer::getCustomerNumber()
{
return customerNumber;
}
char* Customer::getName()
{
return name;
}
char* Customer::getStreetAddress1()
{
return streetAddress_1;
}
char* Customer::getStreetAddress2()
{
return streetAddress_2;
}
char* Customer::getCity()
{
return city;
}
char* Customer::getState()
{
return state;
}
int Customer::getZipCode()
{
return zipCode;
}