I am now dissecting each file piece by piece. The project consists of 2 header files and 2 definition files plus a main program utilizing both classes. One of the definition files (sales.cpp) compiles fine, the other one (register.cpp) is the one that produces 2 errors. I am going to provide the 2 header files that are needed to be included in the register.cpp, as well as the register.cpp file. Any help that can be given I will appreciate immensely.
sale.h
Code:
enum ItemType {BOOK, DVD, SOFTWARE, CREDIT};
class Sale
{
public:
Sale(); // default constructor,
// sets numerical member data to 0
void MakeSale(ItemType x, double amt);
// the MakeSale function loads data into the Sale object. The
// item and price are passed in. Compute tax and total.
// (For store credits, tax is 0).
ItemType Item(); // Returns the type of item in the sale
double Price(); // Returns the price of the sale
double Tax(); // Returns the amount of tax on the sale
double Total(); // Returns the total price of the sale
void Display(); // outputs sale info (described below)
// for the Display function, output the sale item, the price, the tax,
// and the total (all on one line). For store credit, the amounts
// should be enclosed in < > symbols, to indicate a negative charge.
// All monetary output should be in dollars and cents format, to two
// decimal places.
// Examples: Book $ 20.00 Tax: $ 1.40 Total: $ 21.40
// Credit <$ 15.00> Tax: $ 0.00 Total: <$ 15.00>
private:
double price; // price of item or amount of credit
double tax; // amount of sales tax (does not apply to credit)
double total; // final price once tax is added in.
ItemType item; // transaction type
};
register.h
Code:
//register header file
#include "sale.h"
class Register
{
public:
Register(int i, double amt);//allows ID number and starting amount
//in register to be initialized when
//object is created
int GetID();//returns current ID number in the register to the
//caller, accessor function
double GetAmount();//return current amount in the register to
//caller, accessor function
void RingUpSale(ItemType c, double amt);//stores sale in sale list
//also updates money amount
//in register.
//allows item type and sale
//base price to be passed in
void ShowLast();//displays only the info about last sale made
void ShowAll();//Shows all of sales currently in sale list, one per line
void Cancel();//cancels last sale in list
double SalesTax(int n);//calculates and returns total amount of sales tax
//for last n sales (i.e. most recent ones)
private:
int ID;
double Amount;
double sales_taxxx;
double base_price;
int numsales;
Sale *sales;
};
register.cpp
Code:
//definitions for register class
#include <iomanip>
#include <iostream>
#include "Register.h"
#include "sale.h"
using namespace std;
//Register definitions
Register::Register(int i, double amt)
{
ID=i;
Amount=amt;
numsales=0;
//parameters in register are intialized to 0
}
int Register::GetID()
{
return ID;//returning current ID in register
}
double Register::GetAmount()
{
return Amount;//returning current amount in refrigerator
}
void Register::RingUpSale(ItemType c, double amt)
{
Sale *s;
//create a new array
//memcpy the old array into the new array byte by byte
//set the old array to the new array.
numsales++;
s = new Sale[numsales];
memcpy(s, sales, sizeof(Sale)*(numsales-1));
s[numsales-1].MakeSale(c, amt);
sales=s;
if (c==CREDIT) {
Amount-=amt;
}
else {
Amount+=amt;
}
}
void Register::ShowAll(void) {
if (numsales==0) {
cout<<"No Sales Have Been Made Silly....";
return;
}
for (int i=0;i<numsales;i++) {
sales[i].Display();
}
}
void Register::ShowLast(void) {
if (numsales==0) {
cout<<"No Sales Have Been Made Silly....";
return;
}
sales[numsales-1].Display();
}
void Register::Cancel(void) {
{
Sale *s;
if (numsales==0) {
cout<<"No Sales Have Been Made Silly....";
return;
}
//create a new array
//memcpy the old array into the new array byte by byte
//set the old array to the new array.
if (s[numsales].Item()==CREDIT) {
Amount+=s[numsales].Price();
}
else {
Amount-=s[numsales].Price();
}
numsales--;
s = new Sale[numsales];
memcpy(s, sales, sizeof(Sale)*(numsales));
sales=s;
}
}
double Register::SalesTax(int n) {
int t_n=0;
double tax_total=0;
if (n<0) {
cout<<"Invalid Number..."<<endl;
return 0;
}
//figure out how many to count
if (n > numsales) {
t_n=numsales;
}
else {
t_n=n;
}
//count t_n recent items
for (int i=(numsales-1);i>=(numsales-t_n);i--)
tax_total+=sales[i].Tax();
return tax_total;
}
Compiler errors:
Code:
sale.h(14) : error C2011: 'ItemType' : 'enum' type redefinition
sale.h(17) : error C2011: 'Sale' : 'class' type redefinition