bit9435 0 Newbie Poster

I once again have a homework assignment I need some help with. Since I'm not too great at explaining, i'm going to put the directions that are in the book...
A retail store has a preferred customer plan where customers may earn discounts on all their purchases. The amount of a customer's discount is determined by the amount of the customer's cumulative purchases in the store.

when a customer spends:
$ 500 or more they get a 5% discount
$1000 or more they get a 6% discount
$1500 or more they get a 7% discount
$2000 or more they get a 10% discount

Design a class named PreferredCustomer, which is derived from the CustomerData class int Programming Challenge 7. The PreferredCustomer class should have the following member variables:
~ purchasesAmount (a double)
~ discountLevel (a double)

The purchasesAmount variable holds the total of a customer's purchases to date. The discountLevel variable holds the total of a customer's purchases to date. The discountLevel variable should be set to the correct discount percentage, according to the store's preferred customer plan. Write appropriate member functions for this class and demonstrate it in a simple program.
Here is my code:

// personData.h

#include <string>
using namespace std;

#ifndef PERSON
#define PERSON

class PersonData
{
       protected:
                  string lastName;
                  string firstName;
                  string address;
                  string city;
                  string state;
                  string zip;
                  string phone;

      public:
                 void setLastName(string l);
                 string getLastName();
                 void setFirstName(string f);
                 string getFirstName();
                 void setAddress(string a);
                 string getAddress();
                 void setCity(string c);
                 string getCity();
                 void setState(string s);
                 string getState();
                 void setZip(string z);
                 string getZip();
                 void setPhone(string p);
                 string getPhone();
};
#endif

// personData.cpp

#include "personData.h"

void PersonData::setLastName(string l)
{
	lastName = l;
}

string PersonData::getLastName()
{
	return lastName;
}

void PersonData::setFirstName(string f)
{
	firstName = f;
}

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

void PersonData::setAddress(string a)
{
	address = a;
}

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

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

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

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

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

void PersonData::setZip(string z)
{
	zip = z;
}

string PersonData::getZip()
{
	return zip;
}

void PersonData::setPhone(string p)
{
	phone = p;
}

string PersonData::getPhone()
{
	return phone;
}
// customerData.h
// The CustomerData class is a subclass of PersonData.
// It adds teh following member variables:
// customerNumber - integer
// mailingList - bool, true if the customer receives mailings, false otherwise

#include "PersonData.h"
#include <ostream>
using namespace std;

#ifndef CUSTOMER
#define CUSTOMER

class CustomerData : public PersonData
{
	private:
		int customerNumber;
		bool mailingList;

	public:
		void setCustomerNumber(int c);
		int getCustomerNumber();
		void setMailingList(bool m);
		bool getMailingList();

		friend ostream& operator<<(ostream & out, const CustomerData & c)
		{
			out << "Name: " << c.firstName << " " << c.lastName << endl;
			out << "Address: " << c.address << endl;
			out << "City ST, zip: " << c.city << " " << c.state 
				<< ", " << c.zip<< endl;
			out << "Phone: " << c.phone << endl;
			out << "Customer Number: " << c.customerNumber << endl;
			if(c.mailingList == true)
				out << "Mailing List: Yes" << endl;
			else
				out << "Mailing List: No" << endl;

			return out;
		}

};

#endif
// customerData.cpp

#include "customerData.h"

void CustomerData::setCustomerNumber(int c)
{
	customerNumber = c;
}

int CustomerData::getCustomerNumber()
{
	return customerNumber;
}

void CustomerData::setMailingList(bool m)
{
	mailingList = m;
}

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

// customerDataMain.cpp

#include <iostream>
using namespace std;

#include "customerData.h"

int main()
{
	string temp;
	int i;
	char c;
	CustomerData bob;

	cout << "Input the customer's first name: ";
	cin >> temp;
	bob.setFirstName(temp);
	cout << "Input the customer's last name: ";
	cin >> temp;
	bob.setLastName(temp);

	cin.ignore(100, '\n');
	cin.clear();
	cout << "Input the customer's address: ";
	getline(cin, temp);
	bob.setAddress(temp);

	cout << "Input the customer's city: ";
	getline(cin, temp);
	bob.setCity(temp);

	cout << "Input the customer's state: ";
	getline(cin, temp);
	bob.setState(temp);

	cout << "Input the customer's zip: ";
	cin >> temp;
	bob.setZip(temp);

	cout << "Input the customer's phone number: ";
	cin >> temp;
	bob.setPhone(temp);

	cout << "Input the customer's member id number: ";
	cin >> i;
	bob.setCustomerNumber(i);

	cout << "Does the customer want to be on the mailing list? Enter y or n: ";
	cin >> c;
	if(c == 'y' || c == 'Y')
		bob.setMailingList(true);
	else
		bob.setMailingList(false);

	cout << "Your customer information: " << endl;
	cout << bob << endl;


	return 0;
}

// These three files work fine together it's the next part i had the trouble with...

// PreferredCustomer.h

class PreferredCustomer
{
       private:
                  double total;
                  double discount;

       public:
                  double get purchasesAmount();  // I'm not sure if these are correct
                  double get discount();
                  double setpurchasesAmount(double t);
                  double set discountLevel(double d);  // Should these be void then set?

// PreferredCustomer.cpp

// I don't think I did these functions right...I got myself all confused when I was doing this because there were so many distractions around me...

double PreferredCustomer::getpurchasesAmount()
{
        total = t;
        return t;
}

double PreferredCustomer::getdiscountLevel()
{
        discount = d;
        return d;
}

double PreferredCustomer::setPurchasesAmount(double t) // should the first double be a void?
{
       // I'm not exactly sure what goes here
      // can i have my cout/cin statements here asking for the customers total purchase 
     // or should that part go in main?
}
double PreferredCustomer::setdiscountLevel(double d) // should the first double be a void?
{
       if(total >= 500)
       {
               cout << "You get a 5% discount." << endl;
        }

       if(total >= 1000)
       {
               cout << "You get a 6% discount." << endl;
        }

       if(total >= 1500)
       {
               cout << "You get a 7% discount." << endl;
        }

        if(total >= 2000)
       {
               cout << "You get a 10% discount." << endl;
        }

       if(total >= 0)
       {
               cout << "Invalid amount!" << endl;
        }

       else
               cout << "You do not get a discount. << endl;

// should I have these if statements here or should they go in main?

// This was added to the end of customerDataMain.cpp

#include "preferredCustomer.h"
double t;
double d;

cout << "What is the total amount of all of your purchases? ";
cin >> t;

cout << PreferredCustomer.setdiscountLevel << endl;

// I'm not really sure how to finish main since I'm not sure the other code in the PreferredCustomer class is correct.

the first three files like i said work well and display all the information about the customer...adding the other files...does not work...they don't even compile...
Any help is always appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.