Question

In: Computer Science

Refactor Assignment 1 into 3 project related files. Customer.h - Class Specification Customer.cpp - Class Implementation...

Refactor Assignment 1 into 3 project related files.

Customer.h            - Class Specification
Customer.cpp         - Class Implementation (Methods)

TestCustomer.cpp - Your code that performs the logic from Assignment 1.

The 3 files need to be named as listed above and should compile without errors.

I am not understanding how to do this.

Below is the code:

#include
#include

using namespace std;

const int NAME_SIZE = 20;
const int STREET_SIZE = 30;
const int CITY_SIZE = 20;
const int STATE_CODE_SIZE = 3;

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:
   void setNumber(long number);

   bool setName(char name[]);
   bool setStreetAddress1(char street1[]);
   bool setStreetAddress2(char street2[]);
   bool setCity(char c[]);
   bool setState(char st[]);
   bool setZipCode(int zip);

   long getNumber();

   char* getName();
   char* getStreetAddress1();
   char* getStreetAddress2();
   char* getCity();
   char* getState();

   int getZipCode();
};


void Customer::setNumber(long number)
{
   customerNumber = number;
}

bool Customer::setName(char n[])
{
  
   if (strlen(n) > 0)
   {
       strcpy(name, n);
       return true;
   }

   return false;
}

bool Customer::setStreetAddress1(char street1[])
{

   if (strlen(street1) > 0)
   {
       strcpy(streetAddress_1, street1);
       return true;
   }

   return false;
}

bool Customer::setStreetAddress2(char street2[])
{
   if (strlen(street2) > 0)
   {
       strcpy(streetAddress_2, street2);
       return true;
   }

   return false;
}


bool Customer::setState(char st[])
{
  
   if (strlen(st) > 0)
   {
       strcpy(state, st);
      
       for (int i = 0; i < strlen(state); i++)
       {
           state[i] = toupper(state[i]);
           if (state[i] < 'A' || state[i] > 'Z')
               return false;
       }

       return true;
   }

   return false;
}

bool Customer::setCity(char c[])
{

   if (strlen(c) > 0)
   {
       strcpy(city, c);

       for (int i = 0; i < strlen(city); i++)
       {          
           city[i] = toupper(city[i]);
           if (city[i] < 'A' || city[i] > 'Z')
               return false;
       }

       return true;
   }

   return false;

}

bool Customer::setZipCode(int zip)
{

   if (zip >= 0 && zip <= 99999)
   {
       zipCode = zip;
       return true;
   }

   return false;
}


long Customer::getNumber()
{
   return customerNumber;
}

char* Customer::getName()
{
   return name;
}

char* Customer::getStreetAddress1()
{
   return streetAddress_1;
}

char* Customer::getStreetAddress2()
{
   return streetAddress_2;
}

char* Customer::getState()
{
   return state;
}

char* Customer::getCity()
{
   return city;
}

int Customer::getZipCode()
{
   return zipCode;
}

int main()
{
   Customer info;
  

   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;

   info.setNumber(1);

   do
   {
       cout << "What is your name: ";
       cin.getline(name, NAME_SIZE);
   } while (!info.setName(name));


   do
   {
       cout << "Street you live on: ";
       cin.getline(streetAddress_1, STREET_SIZE);
   } while (!info.setStreetAddress1(streetAddress_1));


   do
   {
       cout << "Second street(if applicable, type N/A if not): ";
       cin.getline(streetAddress_2, STREET_SIZE);
   } while (!info.setStreetAddress2(streetAddress_2));

   do
   {
       cout << "What state do you live in: ";
       cin.getline(state, STATE_CODE_SIZE);
   } while (!info.setState(state));

   do
   {
       cout << "What City do you live in: ";
       cin.getline(city, CITY_SIZE);
   } while (!info.setCity(city));

   do
   {
       cout << "what is the zip code: ";
       cin >> zipCode;
   } while (!info.setZipCode(zipCode));


  
   cout << "\n" << "Details of Customer: " << "\n";
   cout << "Customer Number: " << info.getNumber() << "\n";
   cout << "Name: " << info.getName() << "\n";
   cout << "Street Address 1: " << info.getStreetAddress1() << "\n";
   cout << "Street Address 2: " << info.getStreetAddress2() << "\n";
   cout << "State: " << info.getState() << "\n";
   cout << "City: " << info.getCity() << "\n";
   cout << "Zip code: " << info.getZipCode() << "\n";

   return 0;
}

Solutions

Expert Solution

Program Code [C++]

Customer.h

const int NAME_SIZE = 20;
const int STREET_SIZE = 30;
const int CITY_SIZE = 20;
const int STATE_CODE_SIZE = 3;

#include <cstring>
#include <cctype>

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:
void setNumber(long number);

bool setName(char name[]);
bool setStreetAddress1(char street1[]);
bool setStreetAddress2(char street2[]);
bool setCity(char c[]);
bool setState(char st[]);
bool setZipCode(int zip);

long getNumber();

char* getName();
char* getStreetAddress1();
char* getStreetAddress2();
char* getCity();
char* getState();

int getZipCode();
};

Customer.cpp

#include "Customer.h"


void Customer::setNumber(long number)
{
customerNumber = number;
}

bool Customer::setName(char n[])
{

if (strlen(n) > 0)
{
strcpy(name, n);
return true;
}

return false;
}

bool Customer::setStreetAddress1(char street1[])
{

if (strlen(street1) > 0)
{
strcpy(streetAddress_1, street1);
return true;
}

return false;
}

bool Customer::setStreetAddress2(char street2[])
{
if (strlen(street2) > 0)
{
strcpy(streetAddress_2, street2);
return true;
}

return false;
}


bool Customer::setState(char st[])
{

if (strlen(st) > 0)
{
strcpy(state, st);

for (int i = 0; i < strlen(state); i++)
{
state[i] = toupper(state[i]);
if (state[i] < 'A' || state[i] > 'Z')
return false;
}

return true;
}

return false;
}

bool Customer::setCity(char c[])
{

if (strlen(c) > 0)
{
strcpy(city, c);

for (int i = 0; i < strlen(city); i++)
{
city[i] = toupper(city[i]);
if (city[i] < 'A' || city[i] > 'Z')
return false;
}

return true;
}

return false;

}

bool Customer::setZipCode(int zip)
{

if (zip >= 0 && zip <= 99999)
{
zipCode = zip;
return true;
}

return false;
}


long Customer::getNumber()
{
return customerNumber;
}

char* Customer::getName()
{
return name;
}

char* Customer::getStreetAddress1()
{
return streetAddress_1;
}

char* Customer::getStreetAddress2()
{
return streetAddress_2;
}

char* Customer::getState()
{
return state;
}

char* Customer::getCity()
{
return city;
}

int Customer::getZipCode()
{
return zipCode;
}

TestCustomer.cpp

#include <iostream>
#include "Customer.h"

using namespace std;

int main() {

   Customer info;


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;

info.setNumber(1);

do
{
cout << "What is your name: ";
cin.getline(name, NAME_SIZE);
} while (!info.setName(name));


do
{
cout << "Street you live on: ";
cin.getline(streetAddress_1, STREET_SIZE);
} while (!info.setStreetAddress1(streetAddress_1));


do
{
cout << "Second street(if applicable, type N/A if not): ";
cin.getline(streetAddress_2, STREET_SIZE);
} while (!info.setStreetAddress2(streetAddress_2));

do
{
cout << "What state do you live in: ";
cin.getline(state, STATE_CODE_SIZE);
} while (!info.setState(state));

do
{
cout << "What City do you live in: ";
cin.getline(city, CITY_SIZE);
} while (!info.setCity(city));

do
{
cout << "what is the zip code: ";
cin >> zipCode;
} while (!info.setZipCode(zipCode));

cout << "\n" << "Details of Customer: " << "\n";
cout << "Customer Number: " << info.getNumber() << "\n";
cout << "Name: " << info.getName() << "\n";
cout << "Street Address 1: " << info.getStreetAddress1() << "\n";
cout << "Street Address 2: " << info.getStreetAddress2() << "\n";
cout << "State: " << info.getState() << "\n";
cout << "City: " << info.getCity() << "\n";
cout << "Zip code: " << info.getZipCode() << "\n";

return 0;

}

Sample Output:-

----------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERIES!!!
HIT A THUMBS UP IF YOU DO LIKE IT!!!


Related Solutions

In C++ You will create 3 files: The .h (specification file), .cpp (implementation file) and main...
In C++ You will create 3 files: The .h (specification file), .cpp (implementation file) and main file. You will practice writing class constants, using data files. You will add methods public and private to your BankAccount class, as well as helper methods in your main class. You will create an arrayy of objects and practice passing objects to and return objects from functions. String functions practice has also been included. You have been given a template in Zylabs to help...
BankAccount: You will create 3 files: The .h (specification file), .cpp (implementation file) and main file....
BankAccount: You will create 3 files: The .h (specification file), .cpp (implementation file) and main file. You will practice writing class constants, using data files. You will add methods public and private to your BankAccount class, as well as helper methods in your main class. You will create an array of objects and practice passing objects to and return objects from functions. String functions practice has also been included. Extend the BankAccount class. The member fields of the class are:...
1. Copy the files from Assignment 1 to Assignment 3. 2. Modify the PetFoodCompany header to...
1. Copy the files from Assignment 1 to Assignment 3. 2. Modify the PetFoodCompany header to mention a friend function called "computeBonusBudget". This method should compute the bonus budget as netIncome() * BonusBudgetRate and this method should exist in the driver program - not the Class defintion. 3. Modify the output of the program to display the results of the computeBonusBudget. Enter Total Sales: 1000 Enter Total Expenses: 600 Net Income = 400 Bonus Budget = 8 Here is the...
Module 2 Programming Assignment – Battleship Refactor Refactor your Battleship drawing code from Module 1. Download...
Module 2 Programming Assignment – Battleship Refactor Refactor your Battleship drawing code from Module 1. Download the OO template for the basic battleship game, BattleshipRefactor.zip (refer below) The template has the outline of a battleship game using OO constructs. You need to add the Grid class and complete the code so that it runs correctly. At a minimum, you need to complete the Draw and DropBomb methods with code similar to the previous assignment. There will be changes due to...
1. Copy the files from Assignment 1 to Assignment 2. Relabel as necessary 2. Create 3...
1. Copy the files from Assignment 1 to Assignment 2. Relabel as necessary 2. Create 3 instances of the PetFoodCompany class - dogFoodMaker, catFoodMaker, fishFoodMaker. 3. Internally set the division name for each instance. (I.E. "Alpo" for dogFoorMaker, "Purina" for CatFoodMaker, "GloFish" for fishFoodMater) 4. Prompt me to enter the Company Name and Quarter only once. 5. For each of the above instances, prompt me for total sales and total expenses. A loop is not expected. 6. For each instance...
Write the header and the implementation files (.h and .cpp separatelu) for a class called Course,...
Write the header and the implementation files (.h and .cpp separatelu) for a class called Course, and a simple program to test it, according to the following specifications:                    Your class has 3 member data: an integer pointer that will be used to create a dynamic variable to represent the number of students, an integer pointer that will be used to create a dynamic array representing students’ ids, and a double pointer that will be used to create a dynamic array...
Write the header and the implementation files (.h and .cpp separately) for a class called Course,...
Write the header and the implementation files (.h and .cpp separately) for a class called Course, and a simple program to test it (C++), according to the following specifications:                    Your class has 3 member data: an integer pointer that will be used to create a dynamic variable to represent the number of students, an integer pointer that will be used to create a dynamic array representing students’ ids, and a double pointer that will be used to create a dynamic...
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header. Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program 2: class Rectangle in three files. In this lab, we will use class inheritance to write a...
In this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A...
In this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A test driver for testing the class defined in the other 2 files. You can name your file in the way you like. Remember it must be a .cpp file. In DateType.h file, type these lines: // To declare a class for the Date ADT // This is the header file DateType.h class DateType { public: void Initialize(int newMonth, int newDay, int newYear); int GetYear()...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files into a new C++ project.    NOTE: if your IDE does not allow you to create projects - or you are not sure how to do it - then you may combine the two cpp files into a single file. 2) Complete the program by adding code the the class methods. You may want to study the existing code first to get a feel...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT