Here is my code:
`
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Register
{
//Private members
private:
//Creating an array for all the Prices
static double Price[];
//Declaring RegNUM and RecNUM
int RegNUM, RecNUM;
//Print out Item name in a loop
static string items[];
//Creates a Receipt Structure
struct Receipt
{
//Takes in the number of orders and stores items bought
int Orders[5];
double Total = 0;
};
//Creating a pointer (RecPTR)
Receipt *RecPTR;
//Public members
public:
//Register Constructor
Register(int,int);
//Member functions
void getOrder(int);
void RecRETURN();
//Operators
Register operator+(const Register &right);
Register operator=(const Register &right);
};
//Setting the prices for the items within an array
double Register::Price[5] = { 10.99, 19.99, 8.99, 4.99, 10.99 };
//Setting names of the items in order to be displayed in a loop
string Register::items[5] = { "Hammers", "Levels", "Screwdrivers", "Tape Measures", "Wrenches" };
//Constructor with default number of receipt (10) and default register number (0)
Register::Register(int defRec = 10, int defReg = 0)
{
//Initialize RecPTR
RecPTR = new Receipt[defRec];
//Initialize orders to 0
for (int j = 0; j < defRec; j++)
{
//Setting orders to 0
for (int i = 0; i < 5; i++)
RecPTR[j].Orders[i] = 0;
}
//Setting Register Number (RegNUM)
RegNUM = defReg;
//Setting the # of receipts
RecNUM = defRec;
}
//getOrder function --- input order number to store in right receipt
void Register::getOrder(int OrderNUM)
{
int numItem;
//Displays order number and register number
cout << "\nHow many of each item do you want to order"
<< "for order no. " << OrderNUM << " in cash register "
<< RegNUM << "?\n";
//Getting amount for 5 different items
for (int i = 0; i < 5; i++)
{
//Ask user for the amount of each item bought
cout << items [i] << "?: ";
cin >> numItem;
//Storing info. with the structure
RecPTR[OrderNUM-1].Orders[i] += numItem;
//Calculation for the total
RecPTR[OrderNUM - 1].Total += (RecPTR[OrderNUM-1].Orders[i] * Price[i]);
}
//Calculate total price including the tax
RecPTR[OrderNUM - 1].Total = RecPTR[OrderNUM - 1].Total * 1.13;
}
//Member Function to Return Receipts
void Register::RecRETURN()
{
//Displaying receipts for both Register 1 and 2
if (RegNUM <= 2)
{
//Displaying the items purchased for each order
for (int j = 0; j < 2; j++)
{
//Displaying receipts
cout << "\nThe total tools ordered on receipt no. "
<< j + 1 << " in cash register "
<< RegNUM << " are:\n";
cout << items[0] << ":" << setw(13) << RecPTR[j].Orders[0] << endl;
cout << items[1] << ":" << setw(14) << RecPTR[j].Orders[1] << endl;
cout << items[2] << ":" << setw(8) << RecPTR[j].Orders[2] << endl;
cout << items[3] << ":" << setw(7) << RecPTR[j].Orders[3] << endl;
cout << items[4] << ":" << setw(12) << RecPTR[j].Orders[4] << endl;
cout << "Total with Tax:" << setw(6) << "$" << fixed << setprecision(2)
<< RecPTR[j].Total << endl;
}
//Displaying the totals on the registers
cout << "\nThe total for register " << RegNUM << " is:\n"
<< RegNUM << " are:\n";
cout << items[0] << ":" << setw(13) << RecPTR[0].Orders[0] + RecPTR[1].Orders[0] << endl;
cout << items[1] << ":" << setw(14) << RecPTR[0].Orders[1] + RecPTR[1].Orders[1] << endl;
cout << items[2] << ":" << setw(8) << RecPTR[0].Orders[2] + RecPTR[1].Orders[2] << endl;
cout << items[3] << ":" << setw(7) << RecPTR[0].Orders[3] + RecPTR[1].Orders[3] << endl;
cout << items[4] << ":" << setw(12) << RecPTR[0].Orders[4] + RecPTR[1].Orders[4] << endl;
cout << "Total with Tax:" << setw(6) << "$" << fixed << setprecision(2)
<< RecPTR[0].Total + RecPTR[1].Total << endl;
}
//Display register 3 info.
else
{
//Displaying the total for Register 3
cout << "\nThe two registers combined into register "
<< RegNUM << " are:\n";
cout << items[0] << ":" << setw(13) << RecPTR[0].Orders[0] << endl;
cout << items[1] << ":" << setw(14) << RecPTR[0].Orders[1] << endl;
cout << items[2] << ":" << setw(8) << RecPTR[0].Orders[2] << endl;
cout << items[3] << ":" << setw(7) << RecPTR[0].Orders[3] << endl;
cout << items[4] << ":" << setw(12) << RecPTR[0].Orders[4] << endl;
cout << "Total with Tax:" << setw(6) << "$" << fixed << setprecision(2)
<< RecPTR[0].Total << endl;
}
}
// (+) Operator
Register Register::operator+(const Register &right)
{
Register tmp;
for (int j = 0; j < RecNUM; j++)
{
for (int i = 0; i < 5; i++)
{
/********************************************
Adds reg 1,2 for receipt 'j' for each order
they are then stored in receipt 0 of tmp
********************************************/
tmp.RecPTR[0].Orders[i] += RecPTR[j].Orders[i] + right.RecPTR[j].Orders[i];
}
//Register 1 and 2s totals are added to the tmp total
tmp.RecPTR[0].Total += RecPTR[j].Total + right.RecPTR[j].Total;
}
//Returns tmp
return tmp;
}
// (=) Operator
Register Register::operator=(const Register &right)
{
//Temporary Register
Register temp;
for (int i = 0; i < 5; i++)
{
//Storing the orders into the temporary object
RecPTR[0].Orders[i] = right.RecPTR[0].Orders[i];
}
//Storing the total into the temporary object
RecPTR[0].Total = right.RecPTR[0].Total;
//Returns tmp
return temp;
}
int main()
{
//Creating the 3 register instances
Register Reg1(10,1), Reg2(10,2), Reg3(0,3);
cout << "Welcome to Hal's Hardware!\n";
cout << "I see we have a number of customers\n";
cout << "There are two cash register available\n\n";
//Calls getOrder and passes the receipt number
Reg1.getOrder(1);
Reg1.getOrder(2);
Reg2.getOrder(1);
Reg2.getOrder(2);
//Calling RecRETURN
Reg1.RecRETURN();
Reg2.RecRETURN();
//Adding totals for Reg1 and Reg2, storing them in Reg3
Reg3 = Reg1 + Reg2;
//Calling RecRETURN
Reg3.RecRETURN();
}
My error is line 50 (Register::Register(int defRec = 10, int defReg = 0)) I get addition of default argument on redeclaration makes this constructor a default constructor
I am using xcode and it wont run, but in visual it does and says nothing. I would like it to run in xcode.
Is there anyway of fixing this?`