The tools Hal’s sells are: Hammers: $10.99 Wrenches: $10.99 Levels: $19.99 Tape Measures: $4.99 Screwdrivers: $8.99

In order to make things easier in the long run you have decided to make a c++ program that takes in all the orders for each register and tallies them at the end of the day.

Write a c++ program that does the following:

Create a Register class that can store all of the receipts for the day and the totals for that register.

This class could have the following member functions:

Contructor(int) – Creates a number of receipts based on an integer that is passed into the constructor (this is the largest number of orders that the register can take). You may also be required to create additional variables to make the program work but that’s up to you to determine.

void getorder() – Asks the user how many of each item they want an stores that in the first available receipt.

void returnreceipts() – This function returns the details of all the receipts and the total for the day.

Register operator+(const Register &right)- This is an overloaded addition operator. When two objects are added together an empty temporary register is created (with 0 receipts) and only the totals of both objects are added to it. The temporary register is returned by the function.

Register operator=(const Register &right)- This overloaded assignment operator copies only the totals from the Object on the right.

In the Main function I would like:

Create 3 Register Objects. The first two registers are the ones in the store and should be initialized to take 10 orders. The third is used at closing time and can be initialized with 0 receipts as it will only take in the totals from the other registers.

Run the getorder function for registers 1 and 2 twice.
Run returnreceipts for register 1 and register2.
Reg3=Reg1+Reg2;
Run returnreceipts for register 3.

#include <iostream>
#include <iomanip>
using namespace std;

class Register
{
   public:

    void returnreceipts();
    void getorder();

    Register(int numReceipt)
    {
        numReceipt = reciept;
    };

    Register operator+(const Register &right); //two objects are added, an empty reg is created (0 receitps)
                                               //only the totals are added. temp reg is returned by the function
    Register operator=(const Register &right); //copies only the totals fom te object on the right
};

int main()
{
    Register reg1(2),reg2(2),reg3;

        cout << "Welcome to Hardware SuperStore! I see we have a number of customers! There are two cash registers available\n" << endl;

    reg1.getorder();
    reg2.getorder();

    return 0;
}

void Register::getorder()
{
    int W,S,L,TM,H;

    for ( int i = 0; i < 2; i++)
    {
        cout << "\n";
        cout << "How many of each item do you want to order for order no." << i + 1 << "in cash register 1 "<< endl;
        cout << "Wrenches: ";
        cin >> W;
        cout << endl << "Screwdrivers: ";
        cin >> S;
        cout << endl << "Levels: ";
        cin >> L;
        cout << endl << "Tape Measures: ";
        cin >> TM;
        cout << endl << "Hammers: ";
        cin >> H;
    }
}

this is what I have so far I'm trying to get the input part working first, so the user would be asked each item individual how many they want? this will happen for 2 users, then the next register will do the same? any tips will help

Edited 1 Year Ago by NoobCoder85

You need to re-read the 'problem' ...

Write a c++ program that does the following:
Create a Register class that can store all of the receipts
for the day and the totals for that register.

So ... each cash-register STORES each order (could use a struct for each order)

Thus ... could use a vector of struct to hold all orders for each cash-register
also could have a member to track the running dollar sum of orders so far

Edited 1 Year Ago by David W

This example may help you to get started ...

// classCashRegister.cpp //  // 2015-02-27 //

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>

using namespace std;

// a utility useful here ... //
int takeInInt( const string msg )
{
    int val;
    while( true )
    {
        cout << msg << flush;
        if( cin >> val && cin.get() == '\n' )
            break;
        else
        {
            cout << "ERROR! Integers ONLY here please ...\n";
            cin.clear(); // clear error flasgs
            cin.sync(); // 'flush' cin stream ...
        }
    }
    return val;
}



struct MyPair
{
    string name;
    double price;
    // ctor...
    MyPair( const string& name, double price ) : name(name), price(price)  { }
} ;


const MyPair ITEMS[] =
{
    MyPair("Hammers", 10.99),  MyPair("Wrenches", 10.99),
    MyPair("Levels", 19.99),  MyPair("Tape Measures", 4.99),
    MyPair("Screwdrivers", 8.99)
} ;

const int NUM_ITEMS = sizeof(ITEMS) / sizeof( MyPair );

struct Order
{
    int item[NUM_ITEMS]; // to hold quantity of each item ordered //

    // default ctor...
    Order() { for( int i = 0; i < NUM_ITEMS; ++ i ) item[i] = 0; }

    double get_total() const
    {
        double sum = 0;
        for( int i = 0; i < NUM_ITEMS; ++ i )
             sum += item[i] * ITEMS[i].price;
        return sum;
    }
    void takeIn()
    {
        for( int i = 0; i < NUM_ITEMS; ++ i )
        {
            item[i] = takeInInt("How many " + ITEMS[i].name + ": ");
        }
    }
} ;


class Register
{
    vector< Order > myOrders;
    double sum;

public:
    Register( int max_num ) { myOrders.reserve(max_num); sum = 0; }

    void get_order()
    {
        if( myOrders.size() < myOrders.capacity() )
        {
            Order tmpOrd;
            tmpOrd.takeIn();
            sum += tmpOrd.get_total();
            myOrders.push_back( tmpOrd );
        }
        else
        {
            cout << "Error! No room left here ... time to change tape!\n";
        }
    }

    double get_sum() const { return sum; }
} ;



int main()
{
    Register reg1(10); // allow for a max of 10 orders here //

    cout << "Take in 1st order for reg1...\n";
    reg1.get_order();
    cout << "Take in 2nd order for reg1...\n";
    reg1.get_order();

    cout << setprecision(2) << fixed; // show 2 decimal places //

    cout << "The grand total for all orders for reg1 was: $" << reg1.get_sum() << endl;

    cout << "All done!";
}

Edited 1 Year Ago by David W

Thank you David W.,

I am going to have to read up on vectors cause I am not too familiar with them, but this is definitely a start and a great learning tool. Thank you again for taking your time to help me along.

This question has already been answered. Start a new discussion instead.