Question

Write a program in C++ that simulates a soft drink machine. The program will need several...

Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem,

DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class.

DrinkItem class

The DrinkItem class will contains the following private data members:

name: Drink name (type of drink – read in from a file). Type is std::string.

price: Drink cost (the retail cost of one drink). This is the price the customer will pay for one

drink of this type. This is also read in from a file. Type is double.

quantity: Number of drinks, of this type, in the machine. Initial value is read in from a file.

This is also updated by the program. Type unsigned int.

purchased: Drinks purchased. Initially 0. Updated whenever a drink is purchased. Type is

unsigned int.

sales: This is used to keep track of the amount of money paid for all of the drinks purchased.

Every time there is a successful purchase the amount of the purchase should be added to sales.

You need to initially set this to 0. Type is double.

You need to have public accessors for all of the above (five) data members. Make sure you accessors are const member functions. Only the price, and name data members should have a mutator functions. So you will have five get member functions (accessors) but only two set member functions (mutators).

Example:

The prototype for the accessor for price would be:

double getPrice() const;

and the mutator would be:

void setPrice(double newPrice);

You will also need the following additional public member functions / constructors:

void addDrinks(unsigned int amount)

When this member function is called your program needs to update the quantity by the specified amount.

bool purchase()

The purchase member function will check to see if there are any drinks left. If there is at least 1 drink

remaining the purchase member function will subtract 1 drink from the number of drinks, add 1 to the

drinks purchased, add the cost of the drink to sales, and return a true value.

If the number of drinks is 0 when this member function is called no member data should be updated and

a value of false should be returned.

DrinkItem constructors (two total)

The DrinkItem class will have one constructor that takes the input values name, price and quantity (in

that order). The purchased and sales member data variables will be set to 0.

The second constructor is a default constructor (no arguments) that will set the numeric values to 0 and

the name to "";

Create a header file drinkitem.h for the class declaration and create a drinkitem.cpp file for the member

functions. You can inline the accessors and mutations. Do not inline any of the other member functions

and do not inline the constructors.

DrinkMachine class

The DrinkMachine class will contain the following data members:

An unsigned int that contains a version number. For this assignment this will have a value

of 1.

An unsigned int that contains the actual number of DrinkItem objects being used in the drink item array.

An array of DrinkItem objects. Each element of the array will be a DrinkItem object. This array will contain a maximum of 25 elements. You will keep track on the actual number in use via the unsigned int value you created above.

An unsigned int that contains the maximum number of DrinkItem objects. This is used internally by the drink machine to make sure you don’t put more than 25 DrinkItem objects in the array.

The public member functions in the DrinkMachine class are:

DrinkMachine() constructor

The constructor will take no parameters. The various drink machine values will be read in from the file drink.txt. The constructor will also write the drink machine values (read in from the file) to a file called drink_backup.txt. This way you will have a backup copy of your file in case there are bugs in your code. The first value in the input file, drink.txt, is the number of drink items. There will then be drink information for each of the drink items specified by the first value in the file. A drink item is made up of a name, price and quantity. The first drink item you read in will go into the array of DrinkItem value at index 0. The next one will go into the entry with index 1, and so on.

~DrinkMachine() destructor

The destructor will write the current list of items back to the output file, drink.txt. This will include the new quantity values for the DrinkItem objects.

unsigned int size() const

Returns the current number of DrinkItem entries being used by the drink machine. These are the ones read in from the input file.

unsigned int max_size() const

Returns the maximum number of DrinkItem entries allowed in the drink machine.

DrinkItem& at(unsigned int index)

Return a reference to the drink item at the specified index.

const DrinkItem& at(unsigned int index) const

Returns a const reference to the specified drink item. This allows you to use a function that uses a

const DrinkItem reference. You cannot update the DrinkItem object in this case.

bool available(unsigned int drinkId) const

Return true if the drink item at index drinkId has a quantity of 1 or more. Return false otherwise.

double getPrice(unsigned int drinkId) const

Get the price of the item at the specified index.

Receipt purchase(unsigned int drinkId, double amount)

Purchase an item at the specified index. If the purchase worked return a Receipt object with any

change. If the drink could not be purchased (the quantity was 0) or if the funds were insufficient return

Receipt with change of 0 and either insufficient or empty turned on. Check for the funds amount first.

If the funds are enough for the purchase then check the quantity. Update the quantity and purchased

totals as appropriate. Note your return statement will look similar to the following:

Receipt purchase(unsigned int drinkId, double amount)

{

// code goes here

return Receipt(…); // where … is the rest of the constructor

}

You are returning back a temporary object here. The return type for the purchase member function is

also Receipt, which is a temporary object. The object will be deleted once it has been assigned in the

calling function. You do not want to return by reference, it needs to be a copied temporary object. You

also do not want to create it with the new operator or you will be creating a memory leak in your

program.

void addDrinks(unsigned int drinkId, unsigned int amount)

Add the specified number of drinks for the specified drink item index.

void print(std::ostream& outStream) const

Print out the current contents of the drink machine including the drink machine version, the number of

drink items in the machine and all of the information about the drink items (index, name, price,

quantity, number of drinks purchased, and the sales for this drink).

Here is a sample of the output (you must have all of this data in your output). Make sure you align the

output as shown here. Your spacing may be different.

Drink Machine Version 1

Number of entries: 8

Id           Name                   Price $   Qty        Sold       Sales $

0            Cola                       1.25       24           1             1.25

1            Root-beer           1.25       19           1             1.25

2            Lemon-lime        1.25       25           0             0.00

3            Water                   1.00       39           1              1.00

4            Orange                 1.25       0             5             6.25

5            Iced-tea               1.25       35           0             0.00

6            Grape                    1.30       15           0              0.00

7            Iced-coffee         2.00       34           1             2.00

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.cpp
-------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
#include "drinkmachine.h"
#include "drinkitem.h"
#include "receipt.h"

class DrinkMachineApplication
{
private:
    DrinkMachine drinkMachine;
public:
    DrinkMachineApplication();
    void run();
private:
    void displayMenu();
    unsigned int getMenuValue() const;
    void restock();
};

// driver for the application
int main()
{
    DrinkMachineApplication application;
    application.run();
    return 0;
}

DrinkMachineApplication::DrinkMachineApplication()
{
    // don't do anything
}

// run the application
void DrinkMachineApplication::run()
{
    if (drinkMachine.size() == 0)
    {
        std::cout << "The drink machine is empty" << std::endl;
        return;
    }

    // output money amounts in the format xxxx.xx
    std::cout << std::fixed << std::setprecision(2);

    unsigned int menuItem;

    // main processing loop
    do
    {
        // display the menu
        displayMenu();

        menuItem = getMenuValue();

        // process the menu item
        if (menuItem < drinkMachine.size())
        {
            // prompt for the amount
            double amount;
            std::cout << "Enter the amount of the purchase: ";
            std::cin >> amount;

            // try the purchase
            DrinkItem &item = drinkMachine.at(menuItem);
            Receipt receipt = drinkMachine.purchase(menuItem, amount);

            // check the results of the purchase
            if (receipt.success())
            {
                std::cout << "Your purchase of " << item.getName();
                std::cout << " succeeded. ";

                // get the change (if any)
                double change = receipt.getChange();
                if (change == 0.0)
                {
                    std::cout << " There was no change" << std::endl;
                }
                else
                {
                    std::cout << " Your change is $" << change << std::endl;
                }
            }
            else if (receipt.insufficient())
            {
                // insufficient funds
                std::cout << "You need additional money for the purchase" << std::endl;
            }
            else if (receipt.empty())
            {
                // there is no more of this drink in the machine
                std::cout << "Your selection is empty" << std::endl;
            }
            else
            {
                // if this happens you have logic errors in the Receipt class
                std::cout << "The receipt is invalid" << std::endl;
            }
        }

    } while (menuItem != drinkMachine.size());

    // display the output from the run
    std::cout << std::endl;
    drinkMachine.print(std::cout);
    std::cout << std::endl;

    std::cout << "The total sales is $" << drinkMachine.sales() << std::endl;

    // restock the drinks
    std::cout << std::endl;
    std::cout << "Now restock the drink machine" << std::endl;
    restock();

    // display the final output after restocking
    std::cout << std::endl;
    drinkMachine.print(std::cout);
    std::cout << std::endl;
}

// Display the drink machine menu
void DrinkMachineApplication::displayMenu()
{
    const int ID_WIDTH = 6;
    const int NAME_WIDTH = 25;
    const int PRICE_WIDTH = 10;
    const int QTY_WIDTH = 8;

    // make sure the price is output in the format xxxx.xx
    std::cout << std::fixed << std::setprecision(2);

    std::cout << std::endl;

    // output some headers
    std::cout << std::setw(ID_WIDTH) << "Menu #" << " ";
    std::cout << std::left << std::setw(NAME_WIDTH) << "Name" << std::right;
    std::cout << std::setw(PRICE_WIDTH) << "Price $";
    std::cout << std::setw(QTY_WIDTH) << "Qty";
    std::cout << std::endl;

    // for each drink type output the drink information
    //for (unsigned int itemId=0; itemId<drinkMachine.size(); itemId++)
    int count= 0;
    for(auto item : drinkMachine)
    {
        //auto item = drinkMachine.at(itemId);
        //std::cout << std::setw(ID_WIDTH) << itemId << " ";
        std::cout << std::setw(ID_WIDTH) << count++ << " ";
        std::cout << std::left << std::setw(NAME_WIDTH) << item.getName();
        std::cout << std::right << std::setw(PRICE_WIDTH) << item.getPrice();
        std::cout << std::setw(QTY_WIDTH) << item.getQuantity();
        std::cout << std::endl;
    }

    // exit menu item
    std::cout << std::setw(ID_WIDTH) << drinkMachine.size() << " "
              << std::left << std::setw(NAME_WIDTH) << "exit program"
              << std::right << std::endl;

}

// read in and validate the menu item
unsigned int DrinkMachineApplication::getMenuValue() const
{
    // holds the menu item
    unsigned int menuItem;

    // keeps track of the validity of the input data
    bool valid;

    // keep displaying the menu until we get a valid value
    do
    {
        std::cout << "Enter a menu item: ";
        std::cin >> menuItem;

        // check for errors
        if (std::cin.fail())
        {
            // we had an error
            valid = false;

            // the input is invalid, so we need to discard it and
            // clear out the error
            std::string invalidData;

            // clear out the error
            std::cin.clear();

            // read in the bad data
            std::getline(std::cin, invalidData);

            // output an error message
            std::cout << "Invalid input \"" << invalidData
                      << "\" has been discarded"<< std::endl;
        }
        else if (menuItem > drinkMachine.size())
        {
            // the menu selection is out of range
            valid = false;
            std::cout << "The menu item is not valid" << std::endl;
        }
        else
        {
            // the menu value is valid
            valid = true;
        }

    } while ( !valid );

    return menuItem;
}

// go through all of the items and restock any that are 0
void DrinkMachineApplication::restock()
{
    const unsigned int amount = 5;

    // go through all of the drink items and see if any are 0
    for (unsigned int itemId=0; itemId < drinkMachine.size(); itemId++)
    {
        auto drinkItem = drinkMachine.at(itemId);

        if (drinkItem.getQuantity() == 0)
        {
            // output a message saying we are out of drinks
            std::cout << "Drink " << drinkItem.getName()
                      << " is out of stock. Restocking with "
                      << amount << " drinks." << std::endl;

            // add the drinks to the machine
            drinkMachine.addDrinks(itemId, amount);
        }
    }
}
------------------------------------------------------------------------------------
drinkmachine.cpp
-----------------------------------------------
#include "drinkmachine.h"
#include "receipt.h"
#include <iostream>
#include <fstream>
#include <iomanip>

//default constructor of a drink machine.
//Reads in values of drinks from a file and creates a backup of the file
//creates drinks based on input
DrinkMachine::DrinkMachine()
{
    //read in files
    std::ifstream inFile("drink.txt");
    std::ofstream outFile("drink_backup.txt");
    //set default values for variables
    maxDrinks = 25;
    version = 1;
    numDrinks = 0;
    //read in number of drinks to loop through
    inFile >> numDrinks;
    outFile << numDrinks << "\n";
    //loop through drinks
    for(unsigned int i = 0; i < numDrinks; i++)
    {
        //read in values for the drink
        std::string name;
        double price;
        unsigned int quantity;
        inFile >> name >> price >> quantity;
        //create the drink
        drinks[i] = DrinkItem(name, price, quantity);
        //create backup file for the drink
        outFile << std::setw(20) << std::left << name << std::right;
        outFile << std::setw(7) << std::fixed << std::setprecision(2) << price << std::setprecision(std::cout.precision());
        outFile << std::setw(7) << quantity << "\n";
    }
    inFile.close();
    outFile.close();
}

//destructor saves current drink machine to the file
DrinkMachine::~DrinkMachine()
{
    //opens the file to write to
    std::ofstream outFile("drink.txt");
    //reads nubmer of drinks in the machine
    outFile << numDrinks << "\n";
    //loops through the number of drinks in the machine
    for(unsigned int i = 0; i < numDrinks; i++)
    {
        //stores the drinks in the file
        outFile << std::setw(20) << std::left << drinks[i].getName() << std::right;
        outFile << std::setw(7) << std::fixed << std::setprecision(2) << drinks[i].getPrice() << std::setprecision(std::cout.precision());
        outFile << std::setw(7) << drinks[i].getQuantity() << "\n";
    }
}
DrinkItem* DrinkMachine::begin(){
    return (drinks);
    //return &(drinks[0]);
}
DrinkItem* DrinkMachine::end(){
    return (drinks+numDrinks);
    //return &(drinks[numDrinks]);
}
//return the number of drinks being stored in the machine
unsigned int DrinkMachine::size() const
{
    return numDrinks;
}

//return the max number of drinks that can be held by the drink machine
unsigned int DrinkMachine::max_size() const
{
    return maxDrinks;
}

//gets the drink item at the given index of the machine
DrinkItem& DrinkMachine::at(unsigned int index)
{
    return drinks[index];
}

//gets a const version of the drink item at the given index of the machine
const DrinkItem& DrinkMachine::at(unsigned int index) const
{
    return drinks[index];
}

//returns whether or not the drink with the given drink id is available
bool DrinkMachine::available(unsigned int drinkId) const
{
    return drinks[drinkId].getQuantity() > 0;
}

//returns the price of the drink with the given drink id
double DrinkMachine::getPrice(unsigned int drinkId) const
{
    return drinks[drinkId].getPrice();
}

//checks to see if the drink can be purchased with the given amount of money
//if it can, returns a receipt with the proper amount of change
//otherwise returns a receipt holding an error state
Receipt DrinkMachine::purchase(unsigned int drinkId, double amount)
{
    //gets the drink at the current ID
    DrinkItem drink = drinks[drinkId];
    //makes sure the amount paid is enough for the drink
    if(amount >= drink.getPrice())
    {
        //makes sure the drink is still available
        if(drink.getQuantity() > 0)
        {
            //purchases the drink and returns the change
            drinks[drinkId].purchase();
            return Receipt(SUCCESS, amount - drink.getPrice());
        }
        //sets the receipt to the "empty" state
        return Receipt(EMPTY);
    }
    //sets the receipt to the insufficient funds state
    return Receipt(INSUFFICIENT);
}

//adds the amount of drinks with the given drink id
void DrinkMachine::addDrinks(unsigned int drinkId, unsigned int amount)
{
    drinks[drinkId].addDrinks(amount);
}

//outputs the drink machine version, the number of entries, and
//the id, name, price,, quantity, number sold, and sales from each drink in the machine
void DrinkMachine::print(std::ostream& outStream) const
{
    outStream << "Drink Machine Version " << version << "\n";
    outStream << "Number of entries: " << numDrinks << "\n\n";
    outStream << std::setw(6) << "Id";
    outStream << std::setw(27) << std::left << " Name " << std::right;
    outStream << std::setw(7) << " Price $ ";
    outStream << std::setw(7) << "Qty ";
    outStream << std::setw(7) << "Sold ";
    outStream << std::setw(9) << "Sales $\n";
    for(unsigned int i = 0; i < numDrinks; i++)
    {
        outStream << std::setw(6) << i;
        outStream << " " << std::setw(27) << std::left << drinks[i].getName() << std::right;
        outStream << std::setw(7) << drinks[i].getPrice();
        outStream << std::setw(7) << drinks[i].getQuantity();
        outStream << std::setw(7) << drinks[i].getPurchased();
        outStream << std::setw(9) << drinks[i].getSales() << "\n";
    }
}

//gets the total sales from the drink machine
double DrinkMachine::sales() const
{
    double sum = 0;
    //sums all of the drinks in the array
    for(unsigned int i = 0; i < numDrinks; i++)
        sum += drinks[i].getSales();
    //returns the sum
    return sum;
}

//gets the sales from the drink with the given drink id in the drink machine
double DrinkMachine::sales(unsigned int drinkId) const
{
    return drinks[drinkId].getSales();
}
------------------------------------------------------------------------------------------
drinkmachine.h
---------------------------------------------------
#ifndef DRINKMACHINE_H_
#define DRINKMACHINE_H_
#include "drinkitem.h"
#include "receipt.h"

class DrinkMachine
{
    //initialize variables for the class
private:
    unsigned int version;
    unsigned int numDrinks;
    DrinkItem drinks[25];
    unsigned int maxDrinks;
    //prototype methods to be instantiated later
public:
    //constructor for drink machine. Reads in data from a file and creates a backup.
    //creates an array of drinks from these and stores them
    DrinkMachine();
    //saves current state into the file to be read from later.
    ~DrinkMachine();
    DrinkItem* begin();
    DrinkItem* end();
    //returns the number of drinks stored in the machine
    unsigned int size() const;
    //returns the maximum drinks that can be stored in the machine
    unsigned int max_size() const;
    //returns the drink item at the given index
    DrinkItem& at(unsigned int index);
    //returns a const version of the drink item at the given index
    const DrinkItem& at(unsigned int index) const;
    //checks to ensure that the drink item with the given id has a quantity greater than 0
    bool available(unsigned int drinkId) const;
    //returns the price of the drink with the given id
    double getPrice(unsigned int drinkId) const;
    //returns a receipt telling if the drink item was successfully purchased and your change
    Receipt purchase(unsigned int drinkId, double amount);
    //adds the specified amount of the drink with specified id to the machine
    void addDrinks(unsigned int drinkId, unsigned int amount);
    //outputs the properties of the drinks in the drink machine to the given output stream in a particular format
    void print(std::ostream& outStream) const;
    //returns the total number of sales from the machine
    double sales() const;
    //returns sales of the drink with the specified id in the machine
    double sales(unsigned int drinkId) const;
};

#endif /* DRINKMACHINE_H_ */
--------------------------------------------------------------------------------------------
drinkitem.cpp
----------------------------------------------
#include "drinkitem.h"
#include <iostream>

//default constructor
DrinkItem::DrinkItem()
{
    //instantiates variables to default values
    name = "";
    price = 0.0;
    quantity = 0;
    purchased = 0;
    sales = 0;
}

//constructor given name, price, and quantity of the drink
DrinkItem::DrinkItem(std::string name, double price, unsigned int quantity)
{
    //instantiates variables to the given values
    this->name = name;
    this->price = price;
    this->quantity = quantity;
    purchased = 0;
    sales = 0;
}

//copy constructor
DrinkItem::DrinkItem(const DrinkItem& drinkItem)
{
    name = drinkItem.getName();
    price = drinkItem.getPrice();
    quantity = drinkItem.getQuantity();
    purchased = drinkItem.getPurchased();
    sales = drinkItem.getSales();
}

//gets the name of the drink
std::string DrinkItem::getName() const
{
    return name;
}

//sets the name of the drink to the name specified
void DrinkItem::setName(std::string newName)
{
    name = newName;
}

//gets the price of the drink
double DrinkItem::getPrice() const
{
    return price;
}

//set the price of the drink to the price specified
void DrinkItem::setPrice(double newPrice)
{
    price = newPrice;
}

//gets the quantity of the drink
unsigned int DrinkItem::getQuantity() const
{
    return quantity;
}

//gets the number of purchased drinks of this type
unsigned int DrinkItem::getPurchased() const
{
    return purchased;
}

//gets the amount of money earned by the purchases
double DrinkItem::getSales() const
{
    return sales;
}

//increases the quantity by the given amount
void DrinkItem::addDrinks(unsigned int amount)
{
    quantity += amount;
}

//checks if the drink has quantity, then purchases it.
bool DrinkItem::purchase()
{
    //check quantity
    if(!quantity > 0)
        return false;
    //update values
    quantity--;
    purchased++;
    sales += price;
    return true;
}
---------------------------------------------------------------------------------------------
drinkitem.h
--------------------------------------------
#ifndef DRINKITEM_H_
#define DRINKITEM_H_
#include <string>

class DrinkItem
{
    //initialize variables to be used in the class.
private:
    std::string name;
    double price;
    unsigned int quantity;
    unsigned int purchased;
    double sales;
    //prototype methods to be instantiated later.
public:
    //default constructor for a drinkitem.
    DrinkItem();
    //constructs a drink item with the given name, price and quantity
    DrinkItem(std::string name, double price, unsigned int quantity);
    //copy constructor
    DrinkItem(const DrinkItem& drinkItem);
    //returns the name of the drink
    std::string getName() const;
    //changes the name of the drink to the new name provided
    void setName(std::string newName);
    //returns the price of the drink
    double getPrice() const;
    //changes the price of the drink to the new price provided
    void setPrice(double newPrice);
    //gets the quantity of the drink
    unsigned int getQuantity() const;
    //gets the amount of that drink purchased
    unsigned int getPurchased() const;
    //gets the total sales of that drink
    double getSales() const;
    //adds the specified amount of drinks to the quantity
    void addDrinks(unsigned int amount);
    //purchases a drink if the quantity is greater than 0.
    //Reduces quantity, increases purchased and sales
    bool purchase();
};

#endif /* DRINKITEM_H_ */
-----------------------------------------------------------------------
receipt.cpp
----------------------------------------
#include "receipt.h"

//creates a default constructor, giving it the insufficient funds state with no change
Receipt::Receipt()
{
    state = INSUFFICIENT;
    change = 0.0;
}

//sets the receipt state to the state given and sets the change to 0
Receipt::Receipt(states state)
{
    this->state = state;
    change = 0.0;
}

//sets the change to the amount given and sets the receipt to the success state
Receipt::Receipt(double change)
{
    state = SUCCESS;
    this->change = change;
}

//sets the change to the amount given and sets the state to the given state
Receipt::Receipt(states state, double change)
{
    this->state = state;
    this->change = change;
}

//returns true if the receipt is in the success state
bool Receipt::success() const
{
    return state == SUCCESS;
}

//returns true if the receipt is in the insufficient funds state
bool Receipt::insufficient() const
{
    return state == INSUFFICIENT;
}

//returns true if the receipt is in the empty state
bool Receipt::empty() const
{
    return state == EMPTY;
}

//returns the amount of change in the receipt
double Receipt::getChange() const
{
    return change;
}
----------------------------------------------------------------------
receipt.h
-----------------------------------------------
#ifndef RECEIPT_H_
#define RECEIPT_H_

#include "drinkitem.h"

//creates an enum to store the possible states of the receipt
enum states{INSUFFICIENT, SUCCESS, EMPTY};

class Receipt
{
    //initialize variables for the receipt
private:
    states state;
    double change;
    //prototype methods to be used later
public:
    //creates a receipt defaulting to the insufficient funds state
    Receipt();
    //creates a receipt with the given state and no change
    Receipt(states state);
    //creates a successful receipt with the given change
    Receipt(double change);
    //creates a receipt with the given state and change;
    Receipt(states state, double change);
    //returns true if the receipt is in the success state
    bool success() const;
    //returns true if the receipt is in the insufficient funds state
    bool insufficient() const;
    //returns true if the receipt is in the empty state
    bool empty() const;
    //returns the amount of change in the receipt
    double getChange() const;
};

#endif /* RECEIPT_H_ */
----------------------------------------------------------------------
drink.txt
-------------------------------------------
8
Cola                   1.25   25
Root-beer              1.25   20
Lemon-lime             1.25   25
Water                  1.00   40
Orange                 1.25    5
Iced-tea               1.25   35
Grape                  1.30   15
Iced-coffee            2.00   35


DrinkMachine [CAU Eile Edit View Navigate Code Refactor Run Iools VCS Window Help iNCLionProjectstDrinkMachine] - ..main.cpp

Add a comment
Know the answer?
Add Answer to:
Write a program in C++ that simulates a soft drink machine. The program will need several...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with my homework please. I should write this program in C++ language and...

    I need help with my homework please. I should write this program in C++ language and use Inventory.h file (header file), Inventory.cpp file (implementation file), and main.cpp file (main program). This is the program: Demonstrate the class in a driver program. Input validation, don’t accept negative values for item number, quantity, or cost. 6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • C++ edit: You start with the code given and then modify it so that it does...

    C++ edit: You start with the code given and then modify it so that it does what the following asks for. Create an EmployeeException class whose constructor receives a String that consists of an employee’s ID and pay rate. Modify the Employee class so that it has two more fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an EmployeeException if the hourlyWage is less than $6.00 or over $50.00. Write a program that...

  • J Inc. has a file with employee details. You are asked to write a C++ program...

    J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and...

  • in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "Ret...

    in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "RetailItem" class which simulates the sale of a retail item. It should have a constructor that accepts a "RetailItem" object as an argument. The constructor should also accept an integer that represents the quantity of items being purchased. Your class should have these methods: getSubtotal: returns the subtotal of the sale, which is quantity times price....

  • C++ program, inventory.cpp implementation Mostly need the int load(istream&) function. Implementation: You are supp...

    C++ program, inventory.cpp implementation Mostly need the int load(istream&) function. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • The following program contains the definition of a class called List, a class called Date and...

    The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...

  • Your will write a class named Gasket that can be used to build Gasket objects (that...

    Your will write a class named Gasket that can be used to build Gasket objects (that represent Sierpinski gaskets) that you can display graphically.  Your Gasket class is defined in the provided file Gasket.h.   DO NOT CHANGE the file Gasket.h.  The attributes and methods defined for class Gasket are described below.     ·sideLength            an int that holds the length of each side of the Gasket.  The length of the side is measured as a number of pixels ·xLocation              an int that holds the x coordinate (in pixels)...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT